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
Modifier and TypeClassDescriptionstatic enum
static enum
-
Constructor Summary
ConstructorDescriptionSuperCollection
(List<? extends Collection<E>> parents, SuperCollection.AdditionMode additionMode) SuperCollection
(SuperCollection.AdditionMode additionMode) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> objects) abstract Collection<E>
asClone()
Returns a new collection with the same contents as the parents.void
clear()
boolean
boolean
containsAll
(Collection<?> objects) boolean
Determines 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.int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> objects) protected boolean
resultBoolean
(int modified) boolean
retainAll
(Collection<?> objects) void
setAdditionMode
(SuperCollection.AdditionMode additionMode) Determines how this collection will behave to additions.void
setResultMode
(SuperCollection.ResultMode resultMode) Current result mode.int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] array) toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
add
in interfaceCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classObject
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
-
iterator
-
remove
- Specified by:
remove
in interfaceCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] array) - Specified by:
toArray
in 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.
-