Package com.cedarsoftware.util
Class Traverser
- java.lang.Object
-
- com.cedarsoftware.util.Traverser
-
public class Traverser extends Object
Java Object Graph traverser. It will visit all Java object reference fields and call the passed in Visitor instance with each object encountered, including the root. It will properly detect cycles within the graph and not hang.- Author:
- John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Traverser.ClassInfo
This class wraps a class in order to cache the fields so they are only reflectively obtained once.static interface
Traverser.Visitor
-
Field Summary
Fields Modifier and Type Field Description protected Map<Class,Traverser.ClassInfo>
_classCache
-
Constructor Summary
Constructors Constructor Description Traverser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
traverse(Object o, Traverser.Visitor visitor)
static void
traverse(Object o, Class<?>[] skip, Traverser.Visitor visitor)
void
walk(Object root, Class<?>[] skip, Traverser.Visitor visitor)
Traverse the object graph referenced by the passed in root.
-
-
-
Field Detail
-
_classCache
protected final Map<Class,Traverser.ClassInfo> _classCache
-
-
Method Detail
-
traverse
public static void traverse(Object o, Traverser.Visitor visitor)
- Parameters:
o
- Any Java Objectvisitor
- Visitor is called for every object encountered during the Java object graph traversal.
-
traverse
public static void traverse(Object o, Class<?>[] skip, Traverser.Visitor visitor)
- Parameters:
o
- Any Java Objectskip
- String[] of class names to not include in the tallyvisitor
- Visitor is called for every object encountered during the Java object graph traversal.
-
walk
public void walk(Object root, Class<?>[] skip, Traverser.Visitor visitor)
Traverse the object graph referenced by the passed in root.- Parameters:
root
- Any Java object.skip
- Set of classes to skip (ignore). Allowed to be null.
-
-