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

io.github.dheid.roperty.mongodb.ValueAnalyzer Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package io.github.dheid.roperty.mongodb;

import com.parship.roperty.DomainSpecificValue;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.bson.Document;

import java.util.Objects;

import static io.github.dheid.roperty.mongodb.RopertyMongoDbAttribute.CHANGE_SET;
import static io.github.dheid.roperty.mongodb.RopertyMongoDbAttribute.PATTERN;

public class ValueAnalyzer {

    private DomainSpecificValue domainSpecificValue;

    public void setDomainSpecificValue(DomainSpecificValue domainSpecificValue) {
        Validate.notNull(domainSpecificValue, "Domain specific value must not be null");
        this.domainSpecificValue = domainSpecificValue;
    }

    public boolean samePatternAndChangeSetAs(Document valueDocument) {
        Validate.notNull(valueDocument, "Value document must not be null");
        Validate.notNull(domainSpecificValue, "Domain specific value must not be null");
        return Objects.equals(domainSpecificValue.getPatternStr(), valueDocument.getString(PATTERN.getName())) &&
                domainSpecificValue.changeSetIs(nullIfEmpty(valueDocument.getString(CHANGE_SET.getName())));
    }

    private String nullIfEmpty(String string) {
        if (StringUtils.isEmpty(string)) {
            return null;
        }

        return string;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy