Here you can find the source of compareTermList(final List
Parameter | Description |
---|---|
Term | The subterm type, must derive from IDLTerm . |
tl0 | The first term list |
tl1 | The second term list <p/> |
public static <Term extends Comparable<? super Term>> int compareTermList(final List<Term> tl0, final List<? extends Term> tl1)
//package com.java2s; /**/* ww w .j a v a2 s.co m*/ * (c) 2009-2014 Otto-Friedrich-University Bamberg * * $Id$ * * Use, modification and restribution of this file are covered by the * terms of the Artistic License 2.0. * * You should have received a copy of the license terms in a file named * "LICENSE" together with this software package. * * Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT * HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR * A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE * EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO * COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT * OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. **/ import java.util.List; public class Main { /** * Compare two term lists by comparing their subterms in order. <p /> * The comparison of the first non-equal subterm decides. If the first {@literal min(tl0.size(), tl1.size())} of * both term lists are equal, the term length is used to decide. * * @param <Term> The subterm type, must derive from {@link IDLTerm}. * @param tl0 The first term list * @param tl1 The second term list * <p/> * @return {@literal -1}, if {@literal tl0 < tl1}, {@literal 0}, if {@literal tl0.equals(tl1)} and {@literal 1}, * if {@literal tl0 > tl1}. */ public static <Term extends Comparable<? super Term>> int compareTermList(final List<Term> tl0, final List<? extends Term> tl1) { int minSize = Math.min(tl0.size(), tl1.size()); int compare = 0; /* * compareTermList for common initial subterms */ for (int i = 0; (compare == 0) && (i < minSize); ++i) { compare = tl0.get(i).compareTo(tl1.get(i)); } /* * common subterms match, term length decides */ if (compare == 0) { compare = tl1.size() - tl0.size(); } if (compare < 0) { return -1; } else if (compare > 0) { return 1; } else { return 0; } } }