use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class Filter method cloneFunctions.
/**
* Create a deep copy of the {@link uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext}s executed by this
* <code>Filter</code>.
*
* @return Deep copy of {@link uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext}s.
*/
protected List<ConsumerFunctionContext<R, FilterFunction>> cloneFunctions() {
final List<ConsumerFunctionContext<R, FilterFunction>> functionClones = new ArrayList<>();
for (final ConsumerFunctionContext<R, FilterFunction> function : functions) {
final ConsumerFunctionContext<R, FilterFunction> cloneContext = new ConsumerFunctionContext<>();
cloneContext.setSelection(function.getSelection());
final FilterFunction af = function.getFunction();
if (af != null) {
cloneContext.setFunction(af.statelessClone());
}
functionClones.add(cloneContext);
}
return functionClones;
}
use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.
the class FilterTest method shouldBuildFilter.
@Test
public void shouldBuildFilter() {
// Given
final String reference1 = "reference 1";
final String reference2 = "reference 2";
final String reference3a = "reference 3a";
final String reference3b = "reference 3b";
final String reference5 = "reference 5";
final FilterFunction func1 = mock(FilterFunction.class);
final FilterFunction func3 = mock(FilterFunction.class);
final FilterFunction func4 = mock(FilterFunction.class);
final FilterFunction func5 = mock(FilterFunction.class);
// When - check you can build the selection/function in any order,
// although normally it will be done - select then execute.
final Filter<String> filter = new Filter.Builder<String>().select(reference1).execute(func1).select(reference2).select(new String[] { reference3a, reference3b }).execute(func3).execute(func4).execute(func5).select(reference5).build();
// Then
int i = 0;
ConsumerFunctionContext<String, FilterFunction> context = filter.getFunctions().get(i++);
assertEquals(1, context.getSelection().size());
assertEquals(reference1, context.getSelection().get(0));
assertSame(func1, context.getFunction());
context = filter.getFunctions().get(i++);
assertEquals(1, context.getSelection().size());
assertEquals(reference2, context.getSelection().get(0));
context = filter.getFunctions().get(i++);
assertEquals(2, context.getSelection().size());
assertEquals(reference3a, context.getSelection().get(0));
assertEquals(reference3b, context.getSelection().get(1));
assertSame(func3, context.getFunction());
context = filter.getFunctions().get(i++);
assertSame(func4, context.getFunction());
context = filter.getFunctions().get(i++);
assertSame(func5, context.getFunction());
assertEquals(1, context.getSelection().size());
assertEquals(reference5, context.getSelection().get(0));
assertEquals(i, filter.getFunctions().size());
}
Aggregations