KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Collection JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.eclipse.ui.internal.util.Util;
21
22 public final class CategoryActivityBindingDefinition {
23     private final static int HASH_FACTOR = 89;
24
25     private final static int HASH_INITIAL = CategoryActivityBindingDefinition.class
26             .getName().hashCode();
27
28     static Map JavaDoc categoryActivityBindingDefinitionsByCategoryId(
29             Collection JavaDoc categoryActivityBindingDefinitions) {
30         if (categoryActivityBindingDefinitions == null) {
31             throw new NullPointerException JavaDoc();
32         }
33
34         Map JavaDoc map = new HashMap JavaDoc();
35         Iterator JavaDoc iterator = categoryActivityBindingDefinitions.iterator();
36
37         while (iterator.hasNext()) {
38             Object JavaDoc object = iterator.next();
39             Util
40                     .assertInstance(object,
41                             CategoryActivityBindingDefinition.class);
42             CategoryActivityBindingDefinition categoryActivityBindingDefinition = (CategoryActivityBindingDefinition) object;
43             String JavaDoc categoryId = categoryActivityBindingDefinition
44                     .getCategoryId();
45
46             if (categoryId != null) {
47                 Collection JavaDoc categoryActivityBindingDefinitions2 = (Collection JavaDoc) map
48                         .get(categoryId);
49
50                 if (categoryActivityBindingDefinitions2 == null) {
51                     categoryActivityBindingDefinitions2 = new HashSet JavaDoc();
52                     map.put(categoryId, categoryActivityBindingDefinitions2);
53                 }
54
55                 categoryActivityBindingDefinitions2
56                         .add(categoryActivityBindingDefinition);
57             }
58         }
59
60         return map;
61     }
62
63     private String JavaDoc activityId;
64
65     private String JavaDoc categoryId;
66
67     private transient int hashCode = HASH_INITIAL;
68
69     private String JavaDoc sourceId;
70
71     private transient String JavaDoc string;
72
73     public CategoryActivityBindingDefinition(String JavaDoc activityId,
74             String JavaDoc categoryId, String JavaDoc sourceId) {
75         this.activityId = activityId;
76         this.categoryId = categoryId;
77         this.sourceId = sourceId;
78     }
79
80     public int compareTo(Object JavaDoc object) {
81         CategoryActivityBindingDefinition castedObject = (CategoryActivityBindingDefinition) object;
82         int compareTo = Util.compare(activityId, castedObject.activityId);
83
84         if (compareTo == 0) {
85             compareTo = Util.compare(categoryId, castedObject.categoryId);
86
87             if (compareTo == 0) {
88                 compareTo = Util.compare(sourceId, castedObject.sourceId);
89             }
90         }
91
92         return compareTo;
93     }
94
95     public boolean equals(Object JavaDoc object) {
96         if (!(object instanceof CategoryActivityBindingDefinition)) {
97             return false;
98         }
99
100         final CategoryActivityBindingDefinition castedObject = (CategoryActivityBindingDefinition) object;
101         if (!Util.equals(activityId, castedObject.activityId)) {
102             return false;
103         }
104
105         if (!Util.equals(categoryId, castedObject.categoryId)) {
106             return false;
107         }
108
109         return Util.equals(sourceId, castedObject.sourceId);
110     }
111
112     public String JavaDoc getActivityId() {
113         return activityId;
114     }
115
116     public String JavaDoc getCategoryId() {
117         return categoryId;
118     }
119
120     public String JavaDoc getSourceId() {
121         return sourceId;
122     }
123
124     public int hashCode() {
125         if (hashCode == HASH_INITIAL) {
126             hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId);
127             hashCode = hashCode * HASH_FACTOR + Util.hashCode(categoryId);
128             hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId);
129             if (hashCode == HASH_INITIAL) {
130                 hashCode++;
131             }
132         }
133
134         return hashCode;
135     }
136
137     public String JavaDoc toString() {
138         if (string == null) {
139             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
140             stringBuffer.append('[');
141             stringBuffer.append(activityId);
142             stringBuffer.append(',');
143             stringBuffer.append(categoryId);
144             stringBuffer.append(',');
145             stringBuffer.append(sourceId);
146             stringBuffer.append(']');
147             string = stringBuffer.toString();
148         }
149
150         return string;
151     }
152 }
153
Popular Tags