1 11 package org.eclipse.core.commands.common; 12 13 import org.eclipse.core.internal.commands.util.Util; 14 15 39 public abstract class HandleObject extends EventManager implements 40 IIdentifiable { 41 42 46 private static final int HASH_CODE_NOT_COMPUTED = -1; 47 48 51 private static final int HASH_FACTOR = 89; 52 53 56 private static final int HASH_INITIAL = HandleObject.class.getName() 57 .hashCode(); 58 59 63 protected transient boolean defined = false; 64 65 69 private transient int hashCode = HASH_CODE_NOT_COMPUTED; 70 71 76 protected final String id; 77 78 84 protected transient String string = null; 85 86 92 protected HandleObject(final String id) { 93 if (id == null) { 94 throw new NullPointerException ( 95 "Cannot create a handle with a null id"); } 97 98 this.id = id; 99 } 100 101 110 public boolean equals(final Object object) { 111 if (object == this) { 113 return true; 114 } 115 116 if (!(object instanceof HandleObject)) { 118 return false; 119 } 120 121 final HandleObject handle= (HandleObject) object; 123 return Util.equals(id, handle.id) 124 && (this.getClass() == handle.getClass()); 125 } 126 127 public final String getId() { 128 return id; 129 } 130 131 136 public final int hashCode() { 137 if (hashCode == HASH_CODE_NOT_COMPUTED) { 138 hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(id); 139 if (hashCode == HASH_CODE_NOT_COMPUTED) { 140 hashCode++; 141 } 142 } 143 return hashCode; 144 } 145 146 154 public final boolean isDefined() { 155 return defined; 156 } 157 158 164 public abstract String toString(); 165 166 171 public abstract void undefine(); 172 } 173 | Popular Tags |