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 class
Implementation 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 TypeMethodDescriptionvoid
Sets the property value, if no instance existed prior this method call.boolean
Sets the property value, if no instance existed prior this method call.void
clear()
Removes the property value.(package private) final void
clear
(int c) Removes the singleton value, if presents.boolean
Same contract thanAbstractList
, just slightly more efficient for this particular class.get
(int index) Returns the property value, if present.int
hashCode()
Same contract thanAbstractList
, just slightly more efficient for this particular class.int
Returns 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.int
lastIndexOf
(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.int
size()
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, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, 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, stream, toArray
Methods 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:
size
in interfaceCollection<V>
- Specified by:
size
in interfaceList<V>
- Specified by:
size
in 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:
lastIndexOf
in interfaceList<V>
- Overrides:
lastIndexOf
in 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:
add
in interfaceCollection<V>
- Specified by:
add
in interfaceList<V>
- Overrides:
add
in 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.modCount
value, 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:
clear
in interfaceCollection<V>
- Specified by:
clear
in interfaceList<V>
- Overrides:
clear
in classAbstractList<V>
-
toArray
Returns an array wrapping the singleton value, or an empty array if none.- Specified by:
toArray
in interfaceCollection<V>
- Specified by:
toArray
in interfaceList<V>
- Overrides:
toArray
in classAbstractCollection<V>
-
hashCode
public int hashCode()Same contract thanAbstractList
, just slightly more efficient for this particular class.- Specified by:
hashCode
in interfaceCollection<V>
- Specified by:
hashCode
in interfaceList<V>
- Overrides:
hashCode
in classAbstractList<V>
-
equals
Same contract thanAbstractList
, just slightly more efficient for this particular class.- Specified by:
equals
in interfaceCollection<V>
- Specified by:
equals
in interfaceList<V>
- Overrides:
equals
in classAbstractList<V>
-
iterator
Returns an iterator over the unique element in this list.
-