org.javers.core.CoreConfigurationBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.core;
import org.javers.common.string.PrettyValuePrinter;
import org.javers.common.validation.Validate;
import org.javers.core.commit.CommitId;
import org.javers.core.diff.ListCompareAlgorithm;
import java.util.function.Supplier;
class CoreConfigurationBuilder {
private PrettyValuePrinter prettyValuePrinter = PrettyValuePrinter.getDefault();
private MappingStyle mappingStyle = MappingStyle.FIELD;
private ListCompareAlgorithm listCompareAlgorithm = ListCompareAlgorithm.SIMPLE;
private boolean prettyPrint = true;
private boolean initialChanges = true;
private boolean terminalChanges = true;
private boolean usePrimitiveDefaults = true;
private CommitIdGenerator commitIdGenerator = CommitIdGenerator.SYNCHRONIZED_SEQUENCE;
private Supplier customCommitIdGenerator;
private CoreConfigurationBuilder() {
}
static CoreConfigurationBuilder coreConfiguration() {
return new CoreConfigurationBuilder();
}
CoreConfiguration build() {
return new CoreConfiguration(
prettyValuePrinter,
mappingStyle,
listCompareAlgorithm,
initialChanges,
commitIdGenerator,
customCommitIdGenerator,
terminalChanges,
prettyPrint,
usePrimitiveDefaults
);
}
CoreConfigurationBuilder withPrettyPrint(boolean prettyPrint) {
this.prettyPrint = prettyPrint;
return this;
}
CoreConfigurationBuilder withMappingStyle(MappingStyle mappingStyle) {
Validate.argumentIsNotNull(mappingStyle);
this.mappingStyle = mappingStyle;
return this;
}
CoreConfigurationBuilder withCommitIdGenerator(CommitIdGenerator commitIdGenerator) {
Validate.argumentIsNotNull(commitIdGenerator);
Validate.argumentCheck(commitIdGenerator != CommitIdGenerator.CUSTOM, "use withCustomCommitIdGenerator(Supplier)");
this.commitIdGenerator = commitIdGenerator;
this.customCommitIdGenerator = null;
return this;
}
CoreConfigurationBuilder withCustomCommitIdGenerator(Supplier customCommitIdGenerator) {
Validate.argumentIsNotNull(customCommitIdGenerator);
this.commitIdGenerator = CommitIdGenerator.CUSTOM;
this.customCommitIdGenerator = customCommitIdGenerator;
return this;
}
CoreConfigurationBuilder withInitialChanges(boolean initialChanges) {
this.initialChanges = initialChanges;
return this;
}
CoreConfigurationBuilder withTerminalChanges(boolean terminalChanges) {
this.terminalChanges = terminalChanges;
return this;
}
CoreConfigurationBuilder withUsePrimitiveDefaults(boolean usePrimitiveDefaults) {
this.usePrimitiveDefaults = usePrimitiveDefaults;
return this;
}
CoreConfigurationBuilder withListCompareAlgorithm(ListCompareAlgorithm algorithm) {
Validate.argumentIsNotNull(algorithm);
this.listCompareAlgorithm = algorithm;
return this;
}
CoreConfigurationBuilder withPrettyPrintDateFormats(JaversCoreProperties.PrettyPrintDateFormats prettyPrintDateFormats) {
Validate.argumentIsNotNull(prettyPrintDateFormats);
prettyValuePrinter = new PrettyValuePrinter(prettyPrintDateFormats);
return this;
}
}