/** * Checks whether a given parameter value applies to this filter. * * @param parameterValue the value to check if applies to this parameter filter * @return {@code true} if {@code parameterValue} is valid according to this filter, {@code * false} otherwise */ @Override public boolean applies(@Nullable String parameterValue) { return getLegalValues().contains(getNormalize().apply(parameterValue)); }
@Override public String apply(@Nullable String str) throws ParameterException { if (str == null || str.length() == 0) { return getDefaultValue(); } str = getNormalize().apply(str); if (getLegalValues().contains(str)) { return str; } throw new ParameterException(str + " violates filter for parameter " + getKey()); }
@Override public StringParameterFilter clone() { StringParameterFilter clone = new StringParameterFilter(); clone.setDefaultValue(getDefaultValue()); clone.setKey(getKey()); if (values != null) { clone.values = new ArrayList<String>(values); } clone.setNormalize(getNormalize().clone()); return clone; } }
@Test public void testCloneable() throws Exception { filter.setNormalize(new CaseNormalizer(Case.UPPER, Locale.ENGLISH)); StringParameterFilter clone = filter.clone(); assertThat(clone.getDefaultValue(), equalTo(filter.getDefaultValue())); assertThat(clone.getValues(), equalTo(filter.getValues())); assertThat( clone.getNormalize().getConfiguredLocale(), equalTo(filter.getNormalize().getConfiguredLocale())); assertThat(clone.getNormalize().getCase(), equalTo(filter.getNormalize().getCase())); } }
@Test public void testBasic() throws Exception { assertThat( filter.getNormalize(), allOf( hasProperty("case", equalTo(Case.NONE)),