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