Java Collection Equal isEqual(Collection left, Collection right)

Here you can find the source of isEqual(Collection left, Collection right)

Description

is Equal

License

Apache License

Declaration

public static boolean isEqual(Collection left, Collection right) 

Method Source Code

//package com.java2s;
/**// w w  w  . java2s.c o m
 * Copyright (C) 2014-2015 LinkedIn Corp. (pinot-core@linkedin.com)
 *
 * 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.
 */

import java.util.Arrays;
import java.util.Collection;

import java.util.Map;

public class Main {
    public static boolean isEqual(int left, int right) {
        return left == right;
    }

    public static boolean isEqual(long left, long right) {
        return left == right;
    }

    public static boolean isEqual(float left, float right) {
        return Float.compare(left, right) == 0;
    }

    public static boolean isEqual(double left, double right) {
        return Double.compare(left, right) == 0;
    }

    public static boolean isEqual(short left, short right) {
        return left == right;
    }

    public static boolean isEqual(char left, char right) {
        return left == right;
    }

    public static boolean isEqual(byte left, byte right) {
        return left == right;
    }

    public static boolean isEqual(Object[] left, Object[] right) {
        return Arrays.deepEquals(left, right);
    }

    public static boolean isEqual(Collection left, Collection right) {
        if (left != null && right != null) {
            return left.toString().equals(right.toString());
        } else {
            return left == right;
        }
    }

    public static boolean isEqual(Map left, Map right) {
        if (left != null && right != null) {
            if (left.size() != right.size()) {
                return false;
            }
            for (Object key : left.keySet()) {
                if (right.containsKey(key)) {
                    Object leftValue = left.get(key);
                    Object rightValue = right.get(key);
                    if (!isEqual(leftValue, rightValue)) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            return true;
        } else {
            return left == right;
        }
    }

    public static boolean isEqual(Object left, Object right) {
        if (left != null)
            return left.equals(right);
        else
            return null == right;
    }
}

Related

  1. getContainedEquals(Collection a, T b)
  2. indexOfEquals(Collection collection, T element)
  3. isCollectionEqual(Collection c1, Collection c2)
  4. isCollectionsEqual(Collection f1, Collection f2)
  5. isContentEqual(final Collection collectionA, final Collection collectionB)
  6. isEqual(Collection one, Collection two)
  7. isEqual(Collection coll, Comparator comp)
  8. isEqual(Collection a, Collection b)
  9. isEqualBasicCol(Collection col1, Collection col2)