Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Cacheonix Systems licenses this file to You under the LGPL 2.1
 * (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.cacheonix.org/products/cacheonix/license-lgpl-2.1.htm
 *
 * 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.Iterator;
import java.util.List;

import java.util.Set;

public class Main {
    /**
     * Returns <code>true</code> if both lists are the same?
     *
     * @param list1
     * @param list2
     * @return
     */
    @SuppressWarnings("ObjectEquality")
    public static boolean same(final List list1, final List list2) {

        if (list1 == null || list2 == null) {
            return false;
        }
        if (list1.size() != list2.size()) {
            return false;
        }
        if (list1 == list2) {
            return true;
        }
        if (list1.equals(list2)) {
            return true;
        }
        for (int i = 0; i < list1.size(); i++) {
            if (!list1.get(i).equals(list2.get(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * Returns <code>true</code> if both lists are the same?
     *
     * @param set1
     * @param set2
     * @return
     */
    @SuppressWarnings("ObjectEquality")
    public static boolean same(final Set set1, final Set set2) {

        if (set1 == null || set2 == null) {
            return false;
        }
        if (set1.size() != set2.size()) {
            return false;
        }
        if (set1 == set2) {
            return true;
        }
        final Iterator iter1 = set1.iterator();
        final Iterator iter2 = set2.iterator();
        while (iter1.hasNext()) {
            final Object o1 = iter1.next();
            final Object o2 = iter2.next();
            if (!o1.equals(o2)) {
                return false;
            }
        }
        return true;
    }
}