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

scray.common.properties.StringProperty Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
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