Search in sources :

Example 6 with MapFilter

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);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) MapFilter(uk.gov.gchq.gaffer.function.MapFilter) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan)

Example 7 with MapFilter

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);
}
Also used : MapFilter(uk.gov.gchq.gaffer.function.MapFilter) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 8 with MapFilter

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());
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) MapFilter(uk.gov.gchq.gaffer.function.MapFilter) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 9 with MapFilter

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);
}
Also used : MapFilter(uk.gov.gchq.gaffer.function.MapFilter) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 10 with MapFilter

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);
}
Also used : MapFilter(uk.gov.gchq.gaffer.function.MapFilter) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Aggregations

MapFilter (uk.gov.gchq.gaffer.function.MapFilter)11 Test (org.junit.Test)8 FilterFunctionTest (uk.gov.gchq.gaffer.function.FilterFunctionTest)8 FreqMap (uk.gov.gchq.gaffer.types.FreqMap)3 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Exists (uk.gov.gchq.gaffer.function.filter.Exists)1 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)1