All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kenshoo.pl.entity.internal.OverrideFieldsCombination Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy