Class LegacyPropertyAdapter<L,N>
java.lang.Object
java.util.AbstractCollection<L>
org.apache.sis.internal.metadata.legacy.LegacyPropertyAdapter<L,N>
- Type Parameters:
L
- the legacy type.N
- the new type.
- All Implemented Interfaces:
Iterable<L>
,Collection<L>
- Direct Known Subclasses:
LegacyTelephones
,MetadataScopeAdapter
An adapter for collections of a legacy type replaced by another collection.
This adapter is used for implementation of deprecated methods in the
org.apache.sis.metadata.iso
sub-packages, usually when the deprecation is the result of upgrading from an older to a newer ISO standard.- Since:
- 0.5
- Version:
- 0.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Collection<N>
The collection where to store the elements.private boolean
For logging warning only once per collection usage. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
LegacyPropertyAdapter
(Collection<N> elements) Creates a new adapter. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a new element.final boolean
Compares this collection with the given object for equality.static <L> L
getSingleton
(Collection<? extends L> values, Class<L> valueClass, LegacyPropertyAdapter<L, ?> caller, Class<?> callerClass, String callerMethod) Returns the singleton value of the given collection, ornull
if the given collection is null or empty.final int
hashCode()
Returns a hash code value for this collection.final boolean
isEmpty()
Returnstrue
if this collection is empty.private static boolean
Returnstrue
if the given metadata is empty.iterator()
Returns an iterator over the legacy elements.final void
setValues
(Collection<? extends L> newValues) Sets the values from the given collection.final int
size()
Counts the number of non-null elements.protected abstract L
Extracts a legacy value from the new type.protected abstract boolean
Updates a new value with the given legacy value.final LegacyPropertyAdapter<L,
N> Returnsthis
if the collection given at construction time was non-null, ornull
otherwise.static void
warnIgnoredExtraneous
(Class<?> valueClass, Class<?> callerClass, String callerMethod) Emit a warning about extraneous ignored values.protected abstract N
Wraps a legacy value in its new type.Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, 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, spliterator, stream, toArray
-
Field Details
-
elements
The collection where to store the elements. -
warningOccurred
private transient boolean warningOccurredFor logging warning only once per collection usage.
-
-
Constructor Details
-
LegacyPropertyAdapter
Creates a new adapter.- Parameters:
elements
- the collection where to store the elements (may benull
).
-
-
Method Details
-
wrap
Wraps a legacy value in its new type.- Parameters:
value
- the legacy value.- Returns:
- the new type.
-
unwrap
Extracts a legacy value from the new type.- Parameters:
container
- the new type.- Returns:
- the legacy value, or
null
.
-
update
Updates a new value with the given legacy value.- Parameters:
container
- the new value to be used as a container for the old value.value
- the value to update in the container.- Returns:
- whether this method has been able to perform the update.
-
validOrNull
Returnsthis
if the collection given at construction time was non-null, ornull
otherwise. The latter case may happen at marshalling time.- Returns:
this
ornull
.
-
setValues
Sets the values from the given collection.- Parameters:
newValues
- the values to set (may benull
).
-
getSingleton
public static <L> L getSingleton(Collection<? extends L> values, Class<L> valueClass, LegacyPropertyAdapter<L, ?> caller, Class<?> callerClass, String callerMethod) Returns the singleton value of the given collection, ornull
if the given collection is null or empty. If the given collection contains more than one non-null and distinct element, then a warning is emitted.- Type Parameters:
L
- the kind of legacy values to be returned.- Parameters:
values
- the collection from which to get the value.valueClass
- the value class, used in case of warning only.caller
- eitherthis
ornull
.callerClass
- the caller class, used in case of warning only.callerMethod
- the caller method, used in case of warning only.- Returns:
- the first value, or
null
if none.
-
warnIgnoredExtraneous
public static void warnIgnoredExtraneous(Class<?> valueClass, Class<?> callerClass, String callerMethod) Emit a warning about extraneous ignored values.- Parameters:
valueClass
- the value class (usually a GeoAPI interface).callerClass
- the caller class (usually an Apache SIS implementation of a GeoAPI interface).callerMethod
- the caller method (usually the name of a getter method).
-
isEmpty
Returnstrue
if the given metadata is empty. -
isEmpty
public final boolean isEmpty()Returnstrue
if this collection is empty.- Specified by:
isEmpty
in interfaceCollection<L>
- Overrides:
isEmpty
in classAbstractCollection<L>
- Returns:
true
if this collection is empty.
-
size
public final int size()Counts the number of non-null elements.- Specified by:
size
in interfaceCollection<L>
- Specified by:
size
in classAbstractCollection<L>
- Returns:
- number of non-null elements.
-
add
Adds a new element.- Specified by:
add
in interfaceCollection<L>
- Overrides:
add
in classAbstractCollection<L>
- Parameters:
value
- the element to add.- Returns:
true
if the element has been added.
-
iterator
Returns an iterator over the legacy elements.- Specified by:
iterator
in interfaceCollection<L>
- Specified by:
iterator
in interfaceIterable<L>
- Specified by:
iterator
in classAbstractCollection<L>
- Returns:
- iterator over the legacy elements.
-
equals
Compares this collection with the given object for equality. This method performs comparisons only with instances ofLegacyPropertyAdapter
, and returnsfalse
for all other kinds of collection. We do not compare with arbitrary collection implementations.Rational:
Collection.equals(Object)
contract explicitly forbids comparisons withList
andSet
. The rational explained inCollection
javadoc applies also to other kind ofCollection
implementations: we cannot enforceCollection.equals(Object)
to be symmetric in such cases.- Specified by:
equals
in interfaceCollection<L>
- Overrides:
equals
in classObject
- Parameters:
other
- the other object to compare with this collection, ornull
.- Returns:
true
if the objects are equal, orfalse
otherwise.
-
hashCode
public final int hashCode()Returns a hash code value for this collection.- Specified by:
hashCode
in interfaceCollection<L>
- Overrides:
hashCode
in classObject
- Returns:
- a hash code value calculated from the content of this collection.
-