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

com.kenshoo.pl.entity.internal.ResultingFieldsCombination 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.ChangeOperation;
import com.kenshoo.pl.entity.CurrentEntityState;
import com.kenshoo.pl.entity.EntityChange;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.FieldsValueMap;

import java.util.Collection;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toSet;

public class ResultingFieldsCombination> implements FieldsValueMap {
    private final EntityChange entityChange;
    private final CurrentEntityState currentState;
    private final Collection> fields;
    private final ChangeOperation changeOperation;

    public ResultingFieldsCombination(EntityChange entityChange, CurrentEntityState currentState, Stream> fields, ChangeOperation changeOperation) {
        this.entityChange = entityChange;
        this.currentState = currentState;
        this.fields = fields.collect(toSet());
        this.changeOperation = changeOperation;
    }

    @Override
    public  boolean containsField(EntityField field) {
        return entityChange.containsField(field) ||  currentState.containsField(field);
    }

    @Override
    public  T get(EntityField field) {
        if (!fields.contains(field)) {
            throw new IllegalArgumentException("Illegal field: " + field);
        }

        if (entityChange.isFieldChanged(field)) {
            return entityChange.get(field);
        } else {
            if (changeOperation == ChangeOperation.UPDATE) {
                return  currentState.get(field);
            } else {
                return null;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy