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 Type | Input | Result Type | Result |
---|---|---|---|
null | null | ||
java.lang.String | Convert me to upper case | java.lang.String | CONVERT ME TO UPPER CASE |
java.lang.String | Convert me to lower case | java.lang.String | convert me to lower case |
java.lang.String | java.lang.String |