Java Collection Equal orderedEqual(Collection c1, Collection c2)

Here you can find the source of orderedEqual(Collection c1, Collection c2)

Description

ordered Equal

License

Open Source License

Declaration

public static final <T> boolean orderedEqual(Collection<T> c1, Collection<T> c2) 

Method Source Code

//package com.java2s;
/*/*from   w ww.ja v  a2  s. c  o  m*/
   Copyright (c) 2009-2011 Olivier Chafik, All Rights Reserved
       
   This file is part of JNAerator (http://jnaerator.googlecode.com/).
       
   JNAerator is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
       
   JNAerator is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
       
   You should have received a copy of the GNU General Public License
   along with JNAerator.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static final <T> boolean orderedEqual(Collection<T> c1, Collection<T> c2) {
        if (c1.size() != c2.size())
            return false;
        Iterator<T> i1 = c1.iterator(), i2 = c2.iterator();
        while (i1.hasNext() && i2.hasNext()) {
            T t1 = i1.next(), t2 = i2.next();
            if ((t1 == null) != (t2 == null))
                return false;
            if (t1 != null) {
                if (!(t1.equals(t2) && t2.equals(t1)))
                    return false;
            }
        }
        return (i1.hasNext() == i2.hasNext());
    }
}

Related

  1. isEqualCollection(final Collection a, final Collection b)
  2. isEqualCollection(final Collection a, final Collection b)
  3. isEqualDeep(Collection a, Collection b)
  4. isEquals(Collection set1, Collection set2)
  5. isEqualsSize(Collection res, Collection des)