use of uk.gov.gchq.koryphe.impl.function.ToString in project gaffer-doc by gchq.
the class ToStringExample method objectToString.
public void objectToString() {
// ---------------------------------------------------------
final ToString function = new ToString();
// ---------------------------------------------------------
runExample(function, null, 1, 2.5, "abc", null);
}
use of uk.gov.gchq.koryphe.impl.function.ToString in project gaffer-doc by gchq.
the class TransformExample method transformACountPropertyIntoACountStringPropertyOnlyForEdgesOfTypeEdge.
public void transformACountPropertyIntoACountStringPropertyOnlyForEdgesOfTypeEdge() {
// ---------------------------------------------------------
final Transform transform = new Transform.Builder().edge("edge", new ElementTransformer.Builder().select("count").execute(new ToString()).project("countString").build()).build();
// ---------------------------------------------------------
showExample(transform, null);
}
use of uk.gov.gchq.koryphe.impl.function.ToString in project Gaffer by gchq.
the class MapHandlerTest method shouldBuildWithInvalidArgumentsAndFailExecution.
@Test
public void shouldBuildWithInvalidArgumentsAndFailExecution() throws OperationException {
final List<Function> functions = new ArrayList<>();
final Function<Long, Double> func = Double::longBitsToDouble;
final Function<String, Integer> func1 = Integer::valueOf;
functions.add(new ToString());
functions.add(func);
functions.add(func1);
final Map map = new Map();
map.setInput(3);
map.setFunctions(functions);
final MapHandler handler = new MapHandler();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(map, context, store)).withMessage("The input/output types of the functions were incompatible");
}
use of uk.gov.gchq.koryphe.impl.function.ToString in project Gaffer by gchq.
the class MapHandlerTest method shouldMapMultipleObjectsAtOnce.
@Test
public void shouldMapMultipleObjectsAtOnce() throws OperationException {
// Given
final MapHandler<Iterable<Integer>, String> handler = new MapHandler<>();
final Map<Iterable<Integer>, String> operation = new Map.Builder<Iterable<Integer>>().input(Arrays.asList(1, 2)).first(Object::toString).build();
// When
final String result = handler.doOperation(operation, context, store);
// Then
assertNotNull(result);
assertEquals("[1, 2]", result);
}
use of uk.gov.gchq.koryphe.impl.function.ToString in project Gaffer by gchq.
the class MapHandlerTest method shouldReturnIterableFromOperation.
@Test
public void shouldReturnIterableFromOperation() throws OperationException {
// Given
final Iterable<Iterable<Integer>> input = Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9));
final MapHandler<Iterable<Iterable<Integer>>, String> handler = new MapHandler<>();
final Map<Iterable<Iterable<Integer>>, String> operation = new Map.Builder<Iterable<Iterable<Integer>>>().input(input).first(new IterableFunction.Builder<Iterable<Integer>>().first(new NthItem<>(1)).then(Object::toString).build()).then(new NthItem<>(2)).build();
// When
final String results = handler.doOperation(operation, context, store);
// Then
assertNotNull(results);
assertEquals("8", results);
}
Aggregations