Difference methods on the DiffUtils class

DiffUtils is a Java class that compares two branches and helps filter a list of different items. You can use this class for advanced difference comparison. You access DiffUtils methods by using the DiffUtils property in the DiffHelper base class. That property is an instance of the DiffUtils object that is instantiated with the correct bean matcher. Each line of business has its own subclass of DiffHelper. For example, for personal auto, the subclass is the PADiffHelper class.

One of the important tasks of the DiffUtils instance is to compare two branch graphs and generate difference items. To customize this task, you specify the following information to an instance of the DiffUtils class.

  • A bean matcher instance – During instantiation of DiffUtils, you pass a bean matcher instance in the constructor. A bean matcher is an object that compares two objects and determines if they are equal by looking at property data rather than at a fixedID or primary key. For example, you can determine whether two cars are the same by checking their vehicle identification number. You can determine whether two contacts (PolicyContact objects) are the same by checking the name and address. You do not have to write a custom bean matcher, although you can customize the existing logic. The bean matcher in the PolicyCenter base configuration handles objects in the PolicyCenter reference implementation of the policy difference plugin.
  • Set of excluded types – Each DiffUtils instance includes a list of types to exclude. To add excluded types, call the excludeType method.
  • Set of excluded properties – Each DiffUtils instance includes a list of properties to exclude. To add excluded properties, call the excludeField method. To see syntax and examples, in Studio view the usage in the DiffHelper class.
  • Set of included properties – Each DiffUtils instance adds a list of properties to include, even if excluded by other rules. To add included properties, call the includeField method.

The typical methods that you use on the DiffUtils class are described below. To see examples of their usage, view the DiffHelper class.

  • compareBeans – Compares two entity graphs. This method compares all properties and traverses all arrays and links to a specified depth, which is the number of steps down the hierarchy to examine.
  • compareField – Compares two entity graphs starting at a specific property. The property can be a column, link, or array. From that property, compareField compares all properties and traverses all arrays and links to a specified depth, which is the number of steps down the hierarchy to examine. Pass the property as an IEntityPropertyInfo object, which you can get from the type system by using the following syntax.
    PersonalAutoLine#PALineCoverages.PropertyInfo

    The # syntax identifies a feature literal such as a property or method. The compareField method returns an ArrayList of differences as DiffItem.

To customize the built-in behavior, add logic to the class that instantiates DiffUtils. For example, for personal auto line of business, modify the PADiffHelper class, which extends DiffHelper, which instantiates DiffUtils. The addDiffItems method adds the differences.

The following example code instantiates the DiffUtils class and compares two business lines. The code adds differences for properties PersonalAutoLine.PALineCoverages and PersonalAutoLine.Vehicles.

...

// Create a new instance of DiffUtils
var diffUtils = new DiffUtils(new PCBeanMatcher()) // or any other custom BeanMatcher implementation

// Include the policy lines properties
diffUtils.includeField(PolicyPeriod#Lines.PropertyInfo)

// Calculate (add) line coverage differences by comparing a field
diffItems.addAll(diffUtils.compareField( line1, line2, 
        PersonalAutoLine#PALineCoverages.PropertyInfo , 2))

// Calculate (add) vehicle differences
diffItems.addAll(diffUtils.compareField( line1, line2, 
        PersonalAutoLine#Vehicles.PropertyInfo, 2))
...