KickJava   Java API By Example, From Geeks To Geeks.

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


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