1 11 12 package org.eclipse.ui.internal.commands; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 20 import org.eclipse.ui.internal.util.Util; 21 import org.eclipse.ui.keys.KeySequence; 22 23 public final class KeySequenceBindingDefinition 24 implements Comparable { 25 26 private final static int HASH_FACTOR = 89; 27 private final static int HASH_INITIAL = 28 KeySequenceBindingDefinition.class.getName().hashCode(); 29 30 static Map keySequenceBindingDefinitionsByCommandId(Collection keySequenceBindingDefinitions) { 31 if (keySequenceBindingDefinitions == null) 32 throw new NullPointerException (); 33 34 Map map = new HashMap (); 35 Iterator iterator = keySequenceBindingDefinitions.iterator(); 36 37 while (iterator.hasNext()) { 38 Object object = iterator.next(); 39 Util.assertInstance(object, KeySequenceBindingDefinition.class); 40 KeySequenceBindingDefinition keySequenceBindingDefinition = 41 (KeySequenceBindingDefinition) object; 42 String commandId = keySequenceBindingDefinition.getCommandId(); 43 44 if (commandId != null) { 45 Collection keySequenceBindingDefinitions2 = 46 (Collection ) map.get(commandId); 47 48 if (keySequenceBindingDefinitions2 == null) { 49 keySequenceBindingDefinitions2 = new ArrayList (); 50 map.put(commandId, keySequenceBindingDefinitions2); 51 } 52 53 keySequenceBindingDefinitions2.add( 54 keySequenceBindingDefinition); 55 } 56 } 57 58 return map; 59 } 60 61 private String contextId; 62 private String commandId; 63 64 private transient int hashCode; 65 private transient boolean hashCodeComputed; 66 private String keyConfigurationId; 67 private KeySequence keySequence; 68 private String locale; 69 private String platform; 70 private String sourceId; 71 private transient String string; 72 73 public KeySequenceBindingDefinition( 74 String contextId, 75 String commandId, 76 String keyConfigurationId, 77 KeySequence keySequence, 78 String locale, 79 String platform, 80 String sourceId) { 81 this.contextId = contextId; 82 this.commandId = commandId; 83 this.keyConfigurationId = keyConfigurationId; 84 this.keySequence = keySequence; 85 this.locale = locale; 86 this.platform = platform; 87 this.sourceId = sourceId; 88 } 89 90 public int compareTo(Object object) { 91 KeySequenceBindingDefinition castedObject = 92 (KeySequenceBindingDefinition) object; 93 int compareTo = Util.compare(contextId, castedObject.contextId); 94 95 if (compareTo == 0) { 96 compareTo = Util.compare(commandId, castedObject.commandId); 97 98 if (compareTo == 0) { 99 compareTo = 100 Util.compare( 101 keyConfigurationId, 102 castedObject.keyConfigurationId); 103 104 if (compareTo == 0) { 105 compareTo = 106 Util.compare(keySequence, castedObject.keySequence); 107 108 if (compareTo == 0) { 109 compareTo = Util.compare(locale, castedObject.locale); 110 111 if (compareTo == 0) { 112 compareTo = 113 Util.compare(platform, castedObject.platform); 114 115 if (compareTo == 0) 116 compareTo = 117 Util.compare( 118 sourceId, 119 castedObject.sourceId); 120 } 121 } 122 } 123 } 124 } 125 126 return compareTo; 127 } 128 129 public boolean equals(Object object) { 130 if (!(object instanceof KeySequenceBindingDefinition)) 131 return false; 132 133 KeySequenceBindingDefinition castedObject = 134 (KeySequenceBindingDefinition) object; 135 boolean equals = true; 136 equals &= Util.equals(contextId, castedObject.contextId); 137 equals &= Util.equals(commandId, castedObject.commandId); 138 equals 139 &= Util.equals(keyConfigurationId, castedObject.keyConfigurationId); 140 equals &= Util.equals(keySequence, castedObject.keySequence); 141 equals &= Util.equals(locale, castedObject.locale); 142 equals &= Util.equals(platform, castedObject.platform); 143 equals &= Util.equals(sourceId, castedObject.sourceId); 144 return equals; 145 } 146 147 public String getContextId() { 148 return contextId; 149 } 150 151 public String getCommandId() { 152 return commandId; 153 } 154 155 public String getKeyConfigurationId() { 156 return keyConfigurationId; 157 } 158 159 public KeySequence getKeySequence() { 160 return keySequence; 161 } 162 163 public String getLocale() { 164 return locale; 165 } 166 167 public String getPlatform() { 168 return platform; 169 } 170 171 public String getSourceId() { 172 return sourceId; 173 } 174 175 public int hashCode() { 176 if (!hashCodeComputed) { 177 hashCode = HASH_INITIAL; 178 hashCode = hashCode * HASH_FACTOR + Util.hashCode(contextId); 179 hashCode = hashCode * HASH_FACTOR + Util.hashCode(commandId); 180 hashCode = 181 hashCode * HASH_FACTOR + Util.hashCode(keyConfigurationId); 182 hashCode = hashCode * HASH_FACTOR + Util.hashCode(keySequence); 183 hashCode = hashCode * HASH_FACTOR + Util.hashCode(locale); 184 hashCode = hashCode * HASH_FACTOR + Util.hashCode(platform); 185 hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId); 186 hashCodeComputed = true; 187 } 188 189 return hashCode; 190 } 191 192 public String toString() { 193 if (string == null) { 194 final StringBuffer stringBuffer = new StringBuffer (); 195 stringBuffer.append('['); 196 stringBuffer.append(contextId); 197 stringBuffer.append(','); 198 stringBuffer.append(commandId); 199 stringBuffer.append(','); 200 stringBuffer.append(keyConfigurationId); 201 stringBuffer.append(','); 202 stringBuffer.append(keySequence); 203 stringBuffer.append(','); 204 stringBuffer.append(locale); 205 stringBuffer.append(','); 206 stringBuffer.append(platform); 207 stringBuffer.append(','); 208 stringBuffer.append(sourceId); 209 stringBuffer.append(']'); 210 string = stringBuffer.toString(); 211 } 212 213 return string; 214 } 215 } 216 | Popular Tags |