If

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

Available since Koryphe version 1.5.0

Conditionally applies a function

Examples

Apply functions to input

This example tests first whether the input contains 'upper'. If so, then it is converted to upper case. Otherwise, it is converted to lower case

Java
JSON
Full JSON
Python
final If<String, String> predicate = new If<String, String>()
        .predicate(new StringContains("upper"))
        .then(new ToUpperCase())
        .otherwise(new ToLowerCase());
{
  "class" : "uk.gov.gchq.koryphe.impl.function.If",
  "predicate" : {
    "class" : "StringContains",
    "value" : "upper",
    "ignoreCase" : false
  },
  "then" : {
    "class" : "ToUpperCase"
  },
  "otherwise" : {
    "class" : "ToLowerCase"
  }
}
{
  "class" : "uk.gov.gchq.koryphe.impl.function.If",
  "predicate" : {
    "class" : "uk.gov.gchq.koryphe.impl.predicate.StringContains",
    "value" : "upper",
    "ignoreCase" : false
  },
  "then" : {
    "class" : "uk.gov.gchq.koryphe.impl.function.ToUpperCase"
  },
  "otherwise" : {
    "class" : "uk.gov.gchq.koryphe.impl.function.ToLowerCase"
  }
}
g.If( 
  predicate=g.StringContains( 
    value="upper", 
    ignore_case=False 
  ), 
  then=g.ToUpperCase(), 
  otherwise=g.ToLowerCase() 
)

Input type:

java.lang.Object

Example inputs:

Input TypeInputResult TypeResult
nullnull
java.lang.StringConvert me to upper casejava.lang.StringCONVERT ME TO UPPER CASE
java.lang.StringConvert me to lower casejava.lang.Stringconvert me to lower case
java.lang.Stringjava.lang.String

results matching ""

    No results matching ""