public abstract class SuperCollection<E> extends Object implements 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.
Modifier and Type | Class and Description |
---|---|
static class |
SuperCollection.AdditionMode |
static class |
SuperCollection.ResultMode |
Constructor and Description |
---|
SuperCollection(List<? extends Collection<E>> parents,
SuperCollection.AdditionMode additionMode) |
SuperCollection(SuperCollection.AdditionMode additionMode) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E object) |
boolean |
addAll(Collection<? extends E> objects) |
abstract Collection<E> |
asClone()
Returns a new collection with the same contents as the parents.
|
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection<?> objects) |
boolean |
equals(Object object) |
SuperCollection.AdditionMode |
getAdditionMode()
Determines how this collection will behave to additions.
|
protected abstract Class<? extends Collection> |
getCollectionClass()
Returns the class this SuperCollection implements.
|
List<? extends Collection<E>> |
getParents()
Returns the list of parents.
|
SuperCollection.ResultMode |
getResultMode()
Current result mode.
|
int |
hashCode() |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
remove(Object object) |
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) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
parallelStream, removeIf, spliterator, stream
public SuperCollection(SuperCollection.AdditionMode additionMode)
public SuperCollection(List<? extends Collection<E>> parents, SuperCollection.AdditionMode additionMode)
public List<? extends Collection<E>> getParents()
public abstract Collection<E> asClone()
protected abstract Class<? extends Collection> getCollectionClass()
protected boolean resultBoolean(int modified)
public boolean add(E object)
add
in interface Collection<E>
public boolean addAll(Collection<? extends E> objects)
addAll
in interface Collection<E>
public void clear()
clear
in interface Collection<E>
public boolean contains(Object object)
contains
in interface Collection<E>
public boolean containsAll(Collection<?> objects)
containsAll
in interface Collection<E>
public boolean equals(Object object)
equals
in interface Collection<E>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Collection<E>
public boolean remove(Object object)
remove
in interface Collection<E>
public boolean removeAll(Collection<?> objects)
removeAll
in interface Collection<E>
public boolean retainAll(Collection<?> objects)
retainAll
in interface Collection<E>
public int size()
size
in interface Collection<E>
public Object[] toArray()
toArray
in interface Collection<E>
public <T> T[] toArray(T[] array)
toArray
in interface Collection<E>
public SuperCollection.ResultMode getResultMode()
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".
public void setResultMode(SuperCollection.ResultMode resultMode)
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".
resultMode
- Result mode.public SuperCollection.AdditionMode getAdditionMode()
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.
public void setAdditionMode(SuperCollection.AdditionMode additionMode)
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.
additionMode
- Addition mode.Copyright © 2021. All rights reserved.