package io.ebeaninternal.server.deploy;
import java.util.Map;
import java.util.Set;
public class BeanNaturalKey {
private final String[] naturalKey;
private final BeanProperty[] props;
BeanNaturalKey(String[] naturalKey, BeanProperty[] props) {
this.naturalKey = naturalKey;
this.props = props;
}
public int length() {
return naturalKey.length;
}
public boolean matchProperty(String propName) {
for (String key : naturalKey) {
if (key.equals(propName)) {
return true;
}
}
return false;
}
public boolean isSingleProperty() {
return props.length == 1;
}
public boolean matchSingleProperty(String propertyName) {
return naturalKey[0].equals(propertyName);
}
public boolean matchMultiProperties(Set<String> expressionProperties) {
if (expressionProperties.size() != naturalKey.length) {
return false;
}
for (String key : naturalKey) {
if (!expressionProperties.remove(key)) {
return false;
}
}
return expressionProperties.isEmpty();
}
public String calculateKey(Map<String, Object> map) {
StringBuilder sb = new StringBuilder();
for (BeanProperty prop : props) {
sb.append(prop.naturalKeyVal(map)).append(";");
}
return sb.toString();
}
}