Package com.google.caliper.memory
Class ObjectExplorer
- java.lang.Object
-
- com.google.caliper.memory.ObjectExplorer
-
public final class ObjectExplorer extends Object
A depth-first object graph explorer. The traversal starts at a root (anObject) and explores any other reachable object (recursively) or primitive value, excluding static fields from the traversal. The traversal is controlled by a user-suppliedObjectVisitor, which decides for each explored path whether to continue exploration of that path, and it can also return a value at the end of the traversal.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classObjectExplorer.FeatureEnumeration of features that may be optionally requested for an object traversal.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TexploreObject(Object rootObject, ObjectVisitor<T> visitor)Explores an object graph (defined by a root object and whatever is reachable through it, following non-static fields) while using anObjectVisitorto both control the traversal and return a value.static <T> TexploreObject(Object rootObject, ObjectVisitor<T> visitor, EnumSet<ObjectExplorer.Feature> features)Explores an object graph (defined by a root object and whatever is reachable through it, following non-static fields) while using anObjectVisitorto both control the traversal and return a value.
-
-
-
Method Detail
-
exploreObject
public static <T> T exploreObject(Object rootObject, ObjectVisitor<T> visitor)
Explores an object graph (defined by a root object and whatever is reachable through it, following non-static fields) while using anObjectVisitorto both control the traversal and return a value.Equivalent to
exploreObject(rootObject, visitor, EnumSet.noneOf(Feature.class)).- Type Parameters:
T- the type of the value obtained (after the traversal) by the ObjectVisitor- Parameters:
rootObject- an object to be recursively exploredvisitor- a visitor that is notified for each explored path and decides whether to continue exploration of that path, and constructs a return value at the end of the exploration- Returns:
- whatever value is returned by the visitor at the end of the traversal
- See Also:
ObjectVisitor
-
exploreObject
public static <T> T exploreObject(Object rootObject, ObjectVisitor<T> visitor, EnumSet<ObjectExplorer.Feature> features)
Explores an object graph (defined by a root object and whatever is reachable through it, following non-static fields) while using anObjectVisitorto both control the traversal and return a value.The
featuresfurther customizes the exploration behavior. In particular:- If
ObjectExplorer.Feature.VISIT_PRIMITIVESis contained in features, the visitor will also be notified about exploration of primitive values. - If
ObjectExplorer.Feature.VISIT_NULLis contained in features, the visitor will also be notified about exploration ofnullvalues.
ObjectVisitor.visit(Chain)is ignored, since neither primitive values ornullcan be further explored.- Type Parameters:
T- the type of the value obtained (after the traversal) by the ObjectVisitor- Parameters:
rootObject- an object to be recursively exploredvisitor- a visitor that is notified for each explored path and decides whether to continue exploration of that path, and constructs a return value at the end of the explorationfeatures- a set of desired features that the object exploration should have- Returns:
- whatever value is returned by the visitor at the end of the traversal
- See Also:
ObjectVisitor
- If
-
-