Java List Compare compareLists(final List list1, final List list2)

Here you can find the source of compareLists(final List list1, final List list2)

Description

compare Lists

License

Open Source License

Declaration

public static <T extends Comparable<? super T>> int compareLists(final List<? extends T> list1,
            final List<? extends T> list2) 

Method Source Code


//package com.java2s;
/*//from w  ww .  ja  v a 2s . c  o m
========================================================================
SchemaCrawler
http://www.schemacrawler.com
Copyright (c) 2000-2016, Sualeh Fatehi <sualeh@hotmail.com>.
All rights reserved.
------------------------------------------------------------------------
    
SchemaCrawler 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.
    
SchemaCrawler and the accompanying materials are made available under
the terms of the Eclipse Public License v1.0, GNU General Public License
v3 or GNU Lesser General Public License v3.
    
You may elect to redistribute this code under any of these licenses.
    
The Eclipse Public License is available at:
http://www.eclipse.org/legal/epl-v10.html
    
The GNU General Public License v3 and the GNU Lesser General Public
License v3 are available at:
http://www.gnu.org/licenses/
    
========================================================================
*/

import java.util.Iterator;
import java.util.List;

public class Main {
    public static <T extends Comparable<? super T>> int compareLists(final List<? extends T> list1,
            final List<? extends T> list2) {

        if (list1 == null) {
            return -1;
        }
        if (list2 == null) {
            return 1;
        }

        int comparison = list1.size() - list2.size();

        if (comparison == 0) {
            final Iterator<? extends T> iter1 = list1.iterator();
            final Iterator<? extends T> iter2 = list2.iterator();

            while (comparison == 0 && iter1.hasNext() && iter2.hasNext()) {
                final T object1 = iter1.next();
                final T object2 = iter2.next();

                comparison = object1.compareTo(object2);
            }
        }

        return comparison;
    }
}

Related

  1. compareFileLists(List expected, List gotten)
  2. compareIncarnations(List e1, List e2)
  3. compareList(List listA, List listB)
  4. compareList(Object eObj, Object rObj)
  5. compareLists(Class type, List list1, List list2)
  6. compareLists(List strings1, List strings2, boolean ignoreCase)
  7. compareLists(List l1, List l2)
  8. compareLists(List list, List> listOfLists)
  9. compareLists(List a, List b)