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)
.
Allows traversing over the list of Changes grouped by commits and grouped by entities, see:
groupByCommit()
,groupByObject()
.
prettyPrint()
prints Changes to the the nicely formatted String.- Since:
- 3.9
- See Also:
- 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 Change
get(int index)
<C extends Change>
java.util.List<C>getChangesByType(java.lang.Class<C> type)
java.util.List<ChangesByCommit>
groupByCommit()
Changes grouped by commits.java.util.List<ChangesByObject>
groupByObject()
Changes grouped by entities.java.lang.String
prettyPrint()
Prints the nicely formatted list of Changes.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()
Changes grouped by commits.
When formatting a changelog, usually you need to group changes by commits and then by objects.
For example, this changelog:commit 2.0 changes on Employee/Frodo : - ValueChange{ 'salary' changed from '10000' to '11000' } - ListChange{ 'subordinates' collection changes : 0. 'Employee/Sam' added } changes on Employee/Sam : - ValueChange{ 'name' changed from '' to 'Sam' } - ValueChange{ 'salary' changed from '0' to '2000' } - ReferenceChange{ 'boss' changed from '' to 'Employee/Frodo' } - NewObject{ new object: Employee/Sam } commit 1.0 changes on Employee/Frodo : - ValueChange{ 'name' changed from '' to 'Frodo' } - ValueChange{ 'salary' changed from '0' to '10000' } - NewObject{ new object: Employee/Frodo }
is printed by this code:Changes changes = javers.findChanges(QueryBuilder.byClass(Employee.class) .withNewObjectChanges().build()); 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
- See Also:
- http://javers.org/documentation/repository-examples/#change-log
-
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)
-
prettyPrint
public final java.lang.String prettyPrint()
Prints the nicely formatted list of Changes. Alias totoString()
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<Change>
-
-