scray.common.properties.StringProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scray-common Show documentation
Show all versions of scray-common Show documentation
scray artefacts shared between scala and java components
package scray.common.properties;
import java.util.regex.Pattern;
public class StringProperty extends Property {
private String name = null;
private String defaultValue = null;
public StringProperty(String name) {
this.name = name;
}
public StringProperty(String name, String defaultValue) {
this(name);
this.defaultValue = defaultValue;
}
@Override
public boolean hasDefault() {
return defaultValue != null;
}
@Override
public String getDefault() {
return defaultValue;
}
@Override
public String getName() {
return name;
}
public void addRegexConstraint(final String pattern) {
super.addConstraint(new PropertyConstraint() {
Pattern patMatch = Pattern.compile(pattern);
@Override
public boolean checkConstraint(String value) {
return patMatch.matcher(pattern).find();
}
});
}
@Override
public boolean checkConstraintsOnValue(Object value) {
if(value instanceof String) {
return checkConstraints((String)value);
}
return false;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy