| 1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
| 2 | * |
| 3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
| 4 | * |
| 5 | * "Hilbert II" is free software; you can redistribute |
| 6 | * it and/or modify it under the terms of the GNU General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | package org.qedeq.base.utility; |
| 17 | |
| 18 | import java.util.Arrays; |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * A collection of useful static methods for equality. |
| 23 | * |
| 24 | * @author Michael Meyling |
| 25 | */ |
| 26 | public final class EqualsUtility { |
| 27 | |
| 28 | /** |
| 29 | * Constructor, should never be called. |
| 30 | */ |
| 31 | private EqualsUtility() { |
| 32 | // don't call me |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Compare two objects, each of them could be <code>null</code>. |
| 37 | * |
| 38 | * @param a First parameter. |
| 39 | * @param b Second parameter. |
| 40 | * @return Are <code>a</code> and <code>b</code> equal? |
| 41 | */ |
| 42 | public static boolean equals(final Object a, final Object b) { |
| 43 | if (a == null) { |
| 44 | if (b == null) { |
| 45 | return true; |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | return a.equals(b); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Compare two objects, each of them could be <code>null</code>. |
| 54 | * |
| 55 | * @param a First parameter. |
| 56 | * @param b Second parameter. |
| 57 | * @return Are <code>a</code> and <code>b</code> equal? |
| 58 | */ |
| 59 | public static boolean equals(final Object[] a, final Object[] b) { |
| 60 | if (a == null) { |
| 61 | if (b == null) { |
| 62 | return true; |
| 63 | } |
| 64 | return false; |
| 65 | } |
| 66 | return Arrays.equals(a, b); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Compare two objects, each of them could be <code>null</code>. |
| 71 | * |
| 72 | * @param a First parameter. |
| 73 | * @param b Second parameter. |
| 74 | * @return Are <code>a</code> and <code>b</code> equal? |
| 75 | */ |
| 76 | public static boolean equals(final byte[] a, final byte[] b) { |
| 77 | if (a == null) { |
| 78 | if (b == null) { |
| 79 | return true; |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | return Arrays.equals(a, b); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Compare two objects, each of them could be <code>null</code>. |
| 88 | * |
| 89 | * @param a First parameter. |
| 90 | * @param b Second parameter. |
| 91 | * @return Are <code>a</code> and <code>b</code> equal? |
| 92 | */ |
| 93 | public static boolean equals(final int[] a, final int[] b) { |
| 94 | if (a == null) { |
| 95 | if (b == null) { |
| 96 | return true; |
| 97 | } |
| 98 | return false; |
| 99 | } |
| 100 | return Arrays.equals(a, b); |
| 101 | } |
| 102 | |
| 103 | } |