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

com.kenshoo.pl.entity.internal.audit.AuditMandatoryFieldValuesGenerator 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.audit;

import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityFieldValue;
import com.kenshoo.pl.entity.FinalEntityState;
import org.apache.commons.lang3.tuple.ImmutablePair;

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

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static org.jooq.lambda.Seq.seq;

public class AuditMandatoryFieldValuesGenerator {

    private final Collection> mandatoryFields;

    public AuditMandatoryFieldValuesGenerator(final Stream> mandatoryFields) {
        requireNonNull(mandatoryFields, "mandatoryFields must not be null (can be empty)");
        this.mandatoryFields = mandatoryFields.collect(toList());
    }

    Collection generate(final FinalEntityState finalState) {
        requireNonNull(finalState, "finalState is required");
        return seq(mandatoryFields)
            .map(field -> ImmutablePair.of(field, finalState.safeGet(field)))
            .filter(pair -> pair.getValue().isNotNull())
            .map(pair -> new EntityFieldValue(pair.getKey(), pair.getValue().get()))
            .collect(toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy