1 11 12 package org.eclipse.ui.internal.activities; 13 14 import org.eclipse.ui.activities.IActivityRequirementBinding; 15 import org.eclipse.ui.internal.util.Util; 16 17 public final class ActivityRequirementBinding implements 18 IActivityRequirementBinding { 19 private final static int HASH_FACTOR = 89; 20 21 private final static int HASH_INITIAL = ActivityRequirementBinding.class 22 .getName().hashCode(); 23 24 private String requiredActivityId; 25 26 private transient int hashCode = HASH_INITIAL; 27 28 private String activityId; 29 30 private transient String string; 31 32 public ActivityRequirementBinding(String requiredActivityId, 33 String activityId) { 34 if (requiredActivityId == null || activityId == null) { 35 throw new NullPointerException (); 36 } 37 38 this.requiredActivityId = requiredActivityId; 39 this.activityId = activityId; 40 } 41 42 public int compareTo(Object object) { 43 ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object; 44 int compareTo = Util.compare(requiredActivityId, 45 castedObject.requiredActivityId); 46 47 if (compareTo == 0) { 48 compareTo = Util.compare(activityId, castedObject.activityId); 49 } 50 51 return compareTo; 52 } 53 54 public boolean equals(Object object) { 55 if (!(object instanceof ActivityRequirementBinding)) { 56 return false; 57 } 58 59 final ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object; 60 if (!Util.equals(requiredActivityId, castedObject.requiredActivityId)) { 61 return false; 62 } 63 64 return Util.equals(activityId, castedObject.activityId); 65 } 66 67 public String getRequiredActivityId() { 68 return requiredActivityId; 69 } 70 71 public String getActivityId() { 72 return activityId; 73 } 74 75 public int hashCode() { 76 if (hashCode == HASH_INITIAL) { 77 hashCode = hashCode * HASH_FACTOR 78 + Util.hashCode(requiredActivityId); 79 hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); 80 if (hashCode == HASH_INITIAL) { 81 hashCode++; 82 } 83 } 84 85 return hashCode; 86 } 87 88 public String toString() { 89 if (string == null) { 90 final StringBuffer stringBuffer = new StringBuffer (); 91 stringBuffer.append('['); 92 stringBuffer.append(requiredActivityId); 93 stringBuffer.append(','); 94 stringBuffer.append(activityId); 95 stringBuffer.append(']'); 96 string = stringBuffer.toString(); 97 } 98 99 return string; 100 } 101 } 102 | Popular Tags |