⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extendedcomparator.java

📁 一个关于java 的常用工具包
💻 JAVA
字号:
package org.jutil.java.comparator;import java.util.Comparator;/** * <p>A Comparator with more convenient methods than <code>java.util.Comparator</code>.</p> * * @path    $Source: /cvsroot/org-jutil/jutil.org/src/org/jutil/java/comparator/ExtendedComparator.java,v $ * @version $Revision: 1.4 $ * @date    $Date: 2002/08/19 15:54:27 $ * @state   $State: Exp $ * @author  Tom Schrijvers * @author  Marko van Dooren * @release $Name:  $ */public abstract class ExtendedComparator implements Comparator {  /* The revision of this class */    public final static String CVS_REVISION ="$Revision: 1.4 $";	/**	 * <p>Return the maximum of both objects. In case of a tie, any	 * one of both can be returned.</p>	 *	 * @param first	 *        The first object	 * @param second	 *        The second object	 */ /*@	 @ public behavior	 @	 @ post \result == first | \result == second;	 @ post compare(\result, first) >= 0;	 @ post compare(\result, second) >= 0;	 @*/	public Object max(Object first, Object second) {		if (compare(first,second) >= 0) {			return first;		}		return second;	}		/**	 * <p>Return the minimum of both objects. In case of a tie, any	 * one of both can be returned.</p>	 *	 * @param first	 *        The first object	 * @param second	 *        The second object	 */ /*@	 @ public behavior	 @	 @ post \result == first | \result == second;	 @ post compare(\result, first) <= 0;	 @ post compare(\result, second) <= 0;	 @*/	public Object min(Object first, Object second) {		if (compare(first,second) <= 0) {			return first;		}		return second;	}	/**	 * <p>Check whether or not the first object is greater than	 * the second one.</p>	 *	 * @param first	 *        The first object	 * @param second	 *        The second object	 */ /*@	 @ public behavior	 @	 @ post \result == (compare(first, second) > 0);	 @*/	public boolean greater(Object first, Object second) {		return (compare(first,second) > 0);	}	/**	 * <p>Check whether or not the first object is smaller than	 * the second one.</p>	 *	 * @param first	 *        The first object	 * @param second	 *        The second object	 */ /*@	 @ public behavior	 @	 @ post \result == (compare(first, second) < 0);	 @*/	public boolean smaller(Object first, Object second) {		return (compare(first,second) < 0);	}	/**	 * <p>Check whether or not the first object is greater than	 * or equal to the second one.</p>	 *	 * @param first	 *        The first object	 * @param second	 *        The second object	 */ /*@	 @ public behavior	 @	 @ post \result == ! smaller(first, second);	 @*/	public boolean notSmaller(Object first, Object second) {		return (compare(first,second) >= 0);	}	/**	 * <p>Check whether or not the first object is smaller than	 * or equal to the second one.</p>	 *	 * @param first	 *        The first object	 * @param second	 *        The second object	 */ /*@	 @ public behavior	 @	 @ post \result == ! greater(first, second);	 @*/	public boolean notGreater(Object first, Object second) {		return (compare(first,second) <= 0);	}	/**	 * Ensure that the result is an ExtendedComparator.	 * If the given Comparator is not an ExtendedComparator, it	 * will be wrapped.	 *	 * @param comparator	 *        The comparator of which one wants an ExtendedComparator	 *        that behaves the same.	 */ /*@	 @ public behavior	 @	 @ pre comparator != null;	 @	 @ // The result must behave exactly the same as the given comparator.	 @ post (\forall Object o1; ;	 @       (\forall Object o2; ;	 @         \result.compare(o1, o2) == comparator.compare(o1, o2)));	 @*/	public static ExtendedComparator ensureExtended(Comparator comparator) {		if (comparator instanceof ExtendedComparator) {			return (ExtendedComparator) comparator;		}		else {			return new ExtendedComparatorWrapper(comparator);		}	}	/**	 * An ExtendedComparator that wraps around a normal Comparator.	 */	private static class ExtendedComparatorWrapper extends ExtendedComparator {		/**		 * Initialize a new ExtendedComparator that wraps the given comparator.		 *		 * @param comparator		 *        The Comparator to wrap.		 */	 /*@		 @ public behavior		 @		 @ pre comparator != null;		 @		 @ post getComparator() == comparator;		 @*/		public ExtendedComparatorWrapper(Comparator comparator) {			$comparator = comparator;		}		/**		 * See superclass		 */	 /*@		 @ also public behavior		 @		 @ post \result == getComparator().compare(first, second);		 @*/		public int compare(Object first, Object second) {			return $comparator.compare(first, second);		}		/**		 * Return the wrapped Comparator.		 */	 /*@		 @ public behavior		 @		 @ post \result != null;		 @*/		public Comparator getComparator() {			return $comparator;		}		/**		 * The wrapped comparator.		 */	 /*@		 @ private invariant $comparator != null;		 @*/		private final Comparator $comparator;	}}/* * <copyright>Copyright (C) 1997-2001. This software is copyrighted by  * the people and entities mentioned after the "@author" tags above, on  * behalf of the JUTIL.ORG Project. The copyright is dated by the dates  * after the "@date" tags above. All rights reserved. * This software is published under the terms of the JUTIL.ORG Software * License version 1.1 or later, a copy of which has been included with * this distribution in the LICENSE file, which can also be found at * http://org-jutil.sourceforge.net/LICENSE. This software is distributed  * WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  * See the JUTIL.ORG Software License for more details. For more information, * please see http://org-jutil.sourceforge.net/</copyright> */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -