identitycomparator.java
来自「非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应」· Java 代码 · 共 54 行
JAVA
54 行
/* IdentityComparator.java{{IS_NOTE Purpose: The comparator uses == and System.identifyHashCode to do the comparison. Description: History: Fri Sep 13 10:14:11 2002, Created by tomyeh}}IS_NOTECopyright (C) 2002 Potix Corporation. All Rights Reserved.{{IS_RIGHT This program is distributed under GPL Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.util;import java.util.Comparator;/** * The comparator uses == and System.identifyHashCode to compare two objects. * It assumes if o1 != o2, then c1 != c2 where c1 = System.identityHashCode(o1). * * <p>This is useful if dynamic proxy is used with TreeSet or TreeMap * (so equals is expensive). * Reason: the speed of identifyHashCode is much faster than dynamic proxy * (150:1). * * <p>However, if possible, java.util.IdentityHashMap and {@link IdentityHashSet} * are preferred. * * @author tomyeh * @see IdentityHashSet */public class IdentityComparator implements Comparator { public IdentityComparator() { } //-- Comparator --// public int compare(Object o1, Object o2) { if (o1 == o2) return 0; int c1 = System.identityHashCode(o1); int c2 = System.identityHashCode(o2); assert c1 != c2; //if o1 != o2, c1 != c2 return c1 > c2 ? 1: -1; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?