001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.activities;
011:
012: import java.util.ArrayList;
013: import java.util.Collection;
014: import java.util.HashMap;
015: import java.util.Iterator;
016: import java.util.Map;
017:
018: import org.eclipse.ui.internal.util.Util;
019:
020: public final class ActivityPatternBindingDefinition {
021: private final static int HASH_FACTOR = 89;
022:
023: private final static int HASH_INITIAL = ActivityPatternBindingDefinition.class
024: .getName().hashCode();
025:
026: static Map activityPatternBindingDefinitionsByActivityId(
027: Collection activityPatternBindingDefinitions) {
028: if (activityPatternBindingDefinitions == null) {
029: throw new NullPointerException();
030: }
031:
032: Map map = new HashMap();
033: Iterator iterator = activityPatternBindingDefinitions
034: .iterator();
035:
036: while (iterator.hasNext()) {
037: Object object = iterator.next();
038: Util.assertInstance(object,
039: ActivityPatternBindingDefinition.class);
040: ActivityPatternBindingDefinition activityPatternBindingDefinition = (ActivityPatternBindingDefinition) object;
041: String activityId = activityPatternBindingDefinition
042: .getActivityId();
043:
044: if (activityId != null) {
045: Collection activityPatternBindingDefinitions2 = (Collection) map
046: .get(activityId);
047:
048: if (activityPatternBindingDefinitions2 == null) {
049: activityPatternBindingDefinitions2 = new ArrayList();
050: map.put(activityId,
051: activityPatternBindingDefinitions2);
052: }
053:
054: activityPatternBindingDefinitions2
055: .add(activityPatternBindingDefinition);
056: }
057: }
058:
059: return map;
060: }
061:
062: private String activityId;
063:
064: private transient int hashCode = HASH_INITIAL;
065:
066: private String pattern;
067:
068: private String sourceId;
069:
070: private transient String string;
071:
072: public ActivityPatternBindingDefinition(String activityId,
073: String pattern, String sourceId) {
074: this .activityId = activityId;
075: this .pattern = pattern;
076: this .sourceId = sourceId;
077: }
078:
079: public int compareTo(Object object) {
080: ActivityPatternBindingDefinition castedObject = (ActivityPatternBindingDefinition) object;
081: int compareTo = Util.compare(activityId,
082: castedObject.activityId);
083:
084: if (compareTo == 0) {
085: compareTo = Util.compare(pattern, castedObject.pattern);
086:
087: if (compareTo == 0) {
088: compareTo = Util.compare(sourceId,
089: castedObject.sourceId);
090: }
091: }
092:
093: return compareTo;
094: }
095:
096: public boolean equals(Object object) {
097: if (!(object instanceof ActivityPatternBindingDefinition)) {
098: return false;
099: }
100:
101: final ActivityPatternBindingDefinition castedObject = (ActivityPatternBindingDefinition) object;
102: if (!Util.equals(activityId, castedObject.activityId)) {
103: return false;
104: }
105:
106: if (!Util.equals(pattern, castedObject.pattern)) {
107: return false;
108: }
109:
110: return Util.equals(sourceId, castedObject.sourceId);
111: }
112:
113: public String getActivityId() {
114: return activityId;
115: }
116:
117: public String getPattern() {
118: return pattern;
119: }
120:
121: public String getSourceId() {
122: return sourceId;
123: }
124:
125: public int hashCode() {
126: if (hashCode == HASH_INITIAL) {
127: hashCode = hashCode * HASH_FACTOR
128: + Util.hashCode(activityId);
129: hashCode = hashCode * HASH_FACTOR + Util.hashCode(pattern);
130: hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId);
131: if (hashCode == HASH_INITIAL) {
132: hashCode++;
133: }
134: }
135:
136: return hashCode;
137: }
138:
139: public String toString() {
140: if (string == null) {
141: final StringBuffer stringBuffer = new StringBuffer();
142: stringBuffer.append('[');
143: stringBuffer.append(activityId);
144: stringBuffer.append(',');
145: stringBuffer.append(pattern);
146: stringBuffer.append(',');
147: stringBuffer.append(sourceId);
148: stringBuffer.append(']');
149: string = stringBuffer.toString();
150: }
151:
152: return string;
153: }
154: }
|