KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > commands > Match


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.commands;
13
14 import org.eclipse.ui.internal.util.Util;
15
16 public final class Match {
17
18     private final static int HASH_FACTOR = 89;
19     private final static int HASH_INITIAL = Match.class.getName().hashCode();
20
21     private String JavaDoc commandId;
22
23     private transient int hashCode;
24     private transient boolean hashCodeComputed;
25     private transient String JavaDoc string;
26     private int value;
27
28     Match(String JavaDoc commandId, int value) {
29         if (value < 0)
30             throw new IllegalArgumentException JavaDoc();
31
32         this.commandId = commandId;
33         this.value = value;
34     }
35
36     public int compareTo(Object JavaDoc object) {
37         Match castedObject = (Match) object;
38         int compareTo = Util.compare(value, castedObject.value);
39
40         if (compareTo == 0)
41             compareTo = Util.compare(commandId, castedObject.commandId);
42
43         return compareTo;
44     }
45
46     public boolean equals(Object JavaDoc object) {
47         if (!(object instanceof Match))
48             return false;
49
50         Match castedObject = (Match) object;
51         boolean equals = true;
52         equals &= Util.equals(commandId, castedObject.commandId);
53         equals &= Util.equals(value, castedObject.value);
54         return equals;
55     }
56
57     public String JavaDoc getCommandId() {
58         return commandId;
59     }
60
61     public int getValue() {
62         return value;
63     }
64
65     public int hashCode() {
66         if (!hashCodeComputed) {
67             hashCode = HASH_INITIAL;
68             hashCode = hashCode * HASH_FACTOR + Util.hashCode(commandId);
69             hashCode = hashCode * HASH_FACTOR + Util.hashCode(value);
70             hashCodeComputed = true;
71         }
72
73         return hashCode;
74     }
75
76     public String JavaDoc toString() {
77         if (string == null) {
78             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
79             stringBuffer.append('[');
80             stringBuffer.append(commandId);
81             stringBuffer.append(',');
82             stringBuffer.append(value);
83             stringBuffer.append(']');
84             string = stringBuffer.toString();
85         }
86
87         return string;
88     }
89 }
90
Popular Tags