org.javers.core.ChangesByCommit Maven / Gradle / Ivy
package org.javers.core;
import org.javers.common.string.PrettyValuePrinter;
import org.javers.common.validation.Validate;
import org.javers.core.commit.CommitMetadata;
import org.javers.core.diff.Change;
import java.util.Collections;
import java.util.List;
/**
* List of Changes done in a specific commit.
*
*
* {@link #getCommit()}} commit metadata
* {@link #get()} list of Changes
*
*/
public final class ChangesByCommit {
private final List changes;
private final CommitMetadata commitMetadata;
private final transient PrettyValuePrinter valuePrinter;
ChangesByCommit(CommitMetadata commitMetadata, List changes, PrettyValuePrinter valuePrinter) {
Validate.argumentsAreNotNull(commitMetadata, changes, valuePrinter);
this.changes = new Changes(changes, valuePrinter);
this.commitMetadata = commitMetadata;
this.valuePrinter = valuePrinter;
}
/**
* Prints the nicely formatted list of changes in a given commit.
* Alias to {@link #toString()}.
*/
public final String prettyPrint() {
return toString();
}
/**
* Changes grouped by entities
*/
public List groupByObject() {
return new Changes(changes, valuePrinter).groupByObject();
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("Commit " + commitMetadata.getId() +
" done by " + commitMetadata.getAuthor() +
" at " + valuePrinter.format(commitMetadata.getCommitDate()) +
" :\n");
groupByObject().forEach(it -> b.append(it.toString()));
return b.toString();
}
public List get() {
return Collections.unmodifiableList(changes);
}
public CommitMetadata getCommit() {
return commitMetadata;
}
}