Package org.apache.sis.feature
Class PropertySingleton<V>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<V>
org.apache.sis.feature.PropertySingleton<V>
- All Implemented Interfaces:
Iterable<V>,Collection<V>,List<V>
A list containing 0 or 1 value. This implementation is used in the very common case where a
AbstractAttribute accepts at most one value. Its main purpose is to reduce the amount
of objects in memory compared to ArrayList.
There is no need to keep long-lived references to instances of this class. Instances can be recreated when needed.
- Since:
- 0.5
- Version:
- 0.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classImplementation of the iterator returned byiterator(). -
Field Summary
FieldsModifier and TypeFieldDescriptionThe property where to read and write the value.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionPropertySingleton(Field<V> property) Creates a new list for the value of the given property. -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the property value, if no instance existed prior this method call.booleanSets the property value, if no instance existed prior this method call.voidclear()Removes the property value.(package private) final voidclear(int c) Removes the singleton value, if presents.booleanSame contract thanAbstractList, just slightly more efficient for this particular class.get(int index) Returns the property value, if present.inthashCode()Same contract thanAbstractList, just slightly more efficient for this particular class.intReturns the index of the given element (which can only be 0), or -1 if not present.iterator()Returns an iterator over the unique element in this list.intlastIndexOf(Object element) Returns the index of the given element (which can only be 0), or -1 if not present.remove(int index) Removes the property value.Sets the property value, if an instance already exists.intsize()Returns 1 or 0, depending on whether or not a value exists.Object[]toArray()Returns an array wrapping the singleton value, or an empty array if none.Methods inherited from class java.util.AbstractList
addAll, listIterator, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray
-
Field Details
-
property
The property where to read and write the value.
-
-
Constructor Details
-
PropertySingleton
Creates a new list for the value of the given property.
-
-
Method Details
-
size
public int size()Returns 1 or 0, depending on whether or not a value exists.- Specified by:
sizein interfaceCollection<V>- Specified by:
sizein interfaceList<V>- Specified by:
sizein classAbstractCollection<V>
-
indexOf
Returns the index of the given element (which can only be 0), or -1 if not present. -
lastIndexOf
Returns the index of the given element (which can only be 0), or -1 if not present.- Specified by:
lastIndexOfin interfaceList<V>- Overrides:
lastIndexOfin classAbstractList<V>
-
get
Returns the property value, if present. -
set
Sets the property value, if an instance already exists. -
add
Sets the property value, if no instance existed prior this method call. -
add
Sets the property value, if no instance existed prior this method call.- Specified by:
addin interfaceCollection<V>- Specified by:
addin interfaceList<V>- Overrides:
addin classAbstractList<V>
-
remove
Removes the property value. This method does not checks if the removal is allowed by the multiplicity. Such check can be performed byAbstractFeature.quality(). -
clear
final void clear(int c) Removes the singleton value, if presents. This method is forPropertySingleton.Iter.remove()implementation only.- Parameters:
c- the expectedAbstractList.modCountvalue, for check against concurrent modification.
-
clear
public void clear()Removes the property value. This method does not checks if the removal is allowed by the multiplicity. Such check can be performed byAbstractFeature.quality().- Specified by:
clearin interfaceCollection<V>- Specified by:
clearin interfaceList<V>- Overrides:
clearin classAbstractList<V>
-
toArray
Returns an array wrapping the singleton value, or an empty array if none.- Specified by:
toArrayin interfaceCollection<V>- Specified by:
toArrayin interfaceList<V>- Overrides:
toArrayin classAbstractCollection<V>
-
hashCode
public int hashCode()Same contract thanAbstractList, just slightly more efficient for this particular class.- Specified by:
hashCodein interfaceCollection<V>- Specified by:
hashCodein interfaceList<V>- Overrides:
hashCodein classAbstractList<V>
-
equals
Same contract thanAbstractList, just slightly more efficient for this particular class.- Specified by:
equalsin interfaceCollection<V>- Specified by:
equalsin interfaceList<V>- Overrides:
equalsin classAbstractList<V>
-
iterator
Returns an iterator over the unique element in this list.
-