public class FieldsAndGetters extends Object
Modifier and Type | Class and Description |
---|---|
static class |
FieldsAndGetters.ObjectIsNull
Sentinel class for null objects.
|
Constructor and Description |
---|
FieldsAndGetters() |
Modifier and Type | Method and Description |
---|---|
static void |
dumpAll(String name,
Object obj)
Dumps all fields and getters of
obj to System.out . |
static void |
dumpAll(String name,
Object obj,
StringPrinter printer)
Dumps all fields and getters of
obj to printer . |
static void |
dumpIf(String name,
Object obj,
Predicate<String> evalPredicate,
Predicate<Map.Entry<String,Object>> dumpPredicate,
StringPrinter printer)
Passes each field and getter of
obj to evalPredicate , grabs its value if it passes, and if the value passes dumpPredicate then it is dumped to printer . |
static void |
dumpNonNull(String name,
Object obj)
Dumps all non-null fields and getters of
obj to System.out . |
static void |
dumpNonNull(String name,
Object obj,
StringPrinter printer)
Dumps all non-null fields and getters of
obj to printer . |
static Stream<Map.Entry<Field,Object>> |
fields(Object obj)
Returns a
Stream of all public fields and their values for the given object. |
static Stream<Map.Entry<Field,Object>> |
fields(Object obj,
Predicate<Field> predicate)
Returns a
Stream of all public fields which match predicate and their values for the given object. |
static Stream<Map.Entry<String,Object>> |
fieldsAndGetters(Object obj)
Returns a
Stream of all public fields and getter methods and their values for the given object. |
static Stream<Map.Entry<String,Object>> |
fieldsAndGetters(Object obj,
Predicate<String> predicate)
Returns a
Stream of all public fields and getter methods which match predicate and their values for the given object. |
static Stream<Map.Entry<Method,Object>> |
getters(Object obj)
Returns a
Stream of all public getter methods and their return values for the given object. |
static Stream<Map.Entry<Method,Object>> |
getters(Object obj,
Predicate<Method> predicate)
Returns a
Stream of all public getter methods which match predicate and their return values for the given object. |
public static Stream<Map.Entry<Field,Object>> fields(Object obj)
Stream
of all public fields and their values for the given object.fields(Object, Predicate)
public static Stream<Map.Entry<Field,Object>> fields(Object obj, Predicate<Field> predicate)
Stream
of all public fields which match predicate
and their values for the given object.
This method uses reflection to find all of the public instance fields of the given object,
and if they pass the given predicate, it includes them in a stream of Map.Entry<Field, Object>
where the entry's value is the value of the field for this object.
public static Stream<Map.Entry<Method,Object>> getters(Object obj)
Stream
of all public getter methods and their return values for the given object.getters(Object, Predicate)
public static Stream<Map.Entry<Method,Object>> getters(Object obj, Predicate<Method> predicate)
Stream
of all public getter methods which match predicate
and their return values for the given object.
This method uses reflection to find all of the public instance methods which don't take any arguments
and return a value. If they pass the given predicate, then they are called, and the return value is
included in a stream of Map.Entry<Method, Object>
.
Note that there are some methods which have the signature of a getter, but actually mutate the object
being inspected, e.g. InputStream.read()
. These will be called unless you manually
exclude them using the predicate.
public static Stream<Map.Entry<String,Object>> fieldsAndGetters(Object obj)
Stream
of all public fields and getter methods and their values for the given object.getters(Object, Predicate)
public static Stream<Map.Entry<String,Object>> fieldsAndGetters(Object obj, Predicate<String> predicate)
Stream
of all public fields and getter methods which match predicate
and their values for the given object.
This method combines the results of fields(Object, Predicate)
and getters(Object, Predicate)
. The Predicate<String>
will be passed the field names and the getter names (which are postfixed by ()
to mark them as methods).
public static void dumpIf(String name, Object obj, Predicate<String> evalPredicate, Predicate<Map.Entry<String,Object>> dumpPredicate, StringPrinter printer)
obj
to evalPredicate
, grabs its value if it passes, and if the value passes dumpPredicate
then it is dumped to printer
.fieldsAndGetters(Object, Predicate)
public static void dumpAll(String name, Object obj)
obj
to System.out
.public static void dumpNonNull(String name, Object obj)
obj
to System.out
.public static void dumpAll(String name, Object obj, StringPrinter printer)
obj
to printer
.public static void dumpNonNull(String name, Object obj, StringPrinter printer)
obj
to printer
.