1 11 package org.eclipse.jface.bindings; 12 13 import java.util.Map ; 14 15 import org.eclipse.jface.util.Util; 16 17 27 final class CachedBindingSet { 28 29 32 private final static int HASH_FACTOR = 89; 33 34 37 private final static int HASH_INITIAL = CachedBindingSet.class.getName() 38 .hashCode(); 39 40 56 private final Map activeContextTree; 57 58 63 private Map bindingsByTrigger = null; 64 65 71 private Map conflictsByTrigger = null; 72 73 77 private transient int hashCode; 78 79 82 private transient boolean hashCodeComputed = false; 83 84 97 private final String [] locales; 98 99 112 private final String [] platforms; 113 114 121 private Map prefixTable = null; 122 123 136 private final String [] schemeIds; 137 138 144 private Map triggersByCommandId = null; 145 146 176 CachedBindingSet(final Map activeContextTree, final String [] locales, 177 final String [] platforms, final String [] schemeIds) { 178 if (locales == null) { 179 throw new NullPointerException ("The locales cannot be null."); } 181 182 if (locales.length == 0) { 183 throw new NullPointerException ("The locales cannot be empty."); } 185 186 if (platforms == null) { 187 throw new NullPointerException ("The platforms cannot be null."); } 189 190 if (platforms.length == 0) { 191 throw new NullPointerException ("The platforms cannot be empty."); } 193 194 this.activeContextTree = activeContextTree; 195 this.locales = locales; 196 this.platforms = platforms; 197 this.schemeIds = schemeIds; 198 } 199 200 211 public final boolean equals(final Object object) { 212 if (!(object instanceof CachedBindingSet)) { 213 return false; 214 } 215 216 final CachedBindingSet other = (CachedBindingSet) object; 217 218 if (!Util.equals(activeContextTree, other.activeContextTree)) { 219 return false; 220 } 221 if (!Util.equals(locales, other.locales)) { 222 return false; 223 } 224 if (!Util.equals(platforms, other.platforms)) { 225 return false; 226 } 227 return Util.equals(schemeIds, other.schemeIds); 228 } 229 230 237 final Map getBindingsByTrigger() { 238 return bindingsByTrigger; 239 } 240 241 248 final Map getConflictsByTrigger() { 249 return conflictsByTrigger; 250 } 251 252 263 final Map getPrefixTable() { 264 return prefixTable; 265 } 266 267 275 final Map getTriggersByCommandId() { 276 return triggersByCommandId; 277 } 278 279 287 public final int hashCode() { 288 if (!hashCodeComputed) { 289 hashCode = HASH_INITIAL; 290 hashCode = hashCode * HASH_FACTOR 291 + Util.hashCode(activeContextTree); 292 hashCode = hashCode * HASH_FACTOR + Util.hashCode(locales); 293 hashCode = hashCode * HASH_FACTOR + Util.hashCode(platforms); 294 hashCode = hashCode * HASH_FACTOR + Util.hashCode(schemeIds); 295 hashCodeComputed = true; 296 } 297 298 return hashCode; 299 } 300 301 308 final void setBindingsByTrigger(final Map commandIdsByTrigger) { 309 if (commandIdsByTrigger == null) { 310 throw new NullPointerException ( 311 "Cannot set a null binding resolution"); } 313 314 this.bindingsByTrigger = commandIdsByTrigger; 315 } 316 317 324 final void setConflictsByTrigger(final Map conflicts) { 325 if (conflicts == null) { 326 throw new NullPointerException ( 327 "Cannot set a null binding conflicts"); } 329 conflictsByTrigger = conflicts; 330 } 331 332 344 final void setPrefixTable(final Map prefixTable) { 345 if (prefixTable == null) { 346 throw new NullPointerException ("Cannot set a null prefix table"); } 348 349 this.prefixTable = prefixTable; 350 } 351 352 361 final void setTriggersByCommandId(final Map triggersByCommandId) { 362 if (triggersByCommandId == null) { 363 throw new NullPointerException ( 364 "Cannot set a null binding resolution"); } 366 367 this.triggersByCommandId = triggersByCommandId; 368 } 369 } 370 | Popular Tags |