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