| 35 | /// |
| 36 | /// @author shannah |
| 37 | public final class Objects { |
| 38 | private Objects() {} |
| 39 | |
| 40 | /// 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. |
| 41 | /// |
| 42 | /// #### Parameters |
| 43 | /// |
| 44 | /// - `a` |
| 45 | /// |
| 46 | /// - `b` |
| 47 | @SuppressWarnings("PMD.SuspiciousEqualsMethodName") |
| 48 | public static boolean equals(Object a, Object b) { |
| 49 | if (a == b) { //NOPMD CompareObjectsWithEquals |
| 50 | return true; |
| 51 | } |
| 52 | return a != null && a.equals(b); |
| 53 | } |
| 54 | |
| 55 | /// Returns the hash code of a non-null argument and 0 for a null argument. |
| 56 | /// |
| 57 | /// #### Parameters |
| 58 | /// |
| 59 | /// - `o` |
| 60 | public static int hashCode(Object o) { |
| 61 | return o == null ? 0 : o.hashCode(); |
| 62 | } |
| 63 | |
| 64 | public static String toString(Object o) { |
| 65 | return toString(o, "null"); |
| 66 | } |
| 67 | |
| 68 | public static String toString(Object o, String nullDefault) { |
| 69 | return o != null ? o.toString() : nullDefault; |
| 70 | } |
| 71 | |
| 72 | public static <T> int compare(T a, T b, Comparator<? super T> c) { |
| 73 | return a == null && b == null ? 0 : c.compare(a, b); |
| 74 | } |
| 75 | |
| 76 | public static <T> T requireNonNull(T obj) { |
| 77 | return requireNonNull(obj, ""); |
| 78 | } |
| 79 | |
| 80 | public static <T> T requireNonNull(T obj, String message) { |
| 81 | if (obj == null) { |
| 82 | throw new NullPointerException(message); |
| 83 | } |
| 84 | return obj; |
| 85 | } |
| 86 | |
| 87 | public static boolean nonNull(Object obj) { |
| 88 | return obj != null; |
| 89 | } |
| 90 | |
| 91 | public static boolean deepEquals(Object a, Object b) { |
| 92 | if (a == b) { //NOPMD CompareObjectsWithEquals |
| 93 | return true; |
| 94 | } |
nothing calls this directly
no outgoing calls
no test coverage detected