Class Changes

All Implemented Interfaces:
Serializable, Iterable<Change>, Collection<Change>, List<Change>

public class Changes extends AbstractList<Change> implements Serializable
Convenient wrapper for the list of Changes returned by Javers.findChanges(JqlQuery).

Can be used as List<Change>, but also provides additional methods:

Since:
3.9
See Also:
  • Constructor Details

  • Method Details

    • groupByCommit

      public List<ChangesByCommit> groupByCommit()
      Returns changes grouped by commits.
      When formatting a changelog, usually you need to group changes by commits and then by objects.

      A simple changelog, like devPrint(), can be printed by this code:

       changes.groupByCommit().forEach(byCommit -> {
         System.out.println("commit " + byCommit.getCommit().getId());
         byCommit.groupByObject().forEach(byObject -> {
           System.out.println("  changes on " + byObject.getGlobalId().value() + ":");
           byObject.get().forEach(change -> System.out.println("  - " + change));
         });
       });
       
      Since:
      3.9
    • getPropertyChanges

      public List<PropertyChange> getPropertyChanges(String propertyName)
    • groupByObject

      public List<ChangesByObject> groupByObject()
      Changes grouped by entities.
      See example in groupByCommit()
      Since:
      3.9
    • get

      public Change get(int index)
      Specified by:
      get in interface List<Change>
      Specified by:
      get in class AbstractList<Change>
    • size

      public int size()
      Specified by:
      size in interface Collection<Change>
      Specified by:
      size in interface List<Change>
      Specified by:
      size in class AbstractCollection<Change>
    • getChangesByType

      public <C extends Change> List<C> getChangesByType(Class<C> type)
      Returns a subset of Changes with a given type
    • toString

      public String toString()
      Delegates to devPrint().
      See prettyPrint()
      Overrides:
      toString in class AbstractCollection<Change>
    • prettyPrint

      public final String prettyPrint()
      Prints the list of Changes to a nicely formatted String.
      Can be used on GUI to show Changes to your users.

      Example:

       Changes:
       Commit 2.00 done by author at 14 Mar 2021, 12:37:37 :
       * changes on Employee/Frodo :
         - 'lastPromotionDate' = '14.37.2021 12:37'
         - 'performance' map changes :
            · entry ['1' : 'bb'] -> ['1' : 'aa']
            · entry ['2' : 'bb'] added
            · entry ['3' : 'aa'] removed
         - 'position' = 'Hero'
         - 'postalAddress.city' = 'Shire'
         - 'primaryAddress.city' changed: 'Shire' -> 'Mordor'
         - 'primaryAddress.street' = 'Some Street'
         - 'salary' changed: '10000' -> '12000'
         - 'skills' collection changes :
            · 'agile coaching' added
         - 'subordinates' collection changes :
            0. 'Employee/Sam' added
       * new object: Employee/Sam
         - 'name' = 'Sam'
         - 'salary' = '10000'
       Commit 1.00 done by author at 14 Mar 2021, 12:37:37 :
       * new object: Employee/Frodo
         - 'name' = 'Frodo'
         - 'performance' map changes :
            · entry ['1' : 'bb'] added
            · entry ['3' : 'aa'] added
         - 'primaryAddress.city' = 'Shire'
         - 'salary' = '10000'
         - 'skills' collection changes :
            · 'management' added
       
    • devPrint

      public String devPrint()
      Prints the Changes in a technical style.
      Useful for development and debugging.

      You can use the implementation of this method as a template to create your own changelog
      (if prettyPrint() is not ok for you).

      Example:

       Changes (18):
       commit 2.00
         changes on Employee/Frodo :
         - ValueChange{ property: 'city', left:'Shire',  right:'Mordor' }
         - ValueChange{ property: 'street', left:'',  right:'Some Street' }
         - ValueChange{ property: 'position', left:'',  right:'Hero' }
         - ValueChange{ property: 'salary', left:'10000',  right:'12000' }
         - ListChange{ property: 'subordinates', elementChanges:1 }
         - SetChange{ property: 'skills', elementChanges:1 }
         - MapChange{ property: 'performance', entryChanges:3 }
         - ValueChange{ property: 'lastPromotionDate', left:'',  right:'14 Mar 2021, 12:58:06+0100' }
         - InitialValueChange{ property: 'city', left:'',  right:'Shire' }
         changes on Employee/Sam :
         - NewObject{ new object: Employee/Sam }
         - InitialValueChange{ property: 'name', left:'',  right:'Sam' }
         - InitialValueChange{ property: 'salary', left:'',  right:'10000' }
       commit 1.00
         changes on Employee/Frodo :
         - InitialValueChange{ property: 'city', left:'',  right:'Shire' }
         - NewObject{ new object: Employee/Frodo }
         - InitialValueChange{ property: 'name', left:'',  right:'Frodo' }
         - InitialValueChange{ property: 'salary', left:'',  right:'10000' }
         - SetChange{ property: 'skills', elementChanges:1 }
         - MapChange{ property: 'performance', entryChanges:2 }