KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > activities > CategoryActivityBinding


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

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