MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / Objects

Class Objects

Ports/CLDC11/src/java/util/Objects.java:34–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32/// This class consists of static utility methods for operating on objects. These utilities include null-safe or null-tolerant methods for computing the hash code of an object, returning a string for an object, and comparing two objects.
33/// @author shannah
34public final class Objects {
35 /// Returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null, true is returned and if exactly one argument is null, false is returned. Otherwise, equality is determined by using the equals method of the first argument.
36 ///
37 /// #### Parameters
38 ///
39 /// - `a`
40 ///
41 /// - `b`
42 public static boolean equals(Object a, Object b) {
43 if (a == b) {
44 return true;
45 }
46 return a == null ? b == null : a.equals(b);
47 }
48
49 /// Returns the hash code of a non-null argument and 0 for a null argument.
50 ///
51 /// #### Parameters
52 ///
53 /// - `o`
54 public static int hashCode(Object o) {
55 return o == null ? 0 : o.hashCode();
56 }
57
58 public static String toString(Object o) {
59 return toString(o, "null");
60 }
61
62 public static String toString(Object o, String nullDefault) {
63 return o != null ? o.toString() : nullDefault;
64 }
65
66 public static <T> int compare(T a, T b, Comparator<? super T> c) {
67 return a == null && b == null ? 0 : c.compare(a, b);
68 }
69
70 public static <T> T requireNonNull(T obj) {
71 return requireNonNull(obj, "");
72 }
73
74 public static <T> T requireNonNull(T obj, String message) {
75 if (obj == null) {
76 throw new NullPointerException(message);
77 }
78 return obj;
79 }
80
81 public static boolean nonNull(Object obj) {
82 return obj != null;
83 }
84
85 public static boolean deepEquals(Object a, Object b) {
86 if (a == b) {
87 return true;
88 }
89 if (a == null) {
90 return b == null;
91 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected