Java String Equal areStringEquals(String string1, String string2)

Here you can find the source of areStringEquals(String string1, String string2)

Description

Checks if two strings are equals.

License

Apache License

Parameter

Parameter Description
string1 from tree element
string2 from rule element

Return

true if and only if the two strings are equal (both equal or both null)

Declaration

public static boolean areStringEquals(String string1, String string2) 

Method Source Code

//package com.java2s;
/**/*  ww  w .  ja va  2s. c om*/
 * Copyright (C) 2012 cogroo <cogroo@cogroo.org>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Checks if two strings are equals.
     * The strings can be both null, one of them null or none of them null.
     * 
     * @param string1 from tree element 
     * @param string2 from rule element 
     * @return true if and only if the two strings are equal (both equal or both null)
     */
    public static boolean areStringEquals(String string1, String string2) {
        /* string1   string2   outcome
         * null      null   true
         * null      x      false
         * x      null   false
         * x      y      false
         * x      x      true
         */
        // XXX both null must be unequal? If yes, boolean must be too?
        if (string1 == null && string2 == null) {
            return false;
        } else if (string1 != null && !string1.equals(string2)) {
            return false;
        } else if (string2 != null && !string2.equals(string1)) {
            return false;
        }
        return true;
    }
}

Related

  1. areEquals(final String origin, final String checkWith)
  2. areEquals(final String s1, final String s2)
  3. areEqualsIgnoreCaseAndTrim(final String s1, final String s2)
  4. areEqualXMLValues(String s1, String s2)
  5. areStringEquals(String s1, String s2)
  6. areStringsEqual(String one, String two)
  7. areStringsEqual(String s1, String s2, boolean caseInsensitive)
  8. areStringsEqual(String s1, String s2, boolean caseInsensitive, boolean dontDistinctNullAndEmpty)
  9. areStringsEqual(String str1, String str2)