Skip to content

Koryphe Functions

Functions from the Koryphe library.

ApplyBiFunction

Applies the given BiFunction. Javadoc

Input type depends on the BiFunction given.

Example ApplyBiFunction using sum
final ApplyBiFunction<Number, Number, Number> function = new ApplyBiFunction<>(new Sum());
{
  "class" : "ApplyBiFunction",
  "function" : {
    "class" : "Sum"
  }
}
g.ApplyBiFunction( 
  function=g.Sum() 
)

Example inputs:

Input Type Input Result Type Result
[java.lang.Integer, java.lang.Integer] [1, 2] java.lang.Integer 3
[java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer] [1, 2, 3, 4] java.lang.Integer 3
[java.lang.Double, java.lang.Double] [1.1, 2.2] java.lang.Double 3.3000000000000003
Example ApplyBiFunction using max
final ApplyBiFunction<Comparable, Comparable, Comparable> function = new ApplyBiFunction<>(new Max());
{
  "class" : "ApplyBiFunction",
  "function" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
  }
}
g.ApplyBiFunction( 
  function=g.Max() 
)

Example inputs:

Input Type Input Result Type Result
[java.lang.Integer, java.lang.Integer] [1, 2] java.lang.Integer 2
[java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer] [1, 2, 3, 4] java.lang.Integer 2
[java.lang.Double, java.lang.Double] [1.1, 2.2] java.lang.Double 2.2
Example ApplyBiFunction using min
final ApplyBiFunction<Comparable, Comparable, Comparable> function = new ApplyBiFunction<>(new Min());
{
  "class" : "ApplyBiFunction",
  "function" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Min"
  }
}
g.ApplyBiFunction( 
  function=g.Min() 
)

Example inputs:

Input Type Input Result Type Result
[java.lang.Integer, java.lang.Integer] [1, 2] java.lang.Integer 1
[java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer] [1, 2, 3, 4] java.lang.Integer 1
[java.lang.Double, java.lang.Double] [1.1, 2.2] java.lang.Double 1.1

Base64Decode

Decodes a base64 encoded byte array. Javadoc

Input type: byte[]

Example Base64Decode
final Base64Decode function = new Base64Decode();
{
  "class" : "Base64Decode"
}
g.Base64Decode()

Example inputs:

Input Type Input Result Type Result
byte[] dGVzdCBzdHJpbmc= byte[] test string
null null

CallMethod

Allows you to call any public no-argument method on an object. Javadoc

Input type: java.lang.Object

Example CallMethod with toString
final CallMethod function = new CallMethod("toString");
{
  "class" : "CallMethod",
  "method" : "toString"
}
g.CallMethod( 
  method="toString" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String a string java.lang.String a string
java.lang.Integer 1 java.lang.String 1
java.util.HashSet [item2, item1] java.lang.String [item2, item1]
null null
Example CallMethod with toLowerCase
final CallMethod function = new CallMethod("toLowerCase");
{
  "class" : "CallMethod",
  "method" : "toLowerCase"
}
g.CallMethod( 
  method="toLowerCase" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String STRING1 java.lang.String string1
java.lang.String String2 java.lang.String string2
java.lang.Integer 10 RuntimeException: Unable to invoke toLowerCase on object class class java.lang.Integer
null null

Cast

Casts input to specified class. Javadoc

Input type: java.lang.Object

Example Cast
final Cast function = new Cast(String.class);
{
  "class" : "Cast",
  "outputClass" : "String"
}
g.Cast( 
  output_class="java.lang.String" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 5 ClassCastException: Cannot cast java.lang.Integer to java.lang.String
java.lang.String inputString java.lang.String inputString
null null

Concat

Objects are concatenated by concatenating the outputs from calling toString on each object. The default separator is a comma. Javadoc

Input type: java.lang.Object, java.lang.Object

Example Concat
final Concat function = new Concat(",");
{
  "class" : "Concat",
  "separator" : ","
}
g.Concat( 
  separator="," 
)

Example inputs:

Input Type Input Result Type Result
[java.lang.String, java.lang.String] [foo, bar] java.lang.String foo,bar
[java.lang.String, ] [foo, null] java.lang.String foo
[java.lang.String, java.lang.String] [foo, ] java.lang.String foo,
[java.lang.String, java.lang.Double] [foo, 1.2] java.lang.String foo,1.2
[ ,java.lang.String] [null, bar] java.lang.String bar
[java.lang.Integer, java.lang.Integer] [1, 2] java.lang.String 1,2

CreateObject

Creates a new object of a given type. Javadoc

Input type: java.lang.Object

Example CreateObject with String
final CreateObject createObject = new CreateObject(String.class);
{
  "class" : "CreateObject",
  "objectClass" : "String"
}
g.CreateObject( 
  object_class="java.lang.String" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String a normal string java.lang.String a normal string
byte[] some bytes java.lang.String some bytes
null java.lang.String
java.lang.Integer 123 RuntimeException: Unable to create a new instance of java.lang.String. No constructors were found that accept a java.lang.Integer
[C [C@246c4b32 java.lang.String a char array
Example CreateObject with List
final CreateObject createObject = new CreateObject(ArrayList.class);
{
  "class" : "CreateObject",
  "objectClass" : "ArrayList"
}
g.CreateObject( 
  object_class="java.util.ArrayList" 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [list, example] java.util.ArrayList [list, example]
java.util.HashSet [set, example] java.util.ArrayList [set, example]
java.util.HashMap {} RuntimeException: Unable to create a new instance of java.util.ArrayList. No constructors were found that accept a java.util.HashMap
null java.util.ArrayList []

CsvLinesToMaps

Parses CSV lines into Maps. Javadoc

Input type: java.lang.Iterable

Example CsvLinesToMaps with delimiter
final CsvLinesToMaps function = new CsvLinesToMaps()
        .header("header1", "header2", "header3")
        .firstRow(1)
        .delimiter('|');
{
  "class" : "CsvLinesToMaps",
  "header" : [ "header1", "header2", "header3" ],
  "firstRow" : 1,
  "delimiter" : "|"
}
g.CsvLinesToMaps( 
  delimiter="|", 
  header=[ 
    "header1", 
    "header2", 
    "header3" 
  ], 
  first_row=1 
)

Example inputs:

Input Type Input Result Type Result
java.util.Arrays$ArrayList [header1|header2|header3, value1|value2|value3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}]
java.util.Arrays$ArrayList [header1|header2|header3, value1||value3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=, header1=value1}]
java.util.Arrays$ArrayList [header1|header2|header3, value1|value2] IllegalArgumentException: CSV has 2 columns, but there are 3 provided column names
java.util.Arrays$ArrayList [header1||header3, value1|value2|value3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}]
java.util.Arrays$ArrayList [header1|header2, value1|value2|value3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}]
java.util.Arrays$ArrayList [header1|header2|header3, value1|value2|value3, value4|value5|value6] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}, {header3=value6, header2=value5, header1=value4}]
java.util.Arrays$ArrayList [header1|header2|header3, , value4|value5|value6] NoSuchElementException: No more CSV records available
java.util.Arrays$ArrayList [header1|header2|header3, null, value4|value5|value6] NullPointerException: null
java.util.Arrays$ArrayList [value1|value2|value3, value4|value5|value6] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}, {header3=value6, header2=value5, header1=value4}]
java.util.Arrays$ArrayList [null, value1|value2|value3, value4|value5|value6] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}, {header3=value6, header2=value5, header1=value4}]

CsvToMaps

Parses CSVs into Maps. Javadoc

Input type: java.lang.String

Example CsvToMaps
final CsvToMaps function = new CsvToMaps().header("header1", "header2", "header3").firstRow(1);
{
  "class" : "CsvToMaps",
  "header" : [ "header1", "header2", "header3" ],
  "firstRow" : 1
}
g.CsvToMaps( 
  header=[ 
    "header1", 
    "header2", 
    "header3" 
  ], 
  first_row=1 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String header1,header2,header3 \n value1,value2,value3 uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}]
java.lang.String header1,header2,header3 \n value1,value2,value3 \n value4,value5,value6 uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=value2, header1=value1}, {header3=value6", header2=value5, header1=value4}]
java.lang.String header1,header2,header3 \n ,,value3 \n value4,value5,value6 uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [{header3=value3, header2=, header1=}, {header3=value6", header2=value5, header1=value4}]
java.lang.String header1,header2,header3,header4 \n value1,value2,value3,value4 \n value5,value6,value7,value8 NoSuchElementException: null
null null
java.lang.String uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable []

CurrentDate

Returns the current date and time, input is ignored. Javadoc

Input type (ignored): java.lang.Object

Example getting CurrentDate
final CurrentDate currentDate = new CurrentDate();
{
  "class" : "CurrentDate"
}
g.CurrentDate()

Example inputs:

Input Type Input Result Type Result
null java.util.Date Mon Nov 07 11:00:17 GMT 2022

CurrentTime

Returns the current time in milliseconds, input is ignored. Javadoc

Input type (ignored): java.lang.Object

Example getting CurrentTime
final CurrentTime currentTime = new CurrentTime();
{
  "class" : "CurrentTime"
}
g.CurrentTime()

Example inputs:

Input Type Input Result Type Result
null java.lang.Long 1667818817897

DefaultIfEmpty

Provides a default value if the input is empty. Javadoc

Input type: java.lang.Object

Example DefaultIfEmpty
final DefaultIfEmpty function = new DefaultIfEmpty();
{
  "class" : "DefaultIfEmpty"
}
g.DefaultIfEmpty()

Example inputs:

Input Type Input Result Type Result
java.lang.String String input java.lang.String String input
java.lang.Long 5 IllegalArgumentException: Could not determine the size of the provided value
null null
java.lang.String null

DefaultIfNull

Provides a default value if the input is null. Javadoc

Input type: java.lang.Object

Example DefaultIfNull
final DefaultIfNull function = new DefaultIfNull("DEFAULT");
{
  "class" : "DefaultIfNull",
  "defaultValue" : "DEFAULT"
}
g.DefaultIfNull( 
  default_value="DEFAULT" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String String input java.lang.String String input
java.lang.Long 5 java.lang.Long 5
null java.lang.String DEFAULT
java.lang.String java.lang.String

DeserialiseJson

Parses a JSON string into Java objects. Javadoc

Input type: java.lang.String

Example DeserialiseJson
final DeserialiseJson function = new DeserialiseJson();
{
  "class" : "DeserialiseJson"
}
g.DeserialiseJson()

Example inputs:

Input Type Input Result Type Result
java.lang.String {"elements": [{"value": "value1"}, {"value": "value2"}]} java.util.LinkedHashMap {elements=[{value=value1}, {value=value2}]}
java.lang.String [ "ListValue1", "ListValue2", "ListValue3" ] java.util.ArrayList [ListValue1, ListValue2, ListValue3]
java.lang.String { "number":30 } java.util.LinkedHashMap {number=30}
java.lang.String { "false":true } java.util.LinkedHashMap {false=true}
java.lang.String {
"class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
"vertex" : 1
} java.util.LinkedHashMap {class=uk.gov.gchq.gaffer.operation.data.EntitySeed, vertex=1}
java.lang.String [ "listValue1", "listValue1", "listValue1" ] java.util.ArrayList [listValue1, listValue1, listValue1]
java.lang.String {
"key1" : 1.0,
"key2" : 2.2,
"key3" : 3.3
} java.util.LinkedHashMap {key1=1.0, key2=2.2, key3=3.3}

DeserialiseXml

Parses an XML document into multiple Maps. Javadoc

Input type: java.lang.String

Example DeserialiseXml
final DeserialiseXml function = new DeserialiseXml();
{
  "class" : "DeserialiseXml"
}
g.DeserialiseXml()

Example inputs:

Input Type Input Result Type Result
java.lang.String <element1>value</element1> java.util.HashMap {element1=value}
java.lang.String <root><element1>value1</element1><element2>value2</element2></root> java.util.HashMap {root={element1=value1, element2=value2}}
java.lang.String <root><element1><element2>value1</element2></element1><element1><element2>value2</element2></element1></root> java.util.HashMap {root={element1=[{element2=value1}, {element2=value2}]}}

DictionaryLookup

Looks up a value in a Map. Javadoc

Input type: java.lang.Object

Example DictionaryLookup
final DictionaryLookup<Integer, String> dictionaryLookup = new DictionaryLookup<>(map);
{
  "class" : "DictionaryLookup",
  "dictionary" : {
    "1" : "one",
    "2" : "two",
    "3" : "three"
  }
}
g.DictionaryLookup( 
  dictionary={'1': 'one', '2': 'two', '3': 'three'} 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 1 java.lang.String one
null null
java.lang.Integer 4 null
java.lang.Long 2 null

Divide

Divides the input integers, the resulting object is a Tuple2 containing the quotient and remainder. [x, y] -> [x/y, remainder]. Javadoc

Input type: java.lang.Integer, java.lang.Integer

Example Divide
final Divide function = new Divide();
{
  "class" : "Divide"
}
g.Divide()

Example inputs:

Input Type Input Result Type Result
[java.lang.Integer, java.lang.Integer] [6, 2] [java.lang.Integer, java.lang.Integer] [3, 0]
[java.lang.Integer, java.lang.Integer] [6, 4] [java.lang.Integer, java.lang.Integer] [1, 2]
[java.lang.Integer, java.lang.Integer] [6, 8] [java.lang.Integer, java.lang.Integer] [0, 6]
[ ,java.lang.Integer] [null, 2] null
[java.lang.Integer, ] [6, null] [java.lang.Integer, java.lang.Integer] [6, 0]
[java.lang.Double, java.lang.Double] [6.1, 2.1] IllegalArgumentException: Input tuple values do not match the required function input types

DivideBy

Divide the input integer by the provided integer, the resulting object is a Tuple2 containing the quotient and remainder. x -> [x/divideBy, remainder]. Javadoc

Input type: java.lang.Integer

Example DivideBy
final DivideBy function = new DivideBy(2);
{
  "class" : "DivideBy",
  "by" : 2
}
g.DivideBy( 
  by=2 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 6 [java.lang.Integer, java.lang.Integer] [3, 0]
java.lang.Integer 5 [java.lang.Integer, java.lang.Integer] [2, 1]
null null
java.lang.Double 6.1 ClassCastException: java.lang.Double cannot be cast to java.lang.Integer

ExtractKeys

An ExtractKeys will return the Set of keys from the provided Java Map. Javadoc

Input type: java.util.Map

Example ExtractKeys
final ExtractKeys<String, Integer> function = new ExtractKeys<>();
{
  "class" : "ExtractKeys"
}
g.ExtractKeys()

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {firstKey=2, thirdKey=9, secondKey=4} java.util.HashMap$KeySet [firstKey, thirdKey, secondKey]

ExtractValue

An ExtractValue will return the value associated with the pre-configured key, from a supplied Java Map. Javadoc

Input type: java.util.Map

Example ExtractValue
final ExtractValue<String, Integer> function = new ExtractValue<>("blueKey");
{
  "class" : "ExtractValue",
  "key" : "blueKey"
}
g.ExtractValue( 
  key="blueKey" 
)

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {yellowKey=4, greenKey=9, redKey=5, blueKey=25} java.lang.Integer 25

ExtractValues

An ExtractValues will return a Collection of the values from a provided Java Map. Javadoc

Input type: java.util.Map

Example ExtractValues
final ExtractValues<String, Integer> function = new ExtractValues<>();
{
  "class" : "ExtractValues"
}
g.ExtractValues()

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {theKey=1, theWholeKey=2, nothingButTheKey=3} java.util.HashMap$Values [1, 2, 3]

FirstItem

For a given Iterable, a FirstItem will extract the first item. Javadoc

Input type: java.lang.Iterable

Example FirstItem
final FirstItem<Integer> function = new FirstItem<>();
{
  "class" : "FirstItem"
}
g.FirstItem()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [2, 3, 5] java.lang.Integer 2
java.util.ArrayList [7, 11, 13] java.lang.Integer 7
java.util.ArrayList [17, 19, null] java.lang.Integer 17
java.util.ArrayList [null, 19, 27] null
null IllegalArgumentException: Input cannot be null

FirstValid

Provides the first valid item from an iterable based on a predicate. Javadoc

Input type: java.lang.Iterable

Example FirstValid with a predicate
final FirstValid function = new FirstValid(new StringContains("my"));
{
  "class" : "FirstValid",
  "predicate" : {
    "class" : "StringContains",
    "value" : "my",
    "ignoreCase" : false
  }
}
g.FirstValid( 
  predicate=g.StringContains( 
    value="my", 
    ignore_case=False 
  ) 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [1, 2, 3] ClassCastException: java.lang.Integer cannot be cast to java.lang.String
java.util.ArrayList [Hello, my, value] java.lang.String my
java.util.ArrayList [MY, tummy, my, My] java.lang.String tummy
null null
Example FirstValid without a predicate

FirstValid always returns null if no predicate is specified

final FirstValid function = new FirstValid(null);
{
  "class" : "FirstValid"
}
g.FirstValid()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [a, b, c] null
java.util.ArrayList [1, 2, 3] null
java.util.ArrayList [] null

FunctionChain

Applies the given functions consecutively. Javadoc

Input type: java.lang.Object

Example FunctionChain using tuple adapted functions
final FunctionChain function = new FunctionChain.Builder<>()
        .execute(new Integer[]{0}, new ToUpperCase(), new Integer[]{1})
        .execute(new Integer[]{1}, new ToSet(), new Integer[]{2})
        .build();
{
  "class" : "FunctionChain",
  "functions" : [ {
    "class" : "TupleAdaptedFunction",
    "selection" : [ 0 ],
    "function" : {
      "class" : "ToUpperCase"
    },
    "projection" : [ 1 ]
  }, {
    "class" : "TupleAdaptedFunction",
    "selection" : [ 1 ],
    "function" : {
      "class" : "uk.gov.gchq.koryphe.impl.function.ToSet"
    },
    "projection" : [ 2 ]
  } ]
}
g.FunctionChain( 
  functions=[ 
    g.TupleAdaptedFunction( 
      selection=[ 
        0 
      ], 
      function=g.ToUpperCase(), 
      projection=[ 
        1 
      ] 
    ), 
    g.TupleAdaptedFunction( 
      selection=[ 
        1 
      ], 
      function=g.ToSet(), 
      projection=[ 
        2 
      ] 
    ) 
  ] 
)

Example inputs:

Input Type Input Result Type Result
[java.lang.String, ,] [someString, null, null] [java.lang.String, java.lang.String, java.util.HashSet] [someString, SOMESTRING, [SOMESTRING]]
[java.lang.String, ,] [SOMESTRING, null, null] [java.lang.String, java.lang.String, java.util.HashSet] [SOMESTRING, SOMESTRING, [SOMESTRING]]
[java.lang.String, ,] [somestring, null, null] [java.lang.String, java.lang.String, java.util.HashSet] [somestring, SOMESTRING, [SOMESTRING]]
[java.lang.String, ,] [@£$%, null, null] [java.lang.String, java.lang.String, java.util.HashSet] [@£$%, @£$%, [@£$%]]
[java.lang.String, ,] [1234, null, null] [java.lang.String, java.lang.String, java.util.HashSet] [1234, 1234, [1234]]
[java.lang.String, ,] [, null, null] [java.lang.String, java.lang.String, java.util.HashSet] [, , []]
[ , ,] [null, null, null] [ , ,java.util.HashSet] [null, null, [null]]
[java.lang.Integer, ,] [1234, null, null] [java.lang.Integer, java.lang.String, java.util.HashSet] [1234, 1234, [1234]]
Example FunctionChain using standard functions
final FunctionChain function = new FunctionChain.Builder<>()
        .execute(new ToLowerCase())
        .execute(new ToTypeSubTypeValue())
        .execute(new ToEntityId())
        .build();
{
  "class" : "FunctionChain",
  "functions" : [ {
    "class" : "ToLowerCase"
  }, {
    "class" : "ToTypeSubTypeValue"
  }, {
    "class" : "ToEntityId"
  } ]
}
g.FunctionChain( 
  functions=[ 
    g.ToLowerCase(), 
    g.ToTypeSubTypeValue(), 
    g.ToEntityId() 
  ] 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String a string uk.gov.gchq.gaffer.operation.data.EntitySeed EntitySeed[vertex=TypeSubTypeValue[value=a string]]
java.lang.String UPPER uk.gov.gchq.gaffer.operation.data.EntitySeed EntitySeed[vertex=TypeSubTypeValue[value=upper]]
null uk.gov.gchq.gaffer.operation.data.EntitySeed EntitySeed[vertex=TypeSubTypeValue[]]
java.lang.Integer 12 uk.gov.gchq.gaffer.operation.data.EntitySeed EntitySeed[vertex=TypeSubTypeValue[value=12]]

FunctionMap

Applies a function to all values in a map. Javadoc

Input type: java.util.Map

Example using FunctionMap to multiply all map values by 10
final FunctionMap<String, Integer, Integer> function = new FunctionMap<>(new MultiplyBy(10));
{
  "class" : "FunctionMap",
  "function" : {
    "class" : "MultiplyBy",
    "by" : 10
  }
}
g.FunctionMap( 
  function=g.MultiplyBy( 
    by=10 
  ) 
)

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {key1=1, key2=2, key3=3} java.util.HashMap {key1=10, key2=20, key3=30}
java.util.HashMap {key1=null, key2=2, key3=3} java.util.HashMap {key1=null, key2=20, key3=30}
null null

Gunzip

Decompresses gzipped data. Javadoc

Input type: byte[]

Example Gunzip
final Gunzip gunzip = new Gunzip();
{
  "class" : "Gunzip"
}
g.Gunzip()

Example inputs:

Input Type Input Result Type Result
byte[] �+I-.Q(.)��KEG byte[] test string

Identity

Just returns the input. Javadoc

Input type: java.lang.Object

Example Identity
final Identity function = new Identity();
{
  "class" : "Identity"
}
g.Identity()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 6 java.lang.Integer 6
java.lang.Double 6.1 java.lang.Double 6.1
java.lang.String input1 java.lang.String input1
java.util.ArrayList [1, 2, 3] java.util.ArrayList [1, 2, 3]
null null

If

Conditionally applies a function. Javadoc

Input type: java.lang.Object

Example If

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.

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"
  }
}
g.If( 
  predicate=g.StringContains( 
    value="upper", 
    ignore_case=False 
  ), 
  then=g.ToUpperCase(), 
  otherwise=g.ToLowerCase() 
)

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

Increment

Adds a given number to the input, returned value type will match the input type. Javadoc

Input type: java.lang.Number

Example Increment with Int
final Increment increment = new Increment(3);
{
  "class" : "Increment",
  "increment" : 3
}
g.Increment( 
  increment=3 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 2 java.lang.Integer 5
java.lang.Double 2.0 java.lang.Integer 5
java.lang.Float 2.0 java.lang.Integer 5
java.lang.Long 2 java.lang.Integer 5
Example Increment with Double
final Increment increment = new Increment(3.0);
{
  "class" : "Increment",
  "increment" : 3.0
}
g.Increment( 
  increment=3.0 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 2 java.lang.Double 5.0
java.lang.Double 2.0 java.lang.Double 5.0
java.lang.Float 2.0 java.lang.Double 5.0
java.lang.Long 2 java.lang.Double 5.0
java.lang.String 33 ClassCastException: java.lang.String cannot be cast to java.lang.Number
java.lang.String three ClassCastException: java.lang.String cannot be cast to java.lang.Number
null java.lang.Double 3.0
Example Increment with Float
final Increment increment = new Increment(3.0f);
{
  "class" : "Increment",
  "increment" : {
    "Float" : 3.0
  }
}
g.Increment( 
  increment={'java.lang.Float': 3.0} 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 2 java.lang.Float 5.0
java.lang.Double 2.0 java.lang.Float 5.0
java.lang.Float 2.0 java.lang.Float 5.0
java.lang.Long 2 java.lang.Float 5.0
java.lang.String 33 ClassCastException: java.lang.String cannot be cast to java.lang.Number
java.lang.String three ClassCastException: java.lang.String cannot be cast to java.lang.Number
null java.lang.Float 3.0

IterableConcat

For a given Iterable of Iterables, an IterableConcat will essentially perform a FlatMap on the input, by concatenating each of the nested iterables into a single flattened iterable. Javadoc

Input type: java.lang.Iterable

Example IterableConcat
final IterableConcat<Integer> function = new IterableConcat<>();
{
  "class" : "IterableConcat"
}
g.IterableConcat()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [[2, 3, 5], [7, 11, 13], [17, 19, 23]] uk.gov.gchq.koryphe.util.IterableUtil$ChainedIterable [2, 3, 5, 7, 11, 13, 17, 19, 23]
java.util.ArrayList [[29, 31, 37]] uk.gov.gchq.koryphe.util.IterableUtil$ChainedIterable [29, 31, 37]
java.util.ArrayList [[2, 3, 5], [7, 11, 13], null] NullPointerException: null
null IllegalArgumentException: iterables are required

IterableFilter

An IterableFilter applies a given predicate to each element in an Iterable and returns the filtered iterable. Javadoc

Input type: java.lang.Iterable

Example IterableFilter with IsMoreThan
final IterableFilter<Integer> function = new IterableFilter<>(new IsMoreThan(5));
{
  "class" : "IterableFilter",
  "predicate" : {
    "class" : "IsMoreThan",
    "orEqualTo" : false,
    "value" : 5
  }
}
g.IterableFilter( 
  predicate=g.IsMoreThan( 
    value=5, 
    or_equal_to=False 
  ) 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [1, 2, 3] uk.gov.gchq.koryphe.util.IterableUtil$FilteredIterable []
java.util.ArrayList [5, 10, 15] uk.gov.gchq.koryphe.util.IterableUtil$FilteredIterable [10, 15]
java.util.ArrayList [7, 9, 11] uk.gov.gchq.koryphe.util.IterableUtil$FilteredIterable [7, 9, 11]
java.util.ArrayList [1, null, 3] uk.gov.gchq.koryphe.util.IterableUtil$FilteredIterable []
null null

IterableFlatten

Combines the items in an iterable into a single item based on the supplied operator. Javadoc

Input type: java.lang.Iterable

Example IterableFlatten without Binary Operator
final IterableFlatten function = new IterableFlatten(null);
{
  "class" : "IterableFlatten"
}
g.IterableFlatten()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [a, b, c] null
Example IterableFlatten with Binary Operator
final IterableFlatten function = new IterableFlatten<>(new Max());
{
  "class" : "IterableFlatten",
  "operator" : {
    "class" : "uk.gov.gchq.koryphe.impl.binaryoperator.Max"
  }
}
g.IterableFlatten( 
  operator=g.Max() 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [1, 2, 3, 1] java.lang.Integer 3
java.util.ArrayList [1, null, 6] java.lang.Integer 6
java.util.ArrayList [] null
null null

IterableFunction

An IterableFunction is useful for applying a provided function, or functions, to each entry of a supplied Iterable. Javadoc

Input type: java.lang.Iterable

Example IterableFunction with a single function
final IterableFunction<Integer, Integer> function = new IterableFunction<>(new MultiplyBy(2));
{
  "class" : "IterableFunction",
  "functions" : [ {
    "class" : "MultiplyBy",
    "by" : 2
  } ]
}
g.IterableFunction( 
  functions=[ 
    g.MultiplyBy( 
      by=2 
    ) 
  ] 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [1, 2, 3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [2, 4, 6]
java.util.ArrayList [5, 10, 15] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [10, 20, 30]
java.util.ArrayList [7, 9, 11] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [14, 18, 22]
java.util.ArrayList [1, null, 3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [2, null, 6]
null null
Example IterableFunction with multiple functions

Here we build a chain of functions using the IterableFunction's Builder, whereby the output of one function is the input to the next.

final IterableFunction<Integer, Integer> function = new IterableFunction.Builder<Integer>()
        .first(new MultiplyBy(2))
        .then(new MultiplyBy(4))
        .build();
{
  "class" : "IterableFunction",
  "functions" : [ {
    "class" : "MultiplyBy",
    "by" : 2
  }, {
    "class" : "MultiplyBy",
    "by" : 4
  } ]
}
g.IterableFunction( 
  functions=[ 
    g.MultiplyBy( 
      by=2 
    ), 
    g.MultiplyBy( 
      by=4 
    ) 
  ] 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [2, 4, 10] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [16, 32, 80]
java.util.ArrayList [3, 9, 11] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [24, 72, 88]
java.util.ArrayList [1, null, 3] uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable [8, null, 24]
null null

IterableLongest

Returns the longest item in the provided iterable. Javadoc

Input type: java.lang.Iterable

Example IterableLongest
final IterableLongest function = new IterableLongest();
{
  "class" : "IterableLongest"
}
g.IterableLongest()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [[1, 2], [1.5]] java.util.ArrayList [1, 2]
java.util.ArrayList [which, is, the, longest, word] java.lang.String longest
java.util.ArrayList [] null
null null

LastItem

For a given Iterable, a LastItem will extract the last item. Javadoc

Input type: java.lang.Iterable

Example LastItem
final LastItem<Integer> function = new LastItem<>();
{
  "class" : "LastItem"
}
g.LastItem()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [1, 2, 3] java.lang.Integer 3
java.util.ArrayList [5, 8, 13] java.lang.Integer 13
java.util.ArrayList [21, 34, 55] java.lang.Integer 55
java.util.ArrayList [1, null, 3] java.lang.Integer 3
java.util.ArrayList [1, 2, null] null
null IllegalArgumentException: Input cannot be null

Length

Attempts to return the length of an object. Javadoc

Input type: java.lang.Object

Example Length
final Length function = new Length();
{
  "class" : "Length"
}
g.Length()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [Entity[vertex=1,group=entity,properties=Properties[]], Entity[vertex=2,group=entity,properties=Properties[]], Entity[vertex=3,group=entity,properties=Properties[]], Entity[vertex=4,group=entity,properties=Properties[]], Entity[vertex=5,group=entity,properties=Properties[]]] java.lang.Integer 5
java.util.HashMap {option3=value3, option1=value1, option2=value2} java.lang.Integer 3
uk.gov.gchq.gaffer.data.graph.Walk [[Edge[source=A,destination=B,directed=true,group=BasicEdge,properties=Properties[]]], [Edge[source=B,destination=C,directed=true,group=EnhancedEdge,properties=Properties[]], Edge[source=B,destination=C,directed=true,group=BasicEdge,properties=Properties[]]], [Edge[source=C,destination=A,directed=true,group=BasicEdge,properties=Properties[]]], [Edge[source=A,destination=E,directed=true,group=BasicEdge,properties=Properties[]]]] java.lang.Integer 4
java.lang.Integer 5 IllegalArgumentException: Could not determine the size of the provided value
java.lang.String some string java.lang.Integer 11
java.lang.String[] [1, 2] java.lang.Integer 2
null java.lang.Integer 0

Longest

Determines which of two input objects is the longest. Javadoc

Input type: java.lang.Object, java.lang.Object

Example Longest
final Longest function = new Longest();
{
  "class" : "Longest"
}
g.Longest()

Example inputs:

Input Type Input Result Type Result
[java.lang.String, java.lang.String] [smaller, long string] java.lang.String long string
[java.util.ArrayList, java.util.HashSet] [[1, 2], [1.5]] java.util.ArrayList [1, 2]
[ ,java.lang.String] [null, value] java.lang.String value
null IllegalArgumentException: Input tuple is required

MapFilter

A Function which applies the given predicates to the keys and/or values. Javadoc

Input type: java.util.Map

Example MapFilter on keys

MapFilter with key predicate.

final MapFilter keyFilter = new MapFilter().keyPredicate(
        new StringContains("a")
);
{
  "class" : "MapFilter",
  "keyPredicate" : {
    "class" : "StringContains",
    "value" : "a",
    "ignoreCase" : false
  }
}
g.MapFilter(
  key_predicate=g.StringContains( 
    value="a", 
    ignore_case=False 
  ) 
)

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {giraffe=0, cat=3, dog=2} java.util.HashMap {giraffe=0, cat=3}
Example MapFilter on values

MapFilter with value predicate.

final MapFilter valueFilter = new MapFilter().valuePredicate(
        new IsMoreThan(10)
);
{
  "class" : "MapFilter",
  "valuePredicate" : {
    "class" : "IsMoreThan",
    "orEqualTo" : false,
    "value" : 10
  }
}
g.MapFilter( 
  value_predicate=g.IsMoreThan( 
    value=10, 
    or_equal_to=False 
  ) 
)

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {Pizza=30, Casserole=4, Steak=12} java.util.HashMap {Pizza=30, Steak=12}
Example MapFilter on keys and values

MapFilter with key-value Predicate.

final MapFilter keyValueFilter = new MapFilter()
        .keyValuePredicate(new AreEqual());
{
  "class" : "MapFilter",
  "keyValuePredicate" : {
    "class" : "AreEqual"
  }
}
g.MapFilter( 
  key_value_predicate=g.AreEqual() 
)

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {1=2, 3=3, 6=4} java.util.HashMap {3=3}

MapToTuple

Converts a Map to a Tuple. Javadoc

Input type: java.util.Map

Example MapToTuple
final MapToTuple<String> function = new MapToTuple<>();
{
  "class" : "MapToTuple"
}
g.MapToTuple()

Example inputs:

Input Type Input Result Type Result
java.util.HashMap {A=1, B=2, C=3} uk.gov.gchq.koryphe.tuple.MapTuple [1, 2, 3]
uk.gov.gchq.gaffer.types.FreqMap {value2=1, value1=2} uk.gov.gchq.koryphe.tuple.MapTuple [1, 2]

Multiply

The input integers are multiplied together. Javadoc

Input type: java.lang.Integer, java.lang.Integer

Example Multiply
final Multiply function = new Multiply();
{
  "class" : "Multiply"
}
g.Multiply()

Example inputs:

Input Type Input Result Type Result
[java.lang.Integer, java.lang.Integer] [2, 3] java.lang.Integer 6
[ ,java.lang.Integer] [null, 3] null
[java.lang.Integer, ] [2, null] java.lang.Integer 2
[java.lang.Double, java.lang.Double] [2.1, 3.1] IllegalArgumentException: Input tuple values do not match the required function input types

MultiplyBy

Multiply the input integer by the provided number. Javadoc

Input type: java.lang.Integer

Example MultiplyBy
final MultiplyBy function = new MultiplyBy(2);
{
  "class" : "MultiplyBy",
  "by" : 2
}
g.MultiplyBy( 
  by=2 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 6 java.lang.Integer 12
java.lang.Integer 5 java.lang.Integer 10
null null
java.lang.Double 6.1 ClassCastException: java.lang.Double cannot be cast to java.lang.Integer

MultiplyLongBy

Multiply the input Long by the provided number. Javadoc

Input type: java.lang.Long

Example MultiplyLongBy
final MultiplyLongBy function = new MultiplyLongBy(2L);
{
  "class" : "MultiplyLongBy",
  "by" : 2
}
g.MultiplyLongBy( 
  by=2 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Long 6 java.lang.Long 12
java.lang.Long 5 java.lang.Long 10
null null
java.lang.Double 6.1 ClassCastException: java.lang.Double cannot be cast to java.lang.Long

NthItem

For a given Iterable, an NthItem will extract the item at the Nth index, where n is a user-provided selection. (Consider that this is array-backed, so a selection of "1" will extract the item at index 1, ie the 2nd item). Javadoc

Input type: java.lang.Iterable

Example NthItem
final NthItem<Integer> function = new NthItem<>(2);
{
  "class" : "NthItem",
  "selection" : 2
}
g.NthItem( 
  selection=2 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [3, 1, 4] java.lang.Integer 4
java.util.ArrayList [1, 5, 9] java.lang.Integer 9
java.util.ArrayList [2, 6, 5] java.lang.Integer 5
java.util.ArrayList [2, null, 5] java.lang.Integer 5
java.util.ArrayList [2, 6, null] null
null IllegalArgumentException: Input cannot be null

ParseDate

Parses a date string. Javadoc

Input type: java.lang.String

Example ParseDate with GMT+4
final ParseDate parseDate = new ParseDate();
parseDate.setFormat("yyyy-MM-dd HH:mm:ss.SSS");
parseDate.setTimeZone("Etc/GMT+4");
{
  "class" : "ParseDate",
  "format" : "yyyy-MM-dd HH:mm:ss.SSS",
  "timeZone" : "Etc/GMT+4",
  "microseconds" : false
}
g.ParseDate( 
  time_zone="Etc/GMT+4", 
  format="yyyy-MM-dd HH:mm:ss.SSS", 
  microseconds=False 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String 2015-10-21 16:29:00.000 java.util.Date Wed Oct 21 21:29:00 BST 2015
java.lang.String 1985-10-26 09:00:00.000 java.util.Date Sat Oct 26 14:00:00 BST 1985
java.lang.String 1885-01-01 12:00:00.000 java.util.Date Thu Jan 01 16:00:00 GMT 1885
Example ParseDate with GMT+0
final ParseDate parseDate = new ParseDate();
parseDate.setFormat("yyyy-MM-dd HH:mm");
parseDate.setTimeZone("Etc/GMT+0");
{
  "class" : "ParseDate",
  "format" : "yyyy-MM-dd HH:mm",
  "timeZone" : "Etc/GMT+0",
  "microseconds" : false
}
g.ParseDate( 
  time_zone="Etc/GMT+0", 
  format="yyyy-MM-dd HH:mm", 
  microseconds=False 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String 2015-10-21 16:29 java.util.Date Wed Oct 21 17:29:00 BST 2015
java.lang.String 1985-10-26 09:00 java.util.Date Sat Oct 26 10:00:00 BST 1985
java.lang.String 1885-01-01 12:00 java.util.Date Thu Jan 01 12:00:00 GMT 1885

ParseTime

Parses a date string into a timestamp. Javadoc

Input type: java.lang.String

Example ParseTime
final ParseTime parseTime = new ParseTime();
{
  "class" : "ParseTime",
  "timeUnit" : "MILLISECOND"
}
g.ParseTime( 
  time_unit="MILLISECOND" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String 2015-10-21 16:29:00.000 java.lang.Long 1445441340000
java.lang.String 1985-10-26 09:00:00.000 java.lang.Long 499161600000
java.lang.String 1885-01-01 12:00:00.000 java.lang.Long -2682244800000
Example ParseTime with format
final ParseTime parseTime = new ParseTime().format("yyyy-MM hh:mm");
{
  "class" : "ParseTime",
  "format" : "yyyy-MM hh:mm",
  "timeUnit" : "MILLISECOND"
}
g.ParseTime( 
  format="yyyy-MM hh:mm", 
  time_unit="MILLISECOND" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String 2015-10 16:29 java.lang.Long 1443713340000
java.lang.String 1985-10 09:00 java.lang.Long 497001600000
java.lang.String 1885-01 12:00 java.lang.Long -2682288000000
java.lang.String 2015-10-21 16:29 IllegalArgumentException: Date string could not be parsed: 2015-10-21 16:29
Example ParseTime with format and GMT
final ParseTime parseTime = new ParseTime()
        .format("yyyy-MM-dd")
        .timeUnit("SECOND")
        .timeZone("GMT");
{
  "class" : "ParseTime",
  "format" : "yyyy-MM-dd",
  "timeZone" : "GMT",
  "timeUnit" : "SECOND"
}
g.ParseTime( 
  time_zone="GMT", 
  format="yyyy-MM-dd", 
  time_unit="SECOND" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String 2015-10-21 16:29:00.000 java.lang.Long 1445385600
java.lang.String 1985-10-26 09:00:00.000 java.lang.Long 499132800
java.lang.String 1885-01-01 12:00:00.000 java.lang.Long -2682288000

ReverseString

Reverse characters in string. Javadoc

Input type: java.lang.String

Example ReverseString
final ReverseString function = new ReverseString();
{
  "class" : "ReverseString"
}
g.ReverseString()

Example inputs:

Input Type Input Result Type Result
java.lang.String reverse java.lang.String esrever
java.lang.String esrever java.lang.String reverse
null null
java.lang.Long 54 ClassCastException: java.lang.Long cannot be cast to java.lang.String

SetValue

Returns a set value from any input. Javadoc

Input type: java.lang.Object

Example SetValue
final SetValue function = new SetValue(5);
{
  "class" : "SetValue",
  "value" : 5
}
g.SetValue(
  value=5 
)

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 4 java.lang.Integer 5
java.lang.Integer 5 java.lang.Integer 5
java.lang.String aString java.lang.Integer 5
java.util.Arrays$ArrayList [4, 5] java.lang.Integer 5
null java.lang.Integer 5

StringAppend

Appends a provided suffix to a string. Javadoc

Input type: java.lang.String

Example StringAppend
final StringAppend function = new StringAppend("mySuffix");
{
  "class" : "StringAppend",
  "suffix" : "mySuffix"
}
g.StringAppend( 
  suffix="mySuffix" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String a string of some kind java.lang.String a string of some kindmySuffix
java.lang.String java.lang.String mySuffix
null null
java.lang.Long 54 ClassCastException: java.lang.Long cannot be cast to java.lang.String

StringJoin

Joins together all strings in an iterable using the supplied delimiter. Javadoc

Input type: java.lang.Iterable

Example StringJoin without a delimiter
final StringJoin function = new StringJoin();
{
  "class" : "StringJoin"
}
g.StringJoin()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [here, are, my, strings] java.lang.String herearemystrings
java.util.ArrayList [single] java.lang.String single
java.util.ArrayList [] java.lang.String
null null
Example StringJoin with a delimiter
final StringJoin function = new StringJoin("-");
{
  "class" : "StringJoin",
  "delimiter" : "-"
}
g.StringJoin( 
  delimiter="-" 
)

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [here, are, my, strings] java.lang.String here-are-my-strings
java.util.ArrayList [single] java.lang.String single
java.util.ArrayList [] java.lang.String
null null

StringPrepend

Prepends a string with the provided prefix. Javadoc

Input type: java.lang.String

Example StringPrepend
final StringPrepend function = new StringPrepend("myPrefix");
{
  "class" : "StringPrepend",
  "prefix" : "myPrefix"
}
g.StringPrepend( 
  prefix="myPrefix" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String a string of some kind java.lang.String myPrefixa string of some kind
java.lang.String java.lang.String myPrefix
null null
java.lang.Long 54 ClassCastException: java.lang.Long cannot be cast to java.lang.String

StringRegexReplace

Replace all portions of a string which match a regular expression. Javadoc

Input type: java.lang.String

Example StringRegexReplace
final StringRegexReplace function = new StringRegexReplace("[tT]ea", "cake");
{
  "class" : "StringRegexReplace",
  "regex" : "[tT]ea",
  "replacement" : "cake"
}
g.StringRegexReplace( 
  regex="[tT]ea", 
  replacement="cake" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String tea java.lang.String cake
java.lang.String Tea java.lang.String cake
java.lang.String TEA java.lang.String TEA
java.lang.String brainteaser java.lang.String braincakeser
null null
java.lang.String coffee java.lang.String coffee
java.lang.Long 5 ClassCastException: java.lang.Long cannot be cast to java.lang.String

StringRegexSplit

Split a string using the provided regular expression. Javadoc

Input type: java.lang.String

Example StringRegexSplit
final StringRegexSplit function = new StringRegexSplit("[ \\t]+");
{
  "class" : "StringRegexSplit",
  "regex" : "[ \\t]+"
}
g.StringRegexSplit( 
  regex="[ \t]+" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String no-delimiters-in-this-string java.util.Arrays$ArrayList [no-delimiters-in-this-string]
java.lang.String string with two spaces java.util.Arrays$ArrayList [string, with, two, spaces]
java.lang.String string with one space java.util.Arrays$ArrayList [string, with, one, space]
java.lang.String tab delimited string java.util.Arrays$ArrayList [tab, delimited, string]
java.lang.String java.util.Arrays$ArrayList []
null null

StringReplace

Replace all portions of a string which match a regular expression. Javadoc

Input type: java.lang.String

Example StringReplace
final StringReplace function = new StringReplace("[tea", "cake");
{
  "class" : "StringReplace",
  "replacement" : "cake",
  "searchString" : "[tea"
}
g.StringReplace( 
  search_string="[tea", 
  replacement="cake" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String tea java.lang.String tea
java.lang.String Tea java.lang.String Tea
java.lang.String TEA java.lang.String TEA
java.lang.String brainteaser java.lang.String brainteaser
null null
java.lang.String coffee java.lang.String coffee
java.lang.Long 5 ClassCastException: java.lang.Long cannot be cast to java.lang.String

StringSplit

Split a string using the provided regular expression. Javadoc

Input type: java.lang.String

Example StringSplit
final StringSplit function = new StringSplit(" ");
{
  "class" : "StringSplit",
  "delimiter" : " "
}
g.StringSplit( 
  delimiter=" " 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String no-delimiters-in-this-string java.util.Arrays$ArrayList [no-delimiters-in-this-string]
java.lang.String string with two spaces java.util.Arrays$ArrayList [string, with, two, spaces]
java.lang.String string with one space java.util.Arrays$ArrayList [string, with, one, space]
java.lang.String tab delimited string java.util.Arrays$ArrayList [tab delimited string]
java.lang.String java.util.Arrays$ArrayList []
null null

StringTrim

Trims all whitespace around a string. Javadoc

Input type: java.lang.String

Example StringTrim
final StringTrim function = new StringTrim();
{
  "class" : "StringTrim"
}
g.StringTrim()

Example inputs:

Input Type Input Result Type Result
java.lang.String trailing spaces java.lang.String trailing spaces
java.lang.String leading spaces java.lang.String leading spaces
java.lang.String noSpaces java.lang.String noSpaces
null null
java.lang.Long 54 ClassCastException: java.lang.Long cannot be cast to java.lang.String

StringTruncate

Truncates a string, with optional ellipses. Javadoc

Input type: java.lang.String

Example StringTruncate without ellipses
final StringTruncate function = new StringTruncate(5, false);
{
  "class" : "StringTruncate",
  "length" : 5,
  "ellipses" : false
}
g.StringTruncate(
  length=5, 
  ellipses=False 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String no more than five java.lang.String no mo
java.lang.String four java.lang.String four
java.lang.String java.lang.String
null null
java.lang.Long 54 ClassCastException: java.lang.Long cannot be cast to java.lang.String
Example StringTruncate with ellipses
final StringTruncate function = new StringTruncate(5, true);
{
  "class" : "StringTruncate",
  "length" : 5,
  "ellipses" : true
}
g.StringTruncate(
  length=5, 
  ellipses=True 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String no more than five java.lang.String no mo...
java.lang.String four java.lang.String four
java.lang.String java.lang.String
null null
java.lang.Long 54 ClassCastException: java.lang.Long cannot be cast to java.lang.String

ToArray

Converts an Object to an Array. Javadoc

Input type: java.lang.Object

Example ToArray
final ToArray function = new ToArray();
{
  "class" : "uk.gov.gchq.koryphe.impl.function.ToArray"
}
g.ToArray()

Example inputs:

Input Type Input Result Type Result
java.lang.String test java.lang.Object[] [test]
null java.lang.Object[] [null]
java.lang.Long 30 java.lang.Object[] [30]
uk.gov.gchq.gaffer.types.TypeSubTypeValue TypeSubTypeValue[type=t,subType=st,value=v] java.lang.Object[] [TypeSubTypeValue[type=t,subType=st,value=v]]
java.util.Arrays$ArrayList [a, b, c] java.lang.Object[] [a, b, c]
java.util.HashSet [1, 2] java.lang.Object[] [1, 2]

ToBytes

Extracts the bytes from a string. Javadoc

Input type: java.lang.String

Example ToBytes
final ToBytes toBytes = new ToBytes(StandardCharsets.UTF_16);
{
  "class" : "ToBytes",
  "charset" : "UTF-16"
}
g.ToBytes( 
  charset="UTF-16" 
)

Example inputs:

Input Type Input Result Type Result
java.lang.String example String byte[] ��example String
java.lang.String byte[]
null null
java.lang.Integer 1 ClassCastException: java.lang.Integer cannot be cast to java.lang.String

ToDateString

Converts a date to a String. Javadoc

Input type: java.util.Date

Example ToDateString with microsecond
final ToDateString function = new ToDateString("yyyy-MM-dd HH:mm:ss.SSS");
{
  "class" : "ToDateString",
  "format" : "yyyy-MM-dd HH:mm:ss.SSS"
}
g.ToDateString( 
  format="yyyy-MM-dd HH:mm:ss.SSS" 
)

Example inputs:

Input Type Input Result Type Result
java.util.Date Tue Jan 06 19:39:25 GMT 1970 java.lang.String 1970-01-06 19:39:25.200
java.util.Date Thu Jan 01 01:00:00 GMT 1970 java.lang.String 1970-01-01 01:00:00.000
java.lang.Long 1667818823612 ClassCastException: java.lang.Long cannot be cast to java.util.Date
java.util.Date Fri Dec 26 06:20:34 GMT 1969 java.lang.String 1969-12-26 06:20:34.800
Example ToDateString with minute
final ToDateString function = new ToDateString("yy-MM-dd HH:mm");
{
  "class" : "ToDateString",
  "format" : "yy-MM-dd HH:mm"
}
g.ToDateString( 
  format="yy-MM-dd HH:mm" 
)

Example inputs:

Input Type Input Result Type Result
java.util.Date Tue Jan 06 19:39:25 GMT 1970 java.lang.String 70-01-06 19:39
java.util.Date Thu Jan 01 01:00:00 GMT 1970 java.lang.String 70-01-01 01:00
java.lang.Long 1667818823683 ClassCastException: java.lang.Long cannot be cast to java.util.Date
java.util.Date Fri Dec 26 06:20:34 GMT 1969 java.lang.String 69-12-26 06:20
null null
Example ToDateString with date only
final ToDateString function = new ToDateString("yy-MM-dd");
{
  "class" : "ToDateString",
  "format" : "yy-MM-dd"
}
g.ToDateString( 
  format="yy-MM-dd" 
)

Example inputs:

Input Type Input Result Type Result
java.util.Date Tue Jan 06 19:39:25 GMT 1970 java.lang.String 70-01-06
java.util.Date Thu Jan 01 01:00:00 GMT 1970 java.lang.String 70-01-01
java.lang.Long 1667818823752 ClassCastException: java.lang.Long cannot be cast to java.util.Date
java.util.Date Fri Dec 26 06:20:34 GMT 1969 java.lang.String 69-12-26
null null

ToInteger

Returns any input as Integer. Javadoc

Input type: java.lang.Object

Example ToInteger
final ToInteger function = new ToInteger();
{
  "class" : "uk.gov.gchq.koryphe.impl.function.ToInteger"
}
g.ToInteger()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 4 java.lang.Integer 4
java.lang.Long 5 java.lang.Integer 5
java.lang.String 5 java.lang.Integer 5
java.lang.String aString NumberFormatException: For input string: "aString"
java.util.Arrays$ArrayList [6, 3] IllegalArgumentException: Could not convert value to Integer: [6, 3]
null null

ToList

Converts an Object to a List. Javadoc

Input type: java.lang.Object

Example ToList
final ToList function = new ToList();
{
  "class" : "uk.gov.gchq.koryphe.impl.function.ToList"
}
g.ToList()

Example inputs:

Input Type Input Result Type Result
java.lang.String test java.util.ArrayList [test]
null java.util.ArrayList [null]
java.lang.Long 30 java.util.ArrayList [30]
uk.gov.gchq.gaffer.types.TypeSubTypeValue TypeSubTypeValue[type=t,subType=st,value=v] java.util.ArrayList [TypeSubTypeValue[type=t,subType=st,value=v]]
java.lang.String[] [a, b, c] java.util.ArrayList [a, b, c]
java.util.HashSet [1, 2] java.util.ArrayList [1, 2]

ToLong

Returns any input as Long. Javadoc

Input type: java.lang.Object

Example ToLong
final ToLong function = new ToLong();
{
  "class" : "ToLong"
}
g.ToLong()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 4 java.lang.Long 4
java.lang.Long 5 java.lang.Long 5
java.lang.String 5 java.lang.Long 5
java.lang.String aString NumberFormatException: For input string: "aString"
java.util.Arrays$ArrayList [6, 3] IllegalArgumentException: Could not convert value to Long: [6, 3]
null null

ToLowerCase

Performs toLowerCase on input object. Javadoc

Input type: java.lang.Object

Example ToLowerCase
final ToLowerCase function = new ToLowerCase();
{
  "class" : "ToLowerCase"
}
g.ToLowerCase()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 4 java.lang.String 4
java.lang.Long 5 java.lang.String 5
java.lang.String ACAPTIALISEDSTRING java.lang.String acaptialisedstring
java.lang.String alowercasestring java.lang.String alowercasestring
java.lang.String aString java.lang.String astring
java.util.Arrays$ArrayList [6, 3] java.lang.String [6, 3]
null null

ToNull

Returns null on any input object. Javadoc

Input type: java.lang.Object

Example ToNull
final ToNull function = new ToNull();
{
  "class" : "ToNull"
}
g.ToNull()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 4 null
java.lang.Long 5 null
java.lang.String aString null
java.util.Arrays$ArrayList [6, 3] null
null null

ToSet

Converts an Object to a Set. Javadoc

Input type: java.lang.Object

Example ToSet
final ToSet function = new ToSet();
{
  "class" : "uk.gov.gchq.koryphe.impl.function.ToSet"
}
g.ToSet()

Example inputs:

Input Type Input Result Type Result
java.lang.String test java.util.HashSet [test]
null java.util.HashSet [null]
java.lang.Long 30 java.util.HashSet [30]
uk.gov.gchq.gaffer.types.TypeSubTypeValue TypeSubTypeValue[type=t,subType=st,value=v] java.util.HashSet [TypeSubTypeValue[type=t,subType=st,value=v]]
java.lang.String[] [a, b, c] java.util.HashSet [a, b, c]
java.util.Arrays$ArrayList [test1, test2] java.util.HashSet [test2, test1]

ToString

Calls toString on each input. If the input is null, null is returned. Javadoc

Input type: java.lang.Object

Example ToString
final ToString function = new ToString();
{
  "class" : "ToString"
}
g.ToString()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 1 java.lang.String 1
java.lang.Double 2.5 java.lang.String 2.5
java.lang.String abc java.lang.String abc
null null

ToTuple

Converts an Object into a Tuple. Javadoc

Input type: java.lang.Object

Example ToTuple
final ToTuple function = new ToTuple();
{
  "class" : "ToTuple"
}
g.ToTuple()

Example inputs:

Input Type Input Result Type Result
java.util.ArrayList [1, 2, 3, 4] [java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer] [1, 2, 3, 4]
java.lang.Integer[] [1, 2, 3, 4] [java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer] [1, 2, 3, 4]
java.util.HashMap {A=1, B=2, C=3} uk.gov.gchq.koryphe.tuple.MapTuple [1, 2, 3]

ToUpperCase

Calls toString followed by toUpperCase on each input. If the input is null, null is returned. Javadoc

Input type: java.lang.Object

Example ToUpperCase
final ToUpperCase function = new ToUpperCase();
{
  "class" : "ToUpperCase"
}
g.ToUpperCase()

Example inputs:

Input Type Input Result Type Result
java.lang.Integer 4 java.lang.String 4
java.lang.Long 5 java.lang.String 5
java.lang.String ACAPTIALISEDSTRING java.lang.String ACAPTIALISEDSTRING
java.lang.String alowercasestring java.lang.String ALOWERCASESTRING
java.lang.String aString java.lang.String ASTRING
java.util.Arrays$ArrayList [6, 3] java.lang.String [6, 3]
null null

Last update: May 18, 2023
Created: May 18, 2023