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 booleanFor logging warning only once per collection usage. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLegacyPropertyAdapter(Collection<N> elements) Creates a new adapter. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a new element.final booleanCompares this collection with the given object for equality.static <L> LgetSingleton(Collection<? extends L> values, Class<L> valueClass, LegacyPropertyAdapter<L, ?> caller, Class<?> callerClass, String callerMethod) Returns the singleton value of the given collection, ornullif the given collection is null or empty.final inthashCode()Returns a hash code value for this collection.final booleanisEmpty()Returnstrueif this collection is empty.private static booleanReturnstrueif the given metadata is empty.iterator()Returns an iterator over the legacy elements.final voidsetValues(Collection<? extends L> newValues) Sets the values from the given collection.final intsize()Counts the number of non-null elements.protected abstract LExtracts a legacy value from the new type.protected abstract booleanUpdates a new value with the given legacy value.final LegacyPropertyAdapter<L,N> Returnsthisif the collection given at construction time was non-null, ornullotherwise.static voidwarnIgnoredExtraneous(Class<?> valueClass, Class<?> callerClass, String callerMethod) Emit a warning about extraneous ignored values.protected abstract NWraps a legacy value in its new type.Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream
-
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
Returnsthisif the collection given at construction time was non-null, ornullotherwise. The latter case may happen at marshalling time.- Returns:
thisornull.
-
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, ornullif 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- eitherthisornull.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
nullif 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
Returnstrueif the given metadata is empty. -
isEmpty
public final boolean isEmpty()Returnstrueif this collection is empty.- Specified by:
isEmptyin interfaceCollection<L>- Overrides:
isEmptyin classAbstractCollection<L>- Returns:
trueif this collection is empty.
-
size
public final int size()Counts the number of non-null elements.- Specified by:
sizein interfaceCollection<L>- Specified by:
sizein classAbstractCollection<L>- Returns:
- number of non-null elements.
-
add
Adds a new element.- Specified by:
addin interfaceCollection<L>- Overrides:
addin classAbstractCollection<L>- Parameters:
value- the element to add.- Returns:
trueif the element has been added.
-
iterator
Returns an iterator over the legacy elements.- Specified by:
iteratorin interfaceCollection<L>- Specified by:
iteratorin interfaceIterable<L>- Specified by:
iteratorin 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 returnsfalsefor all other kinds of collection. We do not compare with arbitrary collection implementations.Rational:
Collection.equals(Object)contract explicitly forbids comparisons withListandSet. The rational explained inCollectionjavadoc applies also to other kind ofCollectionimplementations: we cannot enforceCollection.equals(Object)to be symmetric in such cases.- Specified by:
equalsin interfaceCollection<L>- Overrides:
equalsin classObject- Parameters:
other- the other object to compare with this collection, ornull.- Returns:
trueif the objects are equal, orfalseotherwise.
-
hashCode
public final int hashCode()Returns a hash code value for this collection.- Specified by:
hashCodein interfaceCollection<L>- Overrides:
hashCodein classObject- Returns:
- a hash code value calculated from the content of this collection.
-