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