Back to Fresco

Objects

docs/javadoc/reference/com/facebook/common/internal/Objects.html

3.6.016.7 KB
Original Source

Fresco

|

|

Packages | Classes

Interfaces

Classes

Annotations

Packages | Classes

Summary: Nested Classes | Methods | Inherited Methods | [Expand All]

public final class

Objects

extends Object

| java.lang.Object | | ↳ | com.facebook.common.internal.Objects |

Class Overview

Helper functions that operate on any Object, and are not already provided in java.util.Objects.

See the Guava User Guide on writing Object methods with Objects.

Summary

Nested Classes
class
Public Methods
static boolean
Determines whether two possibly-null objects are equal.
static <T> T
Returns the first of two given parameters that is not null, if either is, or otherwise throws a NullPointerException.
static int
Generates a hash code for multiple values.
static Objects.ToStringHelper
Creates an instance of Objects.ToStringHelper in the same manner as toStringHelper(Object), but using className instead of using an instance's getClass().
static Objects.ToStringHelper
Creates an instance of Objects.ToStringHelper.
static Objects.ToStringHelper
Creates an instance of Objects.ToStringHelper in the same manner as toStringHelper(Object), but using the simple name of clazz instead of using an instance's getClass().

| [Expand] Inherited Methods | | --- | | From class java.lang.Object

| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |

|

Public Methods

public static boolean equal(Object a, Object b)

Determines whether two possibly-null objects are equal. Returns:

  • true if a and b are both null.
  • true if a and b are both non-null and they are equal according to equals(Object).
  • false in all other situations.

This assumes that any non-null objects passed to this function conform to the equals() contract.

public static T firstNonNull(T first, T second)

Returns the first of two given parameters that is not null, if either is, or otherwise throws a NullPointerException.

Note: if first is represented as an Optional, this can be accomplished with Optional#or(Object) first.or(second). That approach also allows for lazy evaluation of the fallback instance, using Optional#or(Supplier) first.or(Supplier).

Returns
  • first if first is not null, or second if first is null and second is not null
Throws

| NullPointerException | if both first and second were null |

public static int hashCode(Object... objects)

Generates a hash code for multiple values. The hash code is generated by calling 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 hashCode(). For example, in an object that has three properties, x, y, and z, 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.

public static Objects.ToStringHelper toStringHelper(String className)

Creates an instance of Objects.ToStringHelper in the same manner as toStringHelper(Object), but using className instead of using an instance's getClass().

Parameters

| className | the name of the instance type |

public static Objects.ToStringHelper toStringHelper(Object self)

Creates an instance of Objects.ToStringHelper.

This is helpful for implementing 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 (typically this), used only for its class name |

public static Objects.ToStringHelper toStringHelper(Class<?> clazz)

Creates an instance of Objects.ToStringHelper in the same manner as toStringHelper(Object), but using the simple name of clazz instead of using an instance's getClass().

Note that in GWT, class names are often obfuscated.

Parameters

| clazz | the Class of the instance |

+Generated by Doclava. +