If

See javadoc - uk.gov.gchq.koryphe.impl.predicate.If

Available since Koryphe version 1.3.0

Conditionally applies a predicate

Examples

Apply predicates to input

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.

Java
JSON
Full JSON
Python
final If<Comparable> predicate = new If<>(new IsA(Integer.class), new IsMoreThan(3), new Not<>(new IsA(String.class)));
{
  "class" : "uk.gov.gchq.koryphe.impl.predicate.If",
  "predicate" : {
    "class" : "IsA",
    "type" : "java.lang.Integer"
  },
  "then" : {
    "class" : "IsMoreThan",
    "orEqualTo" : false,
    "value" : 3
  },
  "otherwise" : {
    "class" : "Not",
    "predicate" : {
      "class" : "IsA",
      "type" : "java.lang.String"
    }
  }
}
{
  "class" : "uk.gov.gchq.koryphe.impl.predicate.If",
  "predicate" : {
    "class" : "uk.gov.gchq.koryphe.impl.predicate.IsA",
    "type" : "java.lang.Integer"
  },
  "then" : {
    "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
    "orEqualTo" : false,
    "value" : 3
  },
  "otherwise" : {
    "class" : "uk.gov.gchq.koryphe.impl.predicate.Not",
    "predicate" : {
      "class" : "uk.gov.gchq.koryphe.impl.predicate.IsA",
      "type" : "java.lang.String"
    }
  }
}
g.If( 
  predicate=g.IsA( 
    type="java.lang.Integer" 
  ), 
  then=g.IsMoreThan( 
    value=3, 
    or_equal_to=False 
  ), 
  otherwise=g.Not( 
    predicate=g.IsA( 
      type="java.lang.String" 
    ) 
  ) 
)

Input type:

uk.gov.gchq.koryphe.signature.Signature$UnknownGenericType

Example inputs:

Input TypeInputResult
java.lang.Integer2false
java.lang.Integer3false
java.lang.Integer5true
java.lang.Stringtestfalse
java.util.HashMap{}true
java.util.ArrayList[]true

results matching ""

    No results matching ""