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