Class SuperCollection<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>
This class is a generic collection which serves as a base for other super collections. It handles non-indexed accesses to collections like additions, removals, contains...
Note that because this collection holds references to other collections, modifications to children will be reflected here. Also, modifications to this collection will affect its children.
If you need a collection that has the very same contents but isn't affected by operations to
children, you can employ the asClone() method, which returns a new collection with the
same contents.
Since there are several children and not all may return the same return value for certain
operations, you can control how this class behaves by means of the setResultMode(ResultMode) method. It defaults to ANY, so operations that return booleans will
return true as long as at least one children succeeded.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Constructor Summary
ConstructorsConstructorDescriptionSuperCollection(List<? extends Collection<E>> parents, SuperCollection.AdditionMode additionMode) SuperCollection(SuperCollection.AdditionMode additionMode) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> objects) abstract Collection<E>asClone()Returns a new collection with the same contents as the parents.voidclear()booleanbooleancontainsAll(Collection<?> objects) booleanDetermines how this collection will behave to additions.protected abstract Class<? extends Collection>Returns the class this SuperCollection implements.List<? extends Collection<E>>Returns the list of parents.Current result mode.inthashCode()booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> objects) protected booleanresultBoolean(int modified) booleanretainAll(Collection<?> objects) voidsetAdditionMode(SuperCollection.AdditionMode additionMode) Determines how this collection will behave to additions.voidsetResultMode(SuperCollection.ResultMode resultMode) Current result mode.intsize()Object[]toArray()<T> T[]toArray(T[] array) toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
SuperCollection
-
SuperCollection
public SuperCollection(List<? extends Collection<E>> parents, SuperCollection.AdditionMode additionMode)
-
-
Method Details
-
getParents
Returns the list of parents.- Returns:
- Parent list.
-
asClone
Returns a new collection with the same contents as the parents.- Returns:
- New mutable collection.
-
getCollectionClass
Returns the class this SuperCollection implements.- Returns:
- Collection class.
-
resultBoolean
protected boolean resultBoolean(int modified) -
add
- Specified by:
addin interfaceCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>
-
equals
- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>
-
iterator
-
remove
- Specified by:
removein interfaceCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>
-
size
public int size()- Specified by:
sizein interfaceCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] array) - Specified by:
toArrayin interfaceCollection<E>
-
toString
-
getResultMode
Current result mode.If mode is set to ANY, operations will return "true" as long as the parents returned "true" at least once.
If mode is set to ALL, operations will only return "true" if all parents also returned "true".
- Returns:
- Result mode.
-
setResultMode
Current result mode.If mode is set to ANY, operations will return "true" as long as the parents returned "true" at least once.
If mode is set to ALL, operations will only return "true" if all parents also returned "true".
- Parameters:
resultMode- Result mode.
-
getAdditionMode
Determines how this collection will behave to additions.If mode is set to ALL, the addition will be performed on every parent. Default for sets.
If mode is set to LAST, the operation will be performed on the last parent only. Default for lists.
- Returns:
- Addition mode.
-
setAdditionMode
Determines how this collection will behave to additions.If mode is set to ALL, the addition will be performed on every parent. Default for sets.
If mode is set to LAST, the operation will be performed on the last parent only. Default for lists.
- Parameters:
additionMode- Addition mode.
-