public abstract class AbstractMetadata extends Object implements LenientComparable, Emptiable
AbstractMetadata instances shall be associated to a MetadataStandard.
The metadata standard is given by the getStandard() method and is typically a
constant fixed by the subclass.
There is a large number of AbstractMetadata subclasses (not necessarily as direct children)
for the same standard, where each subclass implement one Java interface defined by the metadata standard.
This base class reduces the effort required to implement those metadata interfaces by providing
equals(Object), hashCode() and toString() implementations.
Those methods are implemented using Java reflection for invoking the getter methods
defined by the MetadataStandard.
AbstractMetadata subclasses may be read-only or read/write, at implementation choice.
The methods that modify the metadata may throw UnmodifiableMetadataException if the
metadata does not support the operation. Those methods are:
| Read-only operations | Read/write operations |
|---|---|
|
|
MetadataStandardDefined in the sis-metadata module
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractMetadata()
Creates an initially empty metadata.
|
| Modifier and Type | Method and Description |
|---|---|
Map<String,Object> |
asMap()
Returns a view of the property values in a
Map. |
TreeTable |
asTreeTable()
Returns the property types and values as a tree table.
|
boolean |
equals(Object object)
Performs a strict comparison of this metadata with
the given object.
|
boolean |
equals(Object object,
ComparisonMode mode)
Compares this metadata with the specified object for equality.
|
Class<?> |
getInterface()
Returns the metadata interface implemented by this class.
|
abstract MetadataStandard |
getStandard()
Returns the metadata standard implemented by subclasses.
|
int |
hashCode()
Computes a hash code value for this metadata using Java reflection.
|
boolean |
isEmpty()
|
void |
prune()
Removes all references to empty properties.
|
String |
toString()
Returns a string representation of this metadata.
|
protected AbstractMetadata()
public abstract MetadataStandard getStandard()
MetadataStandard.ISO_19115.
public Class<?> getInterface()
MetadataStandard.getInterface(Class)public boolean isEmpty()
true if this metadata contains only null,
nil or empty properties.
A non-null and non-nil property is considered empty in any of the following cases:
null, nil or empty elements.null, nil or empty properties.prune() method.
MetadataStandard.asValueMap(Object, Class, KeyNamePolicy, ValueExistencePolicy).
Subclasses that override this method should usually not invoke super.isEmpty(),
because the Java reflection will discover and process the properties defined in the
subclasses - which is usually not the intend when overriding a method.isEmpty in interface Emptiabletrue if this metadata is empty.DefaultGeographicBoundingBox.isEmpty()public void prune()
null
the properties for which isEmpty() returned true.UnmodifiableMetadataException - if this metadata is not modifiable.public Map<String,Object> asMap()
Map. The map is backed by this metadata
object, so changes in the underlying metadata object are immediately reflected in the map
and conversely.
put(…) and remove(…) operations if the underlying metadata object contains setter methods.
The remove(…) method is implemented by a call to put(…, null).
put(…) method shall be an instance of the type expected by the corresponding setter method,
or an instance of a type convertible
to the expected type.
put(…) replace the previous value, with one noticeable exception: if the metadata
property associated to the given key is a Collection but the given value is a single
element (not a collection), then the given value is added
to the existing collection. In other words, the returned map behaves as a multi-values map
for the properties that allow multiple values. If the intend is to unconditionally discard all previous
values, then make sure that the given value is a collection when the associated metadata property expects
such collection.
return getStandard().asValueMap(this, null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
MetadataStandard.asValueMap(Object, Class, KeyNamePolicy, ValueExistencePolicy)public TreeTable asTreeTable()
The returned TreeTable instance contains the following columns:
TableColumn.IDENTIFIERDefaultCitation,
there is a node having the "title" identifier.TableColumn.INDEXnull. For example in a tree table view of DefaultCitation, if the
"alternateTitle" collection contains two elements, then there is a node with index 0
for the first element and an other node with index 1 for the second element.
(IDENTIFIER, INDEX) pair can be used as a primary key for uniquely identifying a node
in a list of children. That uniqueness is guaranteed only for the children of a given node;
the same keys may appear in the children of any other nodes.TableColumn.NAMEtoString() implementation and
may be localizable.TableColumn.TYPETableColumn.VALUEVALUE column may be writable, with one exception: newly created children need
to have their IDENTIFIER set before any other operation. For example the following code
adds a title to a citation:
TreeTable.Node node = ...; // The node for a DefaultCitation. TreeTable.Node child = node.newChild(); child.setValue(TableColumn.IDENTIFIER, "title"); child.setValue(TableColumn.VALUE, "Le petit prince"); // Nothing else to do - the child node has been added.Nodes can be removed by invoking the
Iterator.remove() method on the
children iterator.
return getStandard().asTreeTable(this, null, ValueExistencePolicy.COMPACT);
MetadataStandard.asTreeTable(Object, Class, ValueExistencePolicy)public boolean equals(Object object, ComparisonMode mode)
equals in interface LenientComparableobject - the object to compare with this metadata.mode - the strictness level of the comparison.true if the given object is equal to this metadata.Utilities.deepEquals(Object, Object, ComparisonMode)public final boolean equals(Object object)
public final boolean equals(final Object object) {
return equals(object, ComparisonMode.STRICT);
}
If a subclass needs to override the behavior of this method, then
override equals(Object, ComparisonMode) instead.equals in interface LenientComparableequals in class Objectobject - the object to compare with this metadata for equality.true if the given object is strictly equals to this metadata.ComparisonMode.STRICTpublic int hashCode()
Set.hashCode() one and ensures that the hash code value is
insensitive to the ordering of properties.
hashCode in class ObjectMetadataStandard.hashCode(Object)Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.