Package org.geotools.util
Class DerivedSet<B,E>
- Object
-
- AbstractCollection<E>
-
- AbstractSet<E>
-
- DerivedSet<B,E>
-
- Type Parameters:
B- The type of elements in the backing set.E- The type of elements in this set.
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,Set<E>,CheckedCollection<E>
public abstract class DerivedSet<B,E> extends AbstractSet<E> implements CheckedCollection<E>, Serializable
A set whose values are derived from an other set. The values are derived only when requested, which make it possible to backup potentially large sets. Implementations need only to overridesbaseToDerived(B)andderivedToBase(E)methods. This set do not supportsnullvalue, sincenullis used when no mapping from base tothisexists. This class is serializable if the underlying base set is serializable too.This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DerivedSet(Set<B> base, Class<E> derivedType)Creates a new derived set from the specified base set.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(E element)Ensures that this set contains the specified element.protected abstract EbaseToDerived(B element)Transforms a value in the base set to a value in this set.booleancontains(Object element)Returnstrueif this set contains the specified element.protected abstract BderivedToBase(E element)Transforms a value in this set to a value in the base set.Class<E>getElementType()Returns the derived element type.booleanisEmpty()Returnstrueif this set contains no elements.Iterator<E>iterator()Returns an iterator over the elements contained in this set.booleanremove(Object element)Removes a single instance of the specified element from this set.intsize()Returns the number of elements in this set.-
Methods inherited from class AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class AbstractCollection
addAll, clear, containsAll, retainAll, toArray, toArray, toString
-
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface Set
addAll, clear, containsAll, retainAll, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
base
protected final Set<B> base
The base set whose values are derived from.- See Also:
baseToDerived(B),derivedToBase(E)
-
-
Method Detail
-
getElementType
public Class<E> getElementType()
Returns the derived element type.- Specified by:
getElementTypein interfaceCheckedCollection<B>- Returns:
- The element type.
- Since:
- 2.5
-
baseToDerived
protected abstract E baseToDerived(B element)
Transforms a value in the base set to a value in this set. If there is no mapping in the derived set for the specified element, then this method returnsnull.- Parameters:
element- A value in the base set.- Returns:
- The value that this view should contains instead of
element, ornull.
-
derivedToBase
protected abstract B derivedToBase(E element)
Transforms a value in this set to a value in the base set.- Parameters:
element- A value in this set.- Returns:
- The value stored in the base set.
-
iterator
public Iterator<E> iterator()
Returns an iterator over the elements contained in this set. The iterator will invokesbaseToDerived(B)for each element.
-
size
public int size()
Returns the number of elements in this set. The default implementation counts the number of elements returned by theiterator.- Specified by:
sizein interfaceCollection<B>- Specified by:
sizein interfaceSet<B>- Specified by:
sizein classAbstractCollection<E>- Returns:
- the number of elements in this set.
-
isEmpty
public boolean isEmpty()
Returnstrueif this set contains no elements.- Specified by:
isEmptyin interfaceCollection<B>- Specified by:
isEmptyin interfaceSet<B>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
trueif this set contains no elements.
-
contains
public boolean contains(Object element)
Returnstrueif this set contains the specified element. The default implementation invokesbase.contains(derivedToBase(element)).- Specified by:
containsin interfaceCollection<B>- Specified by:
containsin interfaceSet<B>- Overrides:
containsin classAbstractCollection<E>- Parameters:
element- object to be checked for containment in this set.- Returns:
trueif this set contains the specified element.
-
add
public boolean add(E element) throws UnsupportedOperationException
Ensures that this set contains the specified element. The default implementation invokesbase.add(derivedToBase(element)).- Specified by:
addin interfaceCollection<B>- Specified by:
addin interfaceSet<B>- Overrides:
addin classAbstractCollection<E>- Parameters:
element- element whose presence in this set is to be ensured.- Returns:
trueif the set changed as a result of the call.- Throws:
UnsupportedOperationException- if the base set doesn't supports theaddoperation.
-
remove
public boolean remove(Object element) throws UnsupportedOperationException
Removes a single instance of the specified element from this set. The default implementation invokesbase.remove(derivedToBase(element)).- Specified by:
removein interfaceCollection<B>- Specified by:
removein interfaceSet<B>- Overrides:
removein classAbstractCollection<E>- Parameters:
element- element to be removed from this set, if present.- Returns:
trueif the set contained the specified element.- Throws:
UnsupportedOperationException- if the base set doesn't supports theremoveoperation.
-
-