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 });
}
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 });
}
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 });
}
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;
}
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);
}
Aggregations