cdc.util.rdb.tools.dump.AbstractConfig Maven / Gradle / Ivy
package cdc.util.rdb.tools.dump;
import java.util.Collection;
import cdc.util.lang.Checks;
/**
* Base abstract configuration.
*
* @author Damien Carbonne
*
*/
public abstract class AbstractConfig {
/**
* Parent config.
*
* Used to inherit default processing.
*/
private final AbstractConfig parent;
/**
* Default processing.
*
* Can be overridden, whatever the parent says.
*/
private Processing processing = Processing.INHERIT;
private String note;
AbstractConfig(AbstractConfig parent) {
this.parent = parent;
}
public AbstractConfig getParent() {
return parent;
}
public final void setProcessing(Processing processing) {
Checks.isNotNull(processing, "processing");
if (parent == null && processing == Processing.INHERIT) {
throw new IllegalArgumentException("Can not set " + processing + " on root config");
}
this.processing = processing;
}
public final Processing getProcessing() {
return processing;
}
public final EffectiveProcessing getInheritedProcessing() {
if (parent == null) {
// Should be KEEP or IGNORE
return EffectiveProcessing.from(processing);
} else {
if (processing == Processing.INHERIT) {
return parent.getInheritedProcessing();
} else {
return EffectiveProcessing.from(processing);
}
}
}
public abstract EffectiveProcessing getEffectiveProcessing();
protected EffectiveProcessing toEffectiveProcessing(Collection extends AbstractConfig> children) {
if (children.isEmpty()) {
return getInheritedProcessing();
} else {
for (final AbstractConfig child : children) {
if (child.getEffectiveProcessing() == EffectiveProcessing.KEEP) {
return EffectiveProcessing.KEEP;
}
}
return EffectiveProcessing.IGNORE;
}
}
public void setNote(String note) {
this.note = note;
}
public String getNote() {
return note;
}
}