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