KickJava   Java API By Example, From Geeks To Geeks.

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


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