Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.cedarsoftware.util;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.cedarsoftware.util.LoggingConfig;
/**
* A Java Object Graph traverser that visits all object reference fields and invokes a
* provided callback for each encountered object, including the root. It properly
* detects cycles within the graph to prevent infinite loops. For each visited node,
* complete field information including metadata is provided.
*
*
{@code
* // Define a visitor that processes each object
* Traverser.Visitor visitor = new Traverser.Visitor() {
* @Override
* public void process(Object o) {
* System.out.println("Visited: " + o);
* }
* };
*
* // Create an object graph and traverse it
* SomeClass root = new SomeClass();
* Traverser.traverse(root, visitor);
* }
*
*
* Thread Safety: This class is not thread-safe. If multiple threads access
* a {@code Traverser} instance concurrently, external synchronization is required.
*
*
* @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
*
* 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.
*/
public class Traverser {
private static final Logger LOG = Logger.getLogger(Traverser.class.getName());
static { LoggingConfig.init(); }
/**
* Represents a node visit during traversal, containing the node and its field information.
*/
public static class NodeVisit {
private final Object node;
private final java.util.function.Supplier