Search in sources :

Example 6 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class AndExample method property1IsLessThan2AndProperty2IsMoreThan2.

public void property1IsLessThan2AndProperty2IsMoreThan2() {
    // ---------------------------------------------------------
    final And function = new And(Arrays.asList(new ConsumerFunctionContext.Builder<Integer, FilterFunction>().select(// select first property
    0).execute(new IsLessThan(2)).build(), new ConsumerFunctionContext.Builder<Integer, FilterFunction>().select(// select second property
    1).execute(new IsMoreThan(2)).build()));
    // ---------------------------------------------------------
    runExample(function, new Object[] { 1, 3 }, new Object[] { 1, 1 }, new Object[] { 3, 3 }, new Object[] { 3, 1 }, new Object[] { 1L, 3L }, new Object[] { 1 });
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) And(uk.gov.gchq.gaffer.function.filter.And) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan)

Example 7 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class OrExample method property1IsLessThan2OrProperty2IsMoreThan2.

public void property1IsLessThan2OrProperty2IsMoreThan2() {
    // ---------------------------------------------------------
    final Or function = new Or(Arrays.asList(new ConsumerFunctionContext.Builder<Integer, FilterFunction>().select(// select first property
    0).execute(new IsLessThan(2)).build(), new ConsumerFunctionContext.Builder<Integer, FilterFunction>().select(// select second property
    1).execute(new IsMoreThan(2)).build()));
    // ---------------------------------------------------------
    runExample(function, new Object[] { 1, 3 }, new Object[] { 1, 1 }, new Object[] { 3, 3 }, new Object[] { 3, 1 }, new Object[] { 1L, 3L }, new Object[] { 1 });
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Or(uk.gov.gchq.gaffer.function.filter.Or) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan)

Example 8 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class OrExample method isLessThan2OrIsMoreThan2.

public void isLessThan2OrIsMoreThan2() {
    // ---------------------------------------------------------
    final Or function = new Or(Arrays.asList(new ConsumerFunctionContext.Builder<Integer, FilterFunction>().select(// select first property
    0).execute(new IsLessThan(2)).build(), new ConsumerFunctionContext.Builder<Integer, FilterFunction>().select(// select first property
    0).execute(new IsMoreThan(2)).build()));
    // ---------------------------------------------------------
    runExample(function, new Object[] { 1 }, new Object[] { 2 }, new Object[] { 3 }, new Object[] { 1L }, new Object[] { 3L });
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Or(uk.gov.gchq.gaffer.function.filter.Or) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan)

Example 9 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class GraphConfigurationService method getFilterFunctions.

@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<Class> getFilterFunctions(final String inputClass) {
    if (StringUtils.isEmpty(inputClass)) {
        return getFilterFunctions();
    }
    final Class<?> clazz;
    try {
        clazz = Class.forName(inputClass);
    } catch (final Exception e) {
        throw new IllegalArgumentException("Input class was not recognised: " + inputClass, e);
    }
    final Set<Class> classes = new HashSet<>();
    for (final Class functionClass : FILTER_FUNCTIONS) {
        try {
            final FilterFunction function = (FilterFunction) functionClass.newInstance();
            final Class<?>[] inputs = function.getInputClasses();
            if (inputs.length == 1 && inputs[0].isAssignableFrom(clazz)) {
                classes.add(functionClass);
            }
        } catch (final Exception e) {
            // just add the function.
            classes.add(functionClass);
        }
    }
    return classes;
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) HashSet(java.util.HashSet) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 10 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class NotTest method shouldAcceptTheValueWhenTheWrappedFunctionReturnsFalse.

@Test
public void shouldAcceptTheValueWhenTheWrappedFunctionReturnsFalse() {
    // Given
    final FilterFunction function = mock(FilterFunction.class);
    final Not filter = new Not(function);
    final Object[] input = new Object[] { "some value" };
    given(function.isValid(input)).willReturn(false);
    // When
    boolean accepted = filter.isValid(input);
    // Then
    assertTrue(accepted);
    verify(function).isValid(input);
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Aggregations

FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)22 Test (org.junit.Test)14 FilterFunctionTest (uk.gov.gchq.gaffer.function.FilterFunctionTest)11 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)6 ArrayTuple (uk.gov.gchq.gaffer.function.ArrayTuple)4 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)4 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 And (uk.gov.gchq.gaffer.function.filter.And)2 Or (uk.gov.gchq.gaffer.function.filter.Or)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 HashMap (java.util.HashMap)1 InputMismatchException (java.util.InputMismatchException)1 List (java.util.List)1 Set (java.util.Set)1 Filter (org.apache.spark.sql.sources.Filter)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 ElementTuple (uk.gov.gchq.gaffer.data.element.ElementTuple)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1