Search in sources :

Example 1 with ToString

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);
}
Also used : ToString(uk.gov.gchq.koryphe.impl.function.ToString)

Example 2 with ToString

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);
}
Also used : Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) ToString(uk.gov.gchq.koryphe.impl.function.ToString)

Example 3 with ToString

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");
}
Also used : Function(java.util.function.Function) IterableFunction(uk.gov.gchq.koryphe.impl.function.IterableFunction) ArrayList(java.util.ArrayList) ToString(uk.gov.gchq.koryphe.impl.function.ToString) ToString(uk.gov.gchq.koryphe.impl.function.ToString) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 4 with ToString

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);
}
Also used : ToString(uk.gov.gchq.koryphe.impl.function.ToString) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 5 with ToString

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);
}
Also used : NthItem(uk.gov.gchq.koryphe.impl.function.NthItem) ToString(uk.gov.gchq.koryphe.impl.function.ToString) Test(org.junit.jupiter.api.Test)

Aggregations

ToString (uk.gov.gchq.koryphe.impl.function.ToString)11 Test (org.junit.jupiter.api.Test)8 Map (uk.gov.gchq.gaffer.operation.impl.Map)3 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)3 FunctionComposite (uk.gov.gchq.koryphe.function.FunctionComposite)2 IterableFunction (uk.gov.gchq.koryphe.impl.function.IterableFunction)2 Length (uk.gov.gchq.koryphe.impl.function.Length)2 TupleAdaptedFunctionComposite (uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunctionComposite)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 LineIterator (org.apache.commons.io.LineIterator)1 Test (org.junit.Test)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 Properties (uk.gov.gchq.gaffer.data.element.Properties)1 ElementTupleDefinition (uk.gov.gchq.gaffer.data.element.function.ElementTupleDefinition)1