Functions: Get

org.op4j.functions.Get is a special functions class which allows the retrieval of attribute values through the execution of getter methods.

Here is an example: Imagine your application has a User class which contains a getName() method, returning a String. Let's get the names of all the users in a list:

List<User> users = ...;
List<String> userNames = Op.on(users).map(Get.attrOfString("name")).get();

The attrOfX(...) methods in the Get class return the following functions:

MethodReturned function type
attrOfBigDecimal()Function<Object,BigDecimal>
attrOfBigInteger()Function<Object,BigInteger>
attrOfBoolean()Function<Object,Boolean>
attrOfByte()Function<Object,Byte>
attrOfCalendar()Function<Object,Calendar>
attrOfCharacter()Function<Object,Character>
attrOfDate()Function<Object,Date>
attrOfDouble()Function<Object,Double>
attrOfFloat()Function<Object,Float>
attrOfInteger()Function<Object,Integer>
attrOfLong()Function<Object,Long>
attrOfObject()Function<Object,Object>
attrOfShort()Function<Object,Short>
attrOfString()Function<Object,String>
attrOf(Type<T>)Function<Object,T>
attrOfArrayOf(Type<T>)Function<Object,T[]>
attrOfArrayOfString()Function<Object,String[]>
attrOfListOf(Type<T>)Function<Object,List<T>>
attrOfListOfString()Function<Object,List<String>>
attrOfSetOf(Type<T>)Function<Object,Set<T>>
attrOfSetOfString()Function<Object,Set<String>>

There also exist more convenient abbreviated methods, which are:

MethodReturned function type
bigDecimal()Function<Object,BigDecimal>
bigInteger()Function<Object,BigInteger>
bool()Function<Object,Boolean>
calendar()Function<Object,Calendar>
c()Function<Object,Character>
date()Function<Object,Date>
d()Function<Object,Double>
f()Function<Object,Float>
i()Function<Object,Integer>
l()Function<Object,Long>
obj()Function<Object,Object>
shr()Function<Object,Short>
s()Function<Object,String>
obj(Type<T>)Function<Object,T>
arrayOf(Type<T>)Function<Object,T[]>
arrayOfString()Function<Object,String[]>
listOf(Type<T>)Function<Object,List<T>>
listOfString()Function<Object,List<String>>
setOf(Type<T>)Function<Object,Set<T>>
setOfString()Function<Object,Set<String>>