org.opensaml.xml.util
Class ClassIndexedSet<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by org.opensaml.xml.util.ClassIndexedSet<T>
Type Parameters:
T - the type of object stored by this class
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>
Direct Known Subclasses:
CredentialContextSet, CriteriaSet

public class ClassIndexedSet<T>
extends java.util.AbstractSet<T>
implements java.util.Set<T>

Set implementation which provides indexed access to set members via their class, and which allows only one instance of a given class to be present in the set. Null members are not allowed.


Nested Class Summary
protected  class ClassIndexedSet.ClassIndexedSetIterator
          Iterator for set implementation ClassIndexedSet.
 
Constructor Summary
ClassIndexedSet()
          Constructor.
 
Method Summary
 boolean add(T o)
          
 boolean add(T o, boolean replace)
          Add member to set, optionally replacing any existing instance of the same class.
 void clear()
          
 boolean contains(java.lang.Class<? extends T> clazz)
          Check whether set contains an instance of the specified class.
<X extends T>
X
get(java.lang.Class<X> clazz)
          Get the set element specified by the class parameter.
protected  java.lang.Class<? extends T> getIndexClass(java.lang.Object o)
          Get the index class of the specified object.
 java.util.Iterator<T> iterator()
          
 boolean remove(java.lang.Object o)
          
 int size()
          
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

ClassIndexedSet

public ClassIndexedSet()
Constructor.

Method Detail

add

public boolean add(T o)

Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.Set<T>
Overrides:
add in class java.util.AbstractCollection<T>

add

public boolean add(T o,
                   boolean replace)
            throws java.lang.NullPointerException,
                   java.lang.IllegalArgumentException
Add member to set, optionally replacing any existing instance of the same class.

Parameters:
o - the object to add
replace - flag indicating whether to replace an existing class type
Returns:
true if object was added
Throws:
java.lang.IllegalArgumentException - if set already contained an instance of the object's class and replacement was specified as false
java.lang.NullPointerException - if the object to add was null

clear

public void clear()

Specified by:
clear in interface java.util.Collection<T>
Specified by:
clear in interface java.util.Set<T>
Overrides:
clear in class java.util.AbstractCollection<T>

remove

public boolean remove(java.lang.Object o)

Specified by:
remove in interface java.util.Collection<T>
Specified by:
remove in interface java.util.Set<T>
Overrides:
remove in class java.util.AbstractCollection<T>

iterator

public java.util.Iterator<T> iterator()

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in interface java.util.Set<T>
Specified by:
iterator in class java.util.AbstractCollection<T>

size

public int size()

Specified by:
size in interface java.util.Collection<T>
Specified by:
size in interface java.util.Set<T>
Specified by:
size in class java.util.AbstractCollection<T>

contains

public boolean contains(java.lang.Class<? extends T> clazz)
Check whether set contains an instance of the specified class.

Parameters:
clazz - the class to check
Returns:
true if set contains an instance of the specified class, false otherwise

get

public <X extends T> X get(java.lang.Class<X> clazz)
Get the set element specified by the class parameter.

Type Parameters:
X - generic parameter which eliminates need for casting by the caller
Parameters:
clazz - the class to whose instance is to be retrieved
Returns:
the element whose class is of the type specified, or null

getIndexClass

protected java.lang.Class<? extends T> getIndexClass(java.lang.Object o)
Get the index class of the specified object. Subclasses may override to use a class index other than the main runtime class of the object.

Parameters:
o - the object whose class index to determine
Returns:
the class index value associated with the object instance


Copyright © 2006-2011 Internet2. All Rights Reserved.