Package org.javers.core
Class Changes
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<Change>
-
- org.javers.core.Changes
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<Change>
,java.util.Collection<Change>
,java.util.List<Change>
public class Changes extends java.util.AbstractList<Change> implements java.io.Serializable
Convenient wrapper for the list of Changes returned byJavers.findChanges(JqlQuery)
.
Can be used asList<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:
- http://javers.org/documentation/repository-examples/#change-log, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Changes(java.util.List<Change> changes, PrettyValuePrinter valuePrinter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
devPrint()
Prints the Changes in a technical style.Change
get(int index)
<C extends Change>
java.util.List<C>getChangesByType(java.lang.Class<C> type)
Returns a subset of Changes with a given typejava.util.List<PropertyChange>
getPropertyChanges(java.lang.String propertyName)
java.util.List<ChangesByCommit>
groupByCommit()
Returns changes grouped by commits.java.util.List<ChangesByObject>
groupByObject()
Changes grouped by entities.java.lang.String
prettyPrint()
Prints the list of Changes to a nicely formatted String.
Can be used on GUI to show Changes to your users.int
size()
java.lang.String
toString()
-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
-
-
-
-
Constructor Detail
-
Changes
public Changes(java.util.List<Change> changes, PrettyValuePrinter valuePrinter)
-
-
Method Detail
-
groupByCommit
public java.util.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, 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
public java.util.List<PropertyChange> getPropertyChanges(java.lang.String propertyName)
-
groupByObject
public java.util.List<ChangesByObject> groupByObject()
Changes grouped by entities.
See example ingroupByCommit()
- Since:
- 3.9
-
get
public Change get(int index)
-
size
public int size()
-
getChangesByType
public <C extends Change> java.util.List<C> getChangesByType(java.lang.Class<C> type)
Returns a subset of Changes with a given type
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<Change>
-
prettyPrint
public final java.lang.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 java.lang.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
(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 }
-
-