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

📄 datecomparator.java

📁 java阿里巴巴代码
💻 JAVA
字号:
/**
 * DateComparator.java
 * 
 * This class is used along with TreeMap
 * When put a key into a TreeMap, TreeMap will replace the old having the same key with the new 
 * but when you use this class, you can control this case
 * though the key is the same, the Comparator will return false if you set the flag 'takeEqual=true'
 */

package tools.util;

import java.util.Comparator;

public class DateComparator implements Comparator
{
	private int takeEqual = 0;
	private boolean desc	= false;
	
	/**
	 * DateComparator, Constructor
	/ * @param boolean takeEqual, if true, return 1 when equal,
	 */
	public DateComparator(boolean takeEqual)
	{
		this.takeEqual = (takeEqual==true) ? 1 : 0;
	}

	/**
	 * DateComparator, Constructor
	/ * @param boolean takeEqual, if true, return 1 when equal,
	/ * @param boolean desc
	 */
	public DateComparator(boolean takeEqual, boolean desc)
	{
		this.takeEqual = (takeEqual==true) ? 1 : 0;
		this.desc		= desc;
	}

	/**
	 * compare, compare 2 objects
	 /* @param Object o1
	 /* @param Object o2
	 * @return int, 1 ==> o1 > o2, -1 ==> o1 < o2, 0 ==> o1 = o2
	 */
	public int compare(Object o1, Object o2)
	{
		java.util.Date date1 = (java.util.Date)o1;
		java.util.Date date2 = (java.util.Date)o2;

		if (!desc)		// ASC
		{
			if(date1.before(date2)) return -1;
			if(date1.after(date2)) return 1;
		}
		else			// DESC
		{
			if(date1.before(date2)) return 1;
			if(date1.after(date2)) return -1;
		}

		return takeEqual;
	}
	public boolean equals(Object obj)
	{
		return false;
	}


}

⌨️ 快捷键说明

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