Class GraphComparator

java.lang.Object
com.cedarsoftware.util.GraphComparator

public class GraphComparator extends Object
Graph Utility algorithms, such as Asymmetric Graph Difference.
Author:
John DeRegnaucourt ([email protected])
Copyright [2010] John DeRegnaucourt

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.
  • Field Details

  • Constructor Details

    • GraphComparator

      public GraphComparator()
  • Method Details

    • compare

      public static List<GraphComparator.Delta> compare(Object source, Object target, GraphComparator.ID idFetcher)
      Perform the asymmetric graph delta. This will compare two disparate graphs and generate the necessary 'commands' to convert the source graph into the target graph. All nodes (cities) in the graph must be uniquely identifiable. An ID interface must be passed in, where the supplied implementation of this, usually done as an anonymous inner function, implements the ID.getId() method. The compare() function uses this interface to get the unique ID from the graph nodes.
      Returns:
      Collection of Delta records. Each delta record records a difference between graph A - B (asymmetric difference). It contains the information required to morph B into A. For example, if Graph B represents a stored object model in the database, and Graph A is an inbound change of that graph, the deltas can be applied to B such that the persistent storage will now be A.
    • applyDelta

      public static List<GraphComparator.DeltaError> applyDelta(Object source, List<GraphComparator.Delta> commands, GraphComparator.ID idFetcher, GraphComparator.DeltaProcessor deltaProcessor, boolean... failFast)
      Apply the Delta commands to the source object graph, making the requested changes to the source graph. The source of the commands is typically generated from the output of the 'compare()' API, where this source graph was compared to another target graph, and the delta commands were generated from that comparison.
      Parameters:
      source - Source object graph
      commands - List of Delta commands. These commands carry the information required to identify the nodes to be modified, as well as the values to modify them to (including commands to resize arrays, set values into arrays, set fields to specific values, put new entries into Maps, etc.
      Returns:
      List which contains the String error message describing why the Delta could not be applied, and a reference to the Delta that was attempted to be applied.
    • getJavaDeltaProcessor

      public static GraphComparator.DeltaProcessor getJavaDeltaProcessor()
      Returns:
      DeltaProcessor that handles updating Java objects with Delta commands. The typical use is to update the source graph objects with Delta commands to bring it to match the target graph.