Package org.apache.sis.metadata
Class Pruner
Implementation of
AbstractMetadata.isEmpty() and AbstractMetadata.prune() methods.
The MetadataVisitor.visited map inherited by this class is the thread-local map of metadata objects already tested.
Keys are metadata instances, and values are the results of the metadata.isEmpty() operation.
If the final operation requested by the user is isEmpty(), then this map will contain one of
few false values since the walk in the tree will stop at the first false value found.
If the final operation requested by the user is prune(), then this map will contain a mix of
false and true values since the operation will unconditionally walk through the entire tree.- Since:
- 0.3
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.metadata.MetadataVisitor
MetadataVisitor.Filter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether the metadata is empty.private booleantruefor removing empty properties.private static final ThreadLocal<Pruner>Provider of visitor instances.Fields inherited from class org.apache.sis.metadata.MetadataVisitor
SKIP_SIBLINGS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePruner()Creates a new object which will test or prune metadata properties. -
Method Summary
Modifier and TypeMethodDescription(package private) final ThreadLocal<Pruner>creator()Returns the thread-local variable that created thisPrunerinstance.(package private) static booleanisEmpty(AbstractMetadata metadata, boolean prune) Returnstrueif all properties in the given metadata are null or empty.(package private) MetadataVisitor.FilterpreVisit(PropertyAccessor accessor) Marks a metadata instance as empty before we start visiting its non-null properties.(package private) Booleanresult()Returns the result of visiting all elements in the metadata.(package private) ObjectInvoked for each element in the metadata to test or prune.Methods inherited from class org.apache.sis.metadata.MetadataVisitor
getCurrentPropertyPath, setCurrentProperty, walk
-
Field Details
-
VISITORS
Provider of visitor instances. -
prune
private boolean prunetruefor removing empty properties. -
isEmpty
private boolean isEmptyWhether the metadata is empty.
-
-
Constructor Details
-
Pruner
private Pruner()Creates a new object which will test or prune metadata properties.
-
-
Method Details
-
creator
Returns the thread-local variable that created thisPrunerinstance.- Overrides:
creatorin classMetadataVisitor<Boolean>
-
isEmpty
Returnstrueif all properties in the given metadata are null or empty. This method is the entry point for theAbstractMetadata.isEmpty()andAbstractMetadata.prune()public methods.- Parameters:
metadata- the metadata object.prune-truefor deleting empty entries.- Returns:
trueif all metadata properties are null or empty.
-
preVisit
Marks a metadata instance as empty before we start visiting its non-null properties. If the metadata does not contain any property, then theisEmptyfield will staytrue.- Overrides:
preVisitin classMetadataVisitor<Boolean>- Parameters:
accessor- information about the standard interface and implementation of the metadata being visited.- Returns:
MetadataVisitor.Filter.NON_EMPTYsince this visitor is not restricted to writable properties. We need to visit all readable properties even for pruning operation since we need to determine if the metadata is empty.
-
visit
Invoked for each element in the metadata to test or prune. This method is invoked only for new elements not yet processed byPruner. The element may be a value object or a collection. For convenience we will proceed as if we had only collections, wrapping value object in a singleton collection.- Specified by:
visitin classMetadataVisitor<Boolean>- Parameters:
type- the type of elements. Note that this is not necessarily the type of givenelementargument if the latter is a collection.value- value of the metadata element being visited.- Returns:
- the new property value to set, or
MetadataVisitor.SKIP_SIBLINGS.
-
result
Boolean result()Returns the result of visiting all elements in the metadata.- Overrides:
resultin classMetadataVisitor<Boolean>
-