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 boolean
Whether the metadata is empty.private boolean
true
for 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
ConstructorsModifierConstructorDescriptionprivate
Pruner()
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 thisPruner
instance.(package private) static boolean
isEmpty
(AbstractMetadata metadata, boolean prune) Returnstrue
if all properties in the given metadata are null or empty.(package private) MetadataVisitor.Filter
preVisit
(PropertyAccessor accessor) Marks a metadata instance as empty before we start visiting its non-null properties.(package private) Boolean
result()
Returns the result of visiting all elements in the metadata.(package private) Object
Invoked 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 prunetrue
for 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 thisPruner
instance.- Overrides:
creator
in classMetadataVisitor<Boolean>
-
isEmpty
Returnstrue
if 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
-true
for deleting empty entries.- Returns:
true
if 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 theisEmpty
field will staytrue
.- Overrides:
preVisit
in classMetadataVisitor<Boolean>
- Parameters:
accessor
- information about the standard interface and implementation of the metadata being visited.- Returns:
MetadataVisitor.Filter.NON_EMPTY
since 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:
visit
in classMetadataVisitor<Boolean>
- Parameters:
type
- the type of elements. Note that this is not necessarily the type of givenelement
argument 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:
result
in classMetadataVisitor<Boolean>
-