io.github.dheid.roperty.mongodb.ValueAnalyzer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of roperty-mongodb Show documentation
Show all versions of roperty-mongodb Show documentation
A MongoDB persistence implementation for Roperty
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;
}
}