Package org.javers.core
Class Changes
- All Implemented Interfaces:
Serializable,Iterable<Change>,Collection<Change>,List<Change>
Convenient wrapper for the list of Changes returned by
Can be used as
Javers.findChanges(JqlQuery).
Can be used as
List<Change>,
but also provides additional methods:
groupByCommit(),groupByObject()— allow traversing over the list of Changes grouped by commits and grouped by objectsgetChangesByType(Class)— a subset of Changes with a given typeprettyPrint()— prints Changes to a String, nicely formatted, user-readable styledevPrint()— prints Changes to a String, simple and technical style
- Since:
- 3.9
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondevPrint()Prints the Changes in a technical style.get(int index) getChangesByType(Class<C> type) Returns a subset of Changes with a given typegetPropertyChanges(String propertyName) Returns changes grouped by commits.Changes grouped by entities.final StringPrints the list of Changes to a nicely formatted String.
Can be used on GUI to show Changes to your users.intsize()toString()Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Constructor Details
-
Changes
-
-
Method Details
-
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, likedevPrint(), 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
-
groupByObject
Changes grouped by entities.
See example ingroupByCommit()- Since:
- 3.9
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<Change>- Specified by:
sizein interfaceList<Change>- Specified by:
sizein classAbstractCollection<Change>
-
getChangesByType
Returns a subset of Changes with a given type -
toString
- Overrides:
toStringin classAbstractCollection<Change>
-
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
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
(ifprettyPrint()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 }
-