@Test public void valueChangedTest() { EventFilter<GenericEvent> filter = onValueChanged(stringChannel("val")); assertFalse(filter.apply(new GenericEvent(), values1)); assertTrue(filter.apply(new GenericEvent(), values2)); assertFalse(filter.apply(new GenericEvent(), valuesNull)); assertTrue(filter.apply(null, values1)); assertFalse(filter.apply(null, values1)); assertFalse(filter.apply(null, valuesNull)); assertTrue(filter.getChannelIdentifiers().contains("val")); EventFilter<GenericEvent> clone = ClonerUtil.clone(filter); assertFalse(clone.apply(null, values1)); }
@SuppressWarnings("squid:S00119") public static <EVENT extends Serializable, T extends Serializable> EventFilter<EVENT> onValueChanged(Supplier<T> supplier) { return new EventFilter<EVENT>() { private T lastValue; @Override public boolean apply(EVENT event, MRecord values) { boolean keep = false; T value = supplier.extract(values); if(value == null){ return false; } if(lastValue != null){ keep = !value.equals(lastValue); } lastValue = value; return keep; } @Override public Collection<String> getChannelIdentifiers() { return supplier.getChannelIdentifiers(); } }; }
EventFilters { @SuppressWarnings("squid:S00119") public static <EVENT extends Serializable, T extends Serializable> EventFilter<EVENT> onValueChanged(Supplier<T> supplier) { return new EventFilter<EVENT>() { private T lastValue; @Override public boolean apply(EVENT event, MRecord values) { boolean keep = false; T value = supplier.extract(values); if(value == null){ return false; } if(lastValue != null){ keep = !value.equals(lastValue); } lastValue = value; return keep; } @Override public Collection<String> getChannelIdentifiers() { return supplier.getChannelIdentifiers(); } }; } }
EventFilters { @SuppressWarnings("squid:S00119") public static <EVENT extends Serializable, T extends Serializable> EventFilter<EVENT> onValueChanged(Supplier<T> supplier) { return new EventFilter<EVENT>() { private T lastValue; @Override public boolean apply(EVENT event, MRecord values) { boolean keep = false; T value = supplier.extract(values); if(value == null){ return false; } if(lastValue != null){ keep = !value.equals(lastValue); } lastValue = value; return keep; } @Override public Collection<String> getChannelIdentifiers() { return supplier.getChannelIdentifiers(); } }; } private  EventFilters(); }
EventFilters { @SuppressWarnings("squid:S00119") public static <EVENT extends Serializable, T extends Serializable> EventFilter<EVENT> onValueChanged(Supplier<T> supplier) { return new EventFilter<EVENT>() { private T lastValue; @Override public boolean apply(EVENT event, MRecord values) { boolean keep = false; T value = supplier.extract(values); if(value == null){ return false; } if(lastValue != null){ keep = !value.equals(lastValue); } lastValue = value; return keep; } @Override public Collection<String> getChannelIdentifiers() { return supplier.getChannelIdentifiers(); } }; } private  EventFilters(); @SuppressWarnings("squid:S00119") static EventFilter<EVENT> onValueChanged(Supplier<T> supplier); }
EventFilters { @SuppressWarnings("squid:S00119") public static <EVENT extends Serializable, T extends Serializable> EventFilter<EVENT> onValueChanged(Supplier<T> supplier) { return new EventFilter<EVENT>() { private T lastValue; @Override public boolean apply(EVENT event, MRecord values) { boolean keep = false; T value = supplier.extract(values); if(value == null){ return false; } if(lastValue != null){ keep = !value.equals(lastValue); } lastValue = value; return keep; } @Override public Collection<String> getChannelIdentifiers() { return supplier.getChannelIdentifiers(); } }; } private  EventFilters(); @SuppressWarnings("squid:S00119") static EventFilter<EVENT> onValueChanged(Supplier<T> supplier);  }