Search in sources :

Example 1 with IsA

use of uk.gov.gchq.koryphe.impl.predicate.IsA in project gaffer-doc by gchq.

the class IfExample method applyPredicatesToInput.

public void applyPredicatesToInput() {
    // ---------------------------------------------------------
    final If<Comparable> predicate = new If<>(new IsA(Integer.class), new IsMoreThan(3), new Not<>(new IsA(String.class)));
    // ---------------------------------------------------------
    runExample(predicate, "This example tests first whether the input is an Integer. " + "If so, it is then tested to see if the value is greater than 3. " + "Otherwise, since it is not an Integer, we then test to see if it is NOT a String.", 2, 3, 5, "test", new HashMap<>(), new ArrayList<>());
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) If(uk.gov.gchq.koryphe.impl.predicate.If)

Example 2 with IsA

use of uk.gov.gchq.koryphe.impl.predicate.IsA in project gaffer-doc by gchq.

the class IsAExample method isANumber.

public void isANumber() {
    // ---------------------------------------------------------
    final IsA function = new IsA(Number.class);
    // ---------------------------------------------------------
    runExample(function, null, 1, 2.5, "abc");
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA)

Example 3 with IsA

use of uk.gov.gchq.koryphe.impl.predicate.IsA in project Gaffer by gchq.

the class IfIT method shouldRunOtherwiseOperationsWhenConditionIsFalse.

@Test
public void shouldRunOtherwiseOperationsWhenConditionIsFalse() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.Integer")));
    ifOperation.setThen(new Map<>(Lists.newArrayList(new ToUpperCase(), new ToList())));
    ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLowerCase(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(Lists.newArrayList(INPUT_CAMEL_CASE.toLowerCase())).isInstanceOf(List.class);
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToLowerCase(uk.gov.gchq.koryphe.impl.function.ToLowerCase) ToList(uk.gov.gchq.koryphe.impl.function.ToList) ToUpperCase(uk.gov.gchq.koryphe.impl.function.ToUpperCase) Test(org.junit.Test)

Example 4 with IsA

use of uk.gov.gchq.koryphe.impl.predicate.IsA in project Gaffer by gchq.

the class IfIT method shouldDoOtherwiseWhenConditionIsFalseAndNoThenOperation.

@Test
public void shouldDoOtherwiseWhenConditionIsFalseAndNoThenOperation() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.Integer")));
    ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLowerCase(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(Lists.newArrayList(INPUT_CAMEL_CASE.toLowerCase())).isInstanceOf(List.class);
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToLowerCase(uk.gov.gchq.koryphe.impl.function.ToLowerCase) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 5 with IsA

use of uk.gov.gchq.koryphe.impl.predicate.IsA in project gaffer-doc by gchq.

the class IsAExample method isAString.

public void isAString() {
    // ---------------------------------------------------------
    final IsA function = new IsA(String.class);
    // ---------------------------------------------------------
    runExample(function, null, 1, 2.5, "abc");
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA)

Aggregations

IsA (uk.gov.gchq.koryphe.impl.predicate.IsA)9 Test (org.junit.Test)5 If (uk.gov.gchq.gaffer.operation.impl.If)5 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)5 ToList (uk.gov.gchq.koryphe.impl.function.ToList)5 ToLowerCase (uk.gov.gchq.koryphe.impl.function.ToLowerCase)3 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)2 ToUpperCase (uk.gov.gchq.koryphe.impl.function.ToUpperCase)2 Test (org.junit.jupiter.api.Test)1 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 ExampleAggregateFunction (uk.gov.gchq.gaffer.function.ExampleAggregateFunction)1 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)1 Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)1 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)1 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)1 MapSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser)1 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)1 RawLongSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser)1 StringToStringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser)1