T
- the type of object stored by this classpublic class ClassIndexedSet<T> extends AbstractSet<T> implements Set<T>
Modifier and Type | Class and Description |
---|---|
protected class |
ClassIndexedSet.ClassIndexedSetIterator
Iterator for set implementation
ClassIndexedSet . |
Modifier and Type | Field and Description |
---|---|
private HashMap<Class<? extends T>,T> |
index
Storage for index of class -> member.
|
private HashSet<T> |
set
Storage for set members.
|
Constructor and Description |
---|
ClassIndexedSet()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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(Class<? extends T> clazz)
Check whether set contains an instance of the specified class.
|
boolean |
equals(Object obj) |
<X extends T> |
get(Class<X> clazz)
Get the set element specified by the class parameter.
|
protected <X extends T> |
getIndexClass(X o)
Get the index class of the specified object.
|
int |
hashCode() |
Iterator<T> |
iterator() |
boolean |
remove(Object o) |
private void |
removeFromIndex(T o)
Remove the specified object from the index.
|
int |
size() |
String |
toString() |
removeAll
addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, isEmpty, removeAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
public boolean add(@Nonnull T o)
add
in interface Collection<T>
add
in interface Set<T>
add
in class AbstractCollection<T>
public boolean add(@Nonnull T o, boolean replace)
o
- the object to addreplace
- flag indicating whether to replace an existing class typepublic void clear()
clear
in interface Collection<T>
clear
in interface Set<T>
clear
in class AbstractCollection<T>
public boolean remove(@Nullable Object o)
remove
in interface Collection<T>
remove
in interface Set<T>
remove
in class AbstractCollection<T>
public int size()
size
in interface Collection<T>
size
in interface Set<T>
size
in class AbstractCollection<T>
public boolean contains(@Nullable Class<? extends T> clazz)
clazz
- the class to check@Nullable public <X extends T> X get(@Nullable Class<X> clazz)
X
- generic parameter which eliminates need for casting by the callerclazz
- the class to whose instance is to be retrieved@Nonnull protected <X extends T> Class<X> getIndexClass(@Nonnull X o)
X
- generic parameter which eliminates need for casting by the callero
- the object whose class index to determineprivate void removeFromIndex(T o)
o
- the object to removepublic String toString()
toString
in class AbstractCollection<T>
public boolean equals(Object obj)
equals
in interface Collection<T>
equals
in interface Set<T>
equals
in class AbstractSet<T>
public int hashCode()
hashCode
in interface Collection<T>
hashCode
in interface Set<T>
hashCode
in class AbstractSet<T>
Copyright © 1999–2018. All rights reserved.