KickJava   Java API By Example, From Geeks To Geeks.

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


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 ActiveKeyConfigurationDefinition
17     implements Comparable JavaDoc {
18
19     private final static int HASH_FACTOR = 89;
20     private final static int HASH_INITIAL =
21         ActiveKeyConfigurationDefinition.class.getName().hashCode();
22
23     private transient int hashCode;
24     private transient boolean hashCodeComputed;
25
26     private String JavaDoc keyConfigurationId;
27     private String JavaDoc sourceId;
28     private transient String JavaDoc string;
29
30     public ActiveKeyConfigurationDefinition(
31         String JavaDoc keyConfigurationId,
32         String JavaDoc sourceId) {
33         this.keyConfigurationId = keyConfigurationId;
34         this.sourceId = sourceId;
35     }
36
37     public int compareTo(Object JavaDoc object) {
38         ActiveKeyConfigurationDefinition castedObject =
39             (ActiveKeyConfigurationDefinition) object;
40         int compareTo =
41             Util.compare(keyConfigurationId, castedObject.keyConfigurationId);
42
43         if (compareTo == 0)
44             compareTo = Util.compare(sourceId, castedObject.sourceId);
45
46         return compareTo;
47     }
48
49     public boolean equals(Object JavaDoc object) {
50         if (!(object instanceof ActiveKeyConfigurationDefinition))
51             return false;
52
53         ActiveKeyConfigurationDefinition castedObject =
54             (ActiveKeyConfigurationDefinition) object;
55         boolean equals = true;
56         equals
57             &= Util.equals(keyConfigurationId, castedObject.keyConfigurationId);
58         equals &= Util.equals(sourceId, castedObject.sourceId);
59         return equals;
60     }
61
62     public String JavaDoc getKeyConfigurationId() {
63         return keyConfigurationId;
64     }
65
66     public String JavaDoc getSourceId() {
67         return sourceId;
68     }
69
70     public int hashCode() {
71         if (!hashCodeComputed) {
72             hashCode = HASH_INITIAL;
73             hashCode =
74                 hashCode * HASH_FACTOR + Util.hashCode(keyConfigurationId);
75             hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId);
76             hashCodeComputed = true;
77         }
78
79         return hashCode;
80     }
81
82     public String JavaDoc toString() {
83         if (string == null) {
84             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
85             stringBuffer.append('[');
86             stringBuffer.append(keyConfigurationId);
87             stringBuffer.append(',');
88             stringBuffer.append(sourceId);
89             stringBuffer.append(']');
90             string = stringBuffer.toString();
91         }
92
93         return string;
94     }
95 }
96
Popular Tags