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