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

public abstract class LegacyPropertyAdapter<L,N> extends AbstractCollection<L>
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 Details

    • elements

      protected final Collection<N> elements
      The collection where to store the elements.
    • warningOccurred

      private transient boolean warningOccurred
      For logging warning only once per collection usage.
  • Constructor Details

    • LegacyPropertyAdapter

      protected LegacyPropertyAdapter(Collection<N> elements)
      Creates a new adapter.
      Parameters:
      elements - the collection where to store the elements (may be null).
  • Method Details

    • wrap

      protected abstract N wrap(L value)
      Wraps a legacy value in its new type.
      Parameters:
      value - the legacy value.
      Returns:
      the new type.
    • unwrap

      protected abstract L unwrap(N container)
      Extracts a legacy value from the new type.
      Parameters:
      container - the new type.
      Returns:
      the legacy value, or null.
    • update

      protected abstract boolean update(N container, L value)
      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

      public final LegacyPropertyAdapter<L,N> validOrNull()
      Returns this if the collection given at construction time was non-null, or null otherwise. The latter case may happen at marshalling time.
      Returns:
      this or null.
    • setValues

      public final void setValues(Collection<? extends L> newValues)
      Sets the values from the given collection.
      Parameters:
      newValues - the values to set (may be null).
    • 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, or null 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 - either this or null.
      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

      private static boolean isEmpty(Object container)
      Returns true if the given metadata is empty.
    • isEmpty

      public final boolean isEmpty()
      Returns true if this collection is empty.
      Specified by:
      isEmpty in interface Collection<L>
      Overrides:
      isEmpty in class AbstractCollection<L>
      Returns:
      true if this collection is empty.
    • size

      public final int size()
      Counts the number of non-null elements.
      Specified by:
      size in interface Collection<L>
      Specified by:
      size in class AbstractCollection<L>
      Returns:
      number of non-null elements.
    • add

      public boolean add(L value)
      Adds a new element.
      Specified by:
      add in interface Collection<L>
      Overrides:
      add in class AbstractCollection<L>
      Parameters:
      value - the element to add.
      Returns:
      true if the element has been added.
    • iterator

      public final Iterator<L> iterator()
      Returns an iterator over the legacy elements.
      Specified by:
      iterator in interface Collection<L>
      Specified by:
      iterator in interface Iterable<L>
      Specified by:
      iterator in class AbstractCollection<L>
      Returns:
      iterator over the legacy elements.
    • equals

      public final boolean equals(Object other)
      Compares this collection with the given object for equality. This method performs comparisons only with instances of LegacyPropertyAdapter, and returns false for all other kinds of collection. We do not compare with arbitrary collection implementations.

      Rational: Collection.equals(Object) contract explicitly forbids comparisons with List and Set. The rational explained in Collection javadoc applies also to other kind of Collection implementations: we cannot enforce Collection.equals(Object) to be symmetric in such cases.

      Specified by:
      equals in interface Collection<L>
      Overrides:
      equals in class Object
      Parameters:
      other - the other object to compare with this collection, or null.
      Returns:
      true if the objects are equal, or false otherwise.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this collection.
      Specified by:
      hashCode in interface Collection<L>
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value calculated from the content of this collection.