EqualsUtility.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
004  *
005  * "Hilbert II" is free software; you can redistribute
006  * it and/or modify it under the terms of the GNU General Public
007  * License as published by the Free Software Foundation; either
008  * version 2 of the License, or (at your option) any later version.
009  *
010  * This program is distributed in the hope that it will be useful,
011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013  * GNU General Public License for more details.
014  */
015 
016 package org.qedeq.base.utility;
017 
018 import java.util.Arrays;
019 
020 
021 /**
022  * A collection of useful static methods for equality.
023  *
024  @author  Michael Meyling
025  */
026 public final class EqualsUtility {
027 
028     /**
029      * Constructor, should never be called.
030      */
031     private EqualsUtility() {
032         // don't call me
033     }
034 
035     /**
036      * Compare two objects, each of them could be <code>null</code>.
037      *
038      @param   a   First parameter.
039      @param   b   Second parameter.
040      @return  Are <code>a</code> and <code>b</code> equal?
041      */
042     public static boolean equals(final Object a, final Object b) {
043         if (a == null) {
044             if (b == null) {
045                 return true;
046             }
047             return false;
048         }
049         return a.equals(b);
050     }
051 
052     /**
053      * Compare two objects, each of them could be <code>null</code>.
054      *
055      @param   a   First parameter.
056      @param   b   Second parameter.
057      @return  Are <code>a</code> and <code>b</code> equal?
058      */
059     public static boolean equals(final Object[] a, final Object[] b) {
060         if (a == null) {
061             if (b == null) {
062                 return true;
063             }
064             return false;
065         }
066         return Arrays.equals(a, b);
067     }
068 
069     /**
070      * Compare two objects, each of them could be <code>null</code>.
071      *
072      @param   a   First parameter.
073      @param   b   Second parameter.
074      @return  Are <code>a</code> and <code>b</code> equal?
075      */
076     public static boolean equals(final byte[] a, final byte[] b) {
077         if (a == null) {
078             if (b == null) {
079                 return true;
080             }
081             return false;
082         }
083         return Arrays.equals(a, b);
084     }
085 
086     /**
087      * Compare two objects, each of them could be <code>null</code>.
088      *
089      @param   a   First parameter.
090      @param   b   Second parameter.
091      @return  Are <code>a</code> and <code>b</code> equal?
092      */
093     public static boolean equals(final int[] a, final int[] b) {
094         if (a == null) {
095             if (b == null) {
096                 return true;
097             }
098             return false;
099         }
100         return Arrays.equals(a, b);
101     }
102 
103 }