com.kenshoo.pl.entity.internal.OverrideFieldsCombination Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.pl.entity.internal;
import com.kenshoo.pl.entity.CurrentEntityState;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.FieldsValueMap;
import com.kenshoo.pl.entity.spi.FieldsCombinationValidator;
import java.util.Map;
public class OverrideFieldsCombination> implements FieldsValueMap {
private final FieldsValueMap fieldsValueMap;
private final Map, FieldsCombinationValidator.Substitution> overrideFieldValueFunctions;
private final CurrentEntityState currentState;
public OverrideFieldsCombination(CurrentEntityState currentState, FieldsValueMap fieldsValueMap, Map, FieldsCombinationValidator.Substitution> overrideFieldValueFunctions) {
this.currentState = currentState;
this.fieldsValueMap = fieldsValueMap;
this.overrideFieldValueFunctions = overrideFieldValueFunctions;
}
@Override
public boolean containsField(EntityField field) {
return fieldsValueMap.containsField(field);
}
@Override
public T get(EntityField field) {
T value = fieldsValueMap.get(field);
return overrideValue(field, value);
}
private T overrideValue(EntityField field, T result) {
if(overrideFieldValueFunctions.isEmpty()) {
return result;
}
if(overrideFieldValueFunctions.containsKey(field)) {
//noinspection unchecked
FieldsCombinationValidator.Substitution overrideFieldFunction = (FieldsCombinationValidator.Substitution) overrideFieldValueFunctions.get(field);
if(overrideFieldFunction.overrideWhen().test(result)) {
return overrideFieldFunction.overrideHow().apply(currentState);
}
}
return result;
}
}