use of uk.gov.gchq.gaffer.function.MapFilter in project Gaffer by gchq.
the class MapFilterExample method freqMapIsMoreThan2.
public void freqMapIsMoreThan2() {
// ---------------------------------------------------------
final MapFilter function = new MapFilter("key1", new IsMoreThan(2L));
// ---------------------------------------------------------
final FreqMap map1 = new FreqMap();
map1.put("key1", 1L);
final FreqMap map2 = new FreqMap();
map2.put("key1", 2L);
final FreqMap map3 = new FreqMap();
map3.put("key1", 3L);
final FreqMap map4 = new FreqMap();
map4.put("key1", 3L);
map4.put("key2", 0L);
final FreqMap map5 = new FreqMap();
map5.put("key2", 3L);
runExample(function, map1, map2, map3, map4, map5);
}
use of uk.gov.gchq.gaffer.function.MapFilter in project Gaffer by gchq.
the class FreqMapIsMoreThanTest method shouldRejectWhenLessThan10.
@Test
public void shouldRejectWhenLessThan10() {
// Given
final MapFilter filter = new MapFilter(KEY1, new IsMoreThan(10L));
// When
boolean accepted = filter.isValid(new Object[] { map1 });
// Then
assertFalse(accepted);
}
use of uk.gov.gchq.gaffer.function.MapFilter in project Gaffer by gchq.
the class FreqMapIsMoreThanTest method shouldJsonSerialiseAndDeserialise.
@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
// Given
final MapFilter filter = new MapFilter(KEY1, new IsMoreThan(1L, true));
// When
final String json = new String(new JSONSerialiser().serialise(filter, true));
// Then
JsonUtil.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.gaffer.function.MapFilter\",%n" + " \"function\" : {%n" + " \"class\" : \"uk.gov.gchq.gaffer.function.filter.IsMoreThan\",%n" + " \"orEqualTo\" : true,%n" + " \"value\" : {%n" + " \"java.lang.Long\" : 1%n" + " }%n" + " },%n" + " \"key\" : \"key1\"%n" + "}"), json);
// When 2
final MapFilter deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), MapFilter.class);
// Then 2
assertNotNull(deserialisedFilter);
assertEquals(KEY1, deserialisedFilter.getKey());
}
use of uk.gov.gchq.gaffer.function.MapFilter in project Gaffer by gchq.
the class FreqMapIsMoreThanTest method shouldAcceptWhenFreqIsEqualTo1.
@Test
public void shouldAcceptWhenFreqIsEqualTo1() {
// Given
final MapFilter filter = new MapFilter(KEY1, new IsMoreThan(1L, true));
// When
boolean accepted = filter.isValid(new Object[] { map1 });
// Then
assertTrue(accepted);
}
use of uk.gov.gchq.gaffer.function.MapFilter in project Gaffer by gchq.
the class FreqMapIsMoreThanTest method shouldRejectWhenKeyNotPresent.
@Test
public void shouldRejectWhenKeyNotPresent() {
// Given
final MapFilter filter = new MapFilter(KEY2, new IsMoreThan(10L));
// When
boolean accepted = filter.isValid(new Object[] { map1 });
// Then
assertFalse(accepted);
}
Aggregations