Debian Codegraph @

src/main/java/org/jfree/pdf/util/ObjectUtils.java

raw
1 /* =====================================================================
2 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
3 * =====================================================================
4 *
5 * (C)opyright 2013-2022, by David Gilbert. All rights reserved.
6 *
7 * https://github.com/jfree/orsonpdf
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
23 * Other names may be trademarks of their respective owners.]
24 *
25 * If you do not wish to be bound by the terms of the GPL, an alternative
26 * runtime license is available to JFree sponsors:
27 *
28 * https://github.com/sponsors/jfree
29 *
30 */
31
32 package org.jfree.pdf.util;
33
34 /**
35 * Some utility methods.
36 */
37 public class ObjectUtils {
38
39 private ObjectUtils() {
40 // no need to instantiate
41 }
42
43 /**
44 * Returns {@code true} if the objects are equal or both
45 * {@code null}, and {@code false} otherwise. In Java 7, we
46 * could use the {@code Objects} class instead.
47 *
48 * @param obj1 object 1.
49 * @param obj2 object 2.
50 *
51 * @return A boolean.
52 */
53 public static boolean equals(Object obj1, Object obj2) {
54 if (obj1 == null) {
55 return obj2 == null;
56 } else {
57 return obj1.equals(obj2);
58 }
59 }
60
61 /**
62 * Returns the hash code for the object, or 0 if the object is
63 * {@code null}. In Java 7, we could use the {@code Objects}
64 * class instead.
65 *
66 * @param obj the object ({@code null} permitted).
67 *
68 * @return The hash code or 0.
69 */
70 public static int hashCode(Object obj) {
71 if (obj == null) {
72 return 0;
73 }
74 return obj.hashCode();
75 }
76 }