@Override public IntegerParameterFilter clone() { IntegerParameterFilter clone = new IntegerParameterFilter(); clone.setDefaultValue(getDefaultValue()); clone.setKey(getKey()); if (values != null) { clone.values = new ArrayList<Integer>(values); } clone.setThreshold(this.threshold); return clone; } }
@Override public @Nullable List<String> getLegalValues() { List<String> ret = new LinkedList<String>(); Iterator<Integer> iter = getValues().iterator(); while (iter.hasNext()) { ret.add(Integer.toString(iter.next())); } return ret; }
/** @param threshold the threshold to set */ public void setThreshold(@Nullable Integer threshold) { if (threshold == null) threshold = getDefaultThreshold(); this.threshold = threshold; }
@Before public void setUp() { filter = new IntegerParameterFilter(); filter.setKey("TEST"); filter.setValues(Arrays.asList(42, 2, 0, -1, -200)); filter.setDefaultValue("Default"); filter.setThreshold(1); xs = new GeoWebCacheXStream(); xs = XMLConfiguration.getConfiguredXStream(xs, new StaticWebApplicationContext()); }
@Test public void testCloneable() throws Exception { IntegerParameterFilter clone = filter.clone(); assertThat(clone.getDefaultValue(), equalTo(filter.getDefaultValue())); assertThat(clone.getValues(), equalTo(filter.getValues())); } }
@Override public String apply(@Nullable String str) throws ParameterException { if (str == null || str.length() == 0) { return getDefaultValue(); Iterator<Integer> iter = getValues().iterator(); while (iter.hasNext()) { int fl = iter.next();
@Test public void testThreshold() throws Exception { filter.setThreshold(15); filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo(test)); filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo("42")); filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo("2")); filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo("0")); filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo("-1")); filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo("-200")); filter.applies(test), Matchers.describedAs("Filter should not apply to %0", is(false), test));
@Test public void testBasic() throws Exception { assertThat(filter.getLegalValues(), containsInAnyOrder("42", "2", "0", "-1", "-200")); for (String test : Arrays.asList("42", "2", "0", "-1", "-200")) { assertThat( filter.applies(test), Matchers.describedAs("Filter should apply to %0", is(true), test)); assertThat(filter.apply(test), equalTo(test)); } for (String test : Arrays.asList("43", "41", "3", "1", "-2", "-199", "-201", "-42")) { assertThat(filter.applies(test), is(false)); try { filter.apply(test); fail(); } catch (Exception ex) { assertThat(ex, instanceOf(ParameterException.class)); } } assertThat(filter.apply(null), equalTo("Default")); assertThat(filter.apply(""), equalTo("Default")); }
protected Object readResolve() { super.readResolve(); if (values == null) { values = new ArrayList<Integer>(0); } if (threshold == null) { threshold = getDefaultThreshold(); } for (Integer value : values) { Preconditions.checkNotNull(value, "Value list included a null pointer."); } return this; }