KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > util > lookup > ALPairComparator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.util.lookup;
20
21 import java.util.Comparator JavaDoc;
22 import org.openide.util.lookup.AbstractLookup.Pair;
23
24
25 /** Implementation of comparator for AbstractLookup.Pair
26  *
27  * @author Jaroslav Tulach
28  */

29 final class ALPairComparator implements Comparator JavaDoc<Pair<?>> {
30     public static final Comparator JavaDoc<Pair<?>> DEFAULT = new ALPairComparator();
31
32     /** Creates a new instance of ALPairComparator */
33     private ALPairComparator() {
34     }
35
36     /** Compares two items.
37     */

38     public int compare(Pair<?> i1, Pair<?> i2) {
39         int result = i1.getIndex() - i2.getIndex();
40
41         if (result == 0) {
42             if (i1 != i2) {
43                 java.io.ByteArrayOutputStream JavaDoc bs = new java.io.ByteArrayOutputStream JavaDoc();
44                 java.io.PrintStream JavaDoc ps = new java.io.PrintStream JavaDoc(bs);
45
46                 ps.println(
47                     "Duplicate pair in tree" + // NOI18N
48
"Pair1: " + i1 + " pair2: " + i2 + " index1: " + i1.getIndex() + " index2: " +
49                     i2.getIndex() // NOI18N
50
+" item1: " + i1.getInstance() + " item2: " + i2.getInstance() // NOI18N
51
+" id1: " + Integer.toHexString(System.identityHashCode(i1)) // NOI18N
52
+" id2: " + Integer.toHexString(System.identityHashCode(i2)) // NOI18N
53
);
54
55                 // print (ps, false);
56
ps.close();
57
58                 throw new IllegalStateException JavaDoc(bs.toString());
59             }
60
61             return 0;
62         }
63
64         return result;
65     }
66 }
67
Popular Tags