Package org.apache.sis.metadata
Class HashCode
Computes a hash code for the specified metadata. The hash code is defined as the sum of hash codes
of all non-empty properties, plus the hash code of the interface. This is a similar contract than
Set.hashCode()
(except for the interface) and ensures that the hash code value
is insensitive to the ordering of properties.- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.metadata.MetadataVisitor
MetadataVisitor.Filter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The hash code value, returned byMetadataStandard.hashCode(Object)
after calculation.private static final ThreadLocal<HashCode>
Provider of visitor instances used byMetadataStandard.hashCode(Object)
.Fields inherited from class org.apache.sis.metadata.MetadataVisitor
SKIP_SIBLINGS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final ThreadLocal<HashCode>
creator()
Returns the thread-local variable that created thisHashCode
instance.(package private) static HashCode
Returns the visitor for the current thread if it already exists, or creates a new one otherwise.(package private) MetadataVisitor.Filter
preVisit
(PropertyAccessor accessor) Resets the hash code to an initial value for a new metadata instance.(package private) Integer
result()
Returns the hash code result after visiting all elements in a metadata instance.(package private) Object
Adds the hash code of the given metadata property value.Methods inherited from class org.apache.sis.metadata.MetadataVisitor
getCurrentPropertyPath, setCurrentProperty, walk
-
Field Details
-
VISITORS
Provider of visitor instances used byMetadataStandard.hashCode(Object)
. -
code
private int codeThe hash code value, returned byMetadataStandard.hashCode(Object)
after calculation.
-
-
Constructor Details
-
HashCode
private HashCode()Instantiated byVISITORS
only.
-
-
Method Details
-
getOrCreate
Returns the visitor for the current thread if it already exists, or creates a new one otherwise. -
creator
Returns the thread-local variable that created thisHashCode
instance.- Overrides:
creator
in classMetadataVisitor<Integer>
-
preVisit
Resets the hash code to an initial value for a new metadata instance. If another hash code computation was in progress, that code shall be saved before this method is invoked.- Overrides:
preVisit
in classMetadataVisitor<Integer>
- Parameters:
accessor
- contains the standard interface of the metadata for which a hash code value will be computed.- Returns:
MetadataVisitor.Filter.NON_EMPTY
since this visitor is not restricted to writable properties.
-
visit
Adds the hash code of the given metadata property value. Invoking this method may cause recursive calls toHashCode
methods on this visitor instance if the given value is itself another metadata object.- Specified by:
visit
in classMetadataVisitor<Integer>
- Parameters:
value
- the metadata property value for which to add hash code.type
- the type of elements. Note that this is not necessarily the type of givenvalue
argument if the latter is a collection.- Returns:
null
, meaning to not modify the metadata property value.
-
result
Integer result()Returns the hash code result after visiting all elements in a metadata instance.- Overrides:
result
in classMetadataVisitor<Integer>
-