1 11 12 package org.eclipse.ui.internal.activities; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.Map ; 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 activityPatternBindingDefinitionsByActivityId( 29 Collection activityPatternBindingDefinitions) { 30 if (activityPatternBindingDefinitions == null) { 31 throw new NullPointerException (); 32 } 33 34 Map map = new HashMap (); 35 Iterator iterator = activityPatternBindingDefinitions.iterator(); 36 37 while (iterator.hasNext()) { 38 Object object = iterator.next(); 39 Util.assertInstance(object, ActivityPatternBindingDefinition.class); 40 ActivityPatternBindingDefinition activityPatternBindingDefinition = (ActivityPatternBindingDefinition) object; 41 String activityId = activityPatternBindingDefinition 42 .getActivityId(); 43 44 if (activityId != null) { 45 Collection activityPatternBindingDefinitions2 = (Collection ) map 46 .get(activityId); 47 48 if (activityPatternBindingDefinitions2 == null) { 49 activityPatternBindingDefinitions2 = new ArrayList (); 50 map.put(activityId, activityPatternBindingDefinitions2); 51 } 52 53 activityPatternBindingDefinitions2 54 .add(activityPatternBindingDefinition); 55 } 56 } 57 58 return map; 59 } 60 61 private String activityId; 62 63 private transient int hashCode = HASH_INITIAL; 64 65 private String pattern; 66 67 private String sourceId; 68 69 private transient String string; 70 71 public ActivityPatternBindingDefinition(String activityId, String pattern, 72 String sourceId) { 73 this.activityId = activityId; 74 this.pattern = pattern; 75 this.sourceId = sourceId; 76 } 77 78 public int compareTo(Object 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 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 getActivityId() { 111 return activityId; 112 } 113 114 public String getPattern() { 115 return pattern; 116 } 117 118 public String 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 toString() { 136 if (string == null) { 137 final StringBuffer stringBuffer = new StringBuffer (); 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 |