com.kenshoo.pl.entity.internal.ResultingFieldsCombination 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.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;
}
}
}
}