Class Objects
Object.
See the Guava User Guide on writing
Object methods with Objects.
- Since:
- 2.0 (imported from Google Collections Library)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDeprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023 -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanDeprecated.Determines whether two possibly-null objects are equal.static <T> TfirstNonNull(T first, T second) Deprecated.Returns the first of two given parameters that is notnull, if either is, or otherwise throws aNullPointerException.static intDeprecated.Generates a hash code for multiple values.static Objects.ToStringHelpertoStringHelper(Class<?> clazz) Deprecated.Creates an instance ofObjects.ToStringHelperin the same manner astoStringHelper(Object), but using the name ofclazzinstead of using an instance'sObject.getClass().static Objects.ToStringHelpertoStringHelper(Object self) Deprecated.Creates an instance ofObjects.ToStringHelper.static Objects.ToStringHelpertoStringHelper(String className) Deprecated.Creates an instance ofObjects.ToStringHelperin the same manner astoStringHelper(Object), but usingclassNameinstead of using an instance'sObject.getClass().
-
Method Details
-
equal
Deprecated.Determines whether two possibly-null objects are equal. Returns:trueifaandbare both null.trueifaandbare both non-null and they are equal according toObject.equals(Object).falsein all other situations.
This assumes that any non-null objects passed to this function conform to the
equals()contract. -
hashCode
Deprecated.Generates a hash code for multiple values. The hash code is generated by callingArrays.hashCode(Object[]). Note that array arguments to this method, with the exception of a single Object array, do not get any special handling; their hash codes are based on identity and not contents.This is useful for implementing
Object.hashCode(). For example, in an object that has three properties,x,y, andz, one could write:public int hashCode() { return Objects.hashCode(getX(), getY(), getZ()); }Warning: When a single object is supplied, the returned hash code does not equal the hash code of that object.
-
toStringHelper
Deprecated.Creates an instance ofObjects.ToStringHelper.This is helpful for implementing
Object.toString(). Specification by example:// Returns "ClassName{}" Objects.toStringHelper(this) .toString(); // Returns "ClassName{x=1}" Objects.toStringHelper(this) .add("x", 1) .toString(); // Returns "MyObject{x=1}" Objects.toStringHelper("MyObject") .add("x", 1) .toString(); // Returns "ClassName{x=1, y=foo}" Objects.toStringHelper(this) .add("x", 1) .add("y", "foo") .toString(); // 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
-
toStringHelper
Deprecated.Creates an instance ofObjects.ToStringHelperin the same manner astoStringHelper(Object), but using the name ofclazzinstead of using an instance'sObject.getClass().Note that in GWT, class names are often obfuscated.
- Parameters:
clazz- theClassof the instance- Since:
- 7.0 (source-compatible since 2.0)
-
toStringHelper
Deprecated.Creates an instance ofObjects.ToStringHelperin the same manner astoStringHelper(Object), but usingclassNameinstead of using an instance'sObject.getClass().- Parameters:
className- the name of the instance type- Since:
- 7.0 (source-compatible since 2.0)
-
firstNonNull
public static <T> T firstNonNull(@Nullable T first, @Nullable T second) Deprecated.Returns the first of two given parameters that is notnull, if either is, or otherwise throws aNullPointerException.Note: if
firstis represented as anOptional<T>, this can be accomplished withfirst.or(second). That approach also allows for lazy evaluation of the fallback instance, usingfirst.or(Supplier).- Returns:
firstiffirstis notnull, orsecondiffirstisnullandsecondis notnull- Throws:
NullPointerException- if bothfirstandsecondwerenull- Since:
- 3.0
-