Package org.togglz.core.util
Class MoreObjects
- java.lang.Object
-
- org.togglz.core.util.MoreObjects
-
public final class MoreObjects extends Object
Helper functions that can operate on anyObject.See the Guava User Guide on writing
Objectmethods withObjects.Imported from com.google.guava:17.0 Objects
- Author:
- Laurence Gonsalves
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMoreObjects.ToStringHelperSupport class fortoStringHelper(java.lang.Object).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TfirstNonNull(T first, T second)Returns the first of two given parameters that is notnull, if either is, or otherwise throws aNullPointerException.static MoreObjects.ToStringHelpertoStringHelper(Object self)Creates an instance ofMoreObjects.ToStringHelper.
-
-
-
Method Detail
-
toStringHelper
public static MoreObjects.ToStringHelper toStringHelper(Object self)
Creates an instance ofMoreObjects.ToStringHelper.This is helpful for implementing
Object.toString(). Specification by example:// Returns "ClassName{}" Objects.toStringHelper(this) .toString(); <p> // Returns "ClassName{x=1}" Objects.toStringHelper(this) .add("x", 1) .toString(); <p> // Returns "MyObject{x=1}" Objects.toStringHelper("MyObject") .add("x", 1) .toString(); <p> // Returns "ClassName{x=1, y=foo}" Objects.toStringHelper(this) .add("x", 1) .add("y", "foo") .toString(); <p> // Returns "ClassName{x=1}" Objects.toStringHelper(this) .omitNullValues() .add("x", 1) .add("y", null) .toString();}Note that in GWT, class names are often obfuscated.
- Parameters:
self- the object to generate the string for (typicallythis), used only for its class name- Since:
- 2.0
-
firstNonNull
public static <T> T firstNonNull(T first, T second)Returns the first of two given parameters that is notnull, if either is, or otherwise throws aNullPointerException.- Returns:
firstiffirstis notnull, orsecondiffirstisnullandsecondis notnull- Throws:
NullPointerException- if bothfirstandsecondwerenull- Since:
- 3.0
-
-