If

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

Available since Koryphe version 1.3.0

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( 
  otherwise=g.Not( 
    predicate=g.IsA( 
      type="java.lang.String" 
    ) 
  ), 
  then=g.IsMoreThan( 
    value=3, 
    or_equal_to=False 
  ), 
  predicate=g.IsA( 
    type="java.lang.Integer" 
  ) 
)

Input type:

java.lang.Object

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 ""