1 11 package org.eclipse.core.internal.dtree; 12 13 import org.eclipse.core.internal.utils.Messages; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.core.runtime.Path; 16 import org.eclipse.osgi.util.NLS; 17 18 38 39 public abstract class AbstractDataTree { 40 41 44 private boolean immutable = false; 45 46 49 protected static final IPath[] NO_CHILDREN = new IPath[0]; 50 51 54 public AbstractDataTree() { 55 this.empty(); 56 } 57 58 62 protected AbstractDataTree copy() { 63 AbstractDataTree newTree = this.createInstance(); 64 newTree.setImmutable(this.isImmutable()); 65 newTree.setRootNode(this.getRootNode()); 66 return newTree; 67 } 68 69 73 public abstract AbstractDataTreeNode copyCompleteSubtree(IPath key); 74 75 86 public abstract void createChild(IPath parentKey, String localName); 87 88 100 public abstract void createChild(IPath parentKey, String localName, Object object); 101 102 109 protected abstract AbstractDataTree createInstance(); 110 111 118 public abstract void createSubtree(IPath key, AbstractDataTreeNode subtree); 119 120 133 public abstract void deleteChild(IPath parentKey, String localName); 134 135 140 public abstract void empty(); 141 142 154 public IPath getChild(IPath parentKey, int index) { 155 156 String child = getNameOfChild(parentKey, index); 157 return parentKey.append(child); 158 } 159 160 168 public int getChildCount(IPath parentKey) { 169 return getNamesOfChildren(parentKey).length; 170 } 171 172 180 public IPath[] getChildren(IPath parentKey) { 181 String names[] = getNamesOfChildren(parentKey); 182 int len = names.length; 183 if (len == 0) 184 return NO_CHILDREN; 185 IPath answer[] = new IPath[len]; 186 187 for (int i = 0; i < len; i++) { 188 answer[i] = parentKey.append(names[i]); 189 } 190 return answer; 191 } 192 193 201 public abstract Object getData(IPath key); 202 203 215 public String getNameOfChild(IPath parentKey, int index) { 216 String childNames[] = getNamesOfChildren(parentKey); 217 218 return childNames[index]; 219 } 220 221 229 public abstract String [] getNamesOfChildren(IPath parentKey); 230 231 238 AbstractDataTreeNode getRootNode() { 239 throw new AbstractMethodError (Messages.dtree_subclassImplement); 240 } 241 242 247 static void handleImmutableTree() { 248 throw new RuntimeException (Messages.dtree_immutable); 249 } 250 251 256 static void handleNotFound(IPath key) { 257 throw new ObjectNotFoundException(NLS.bind(Messages.dtree_notFound, key)); 258 } 259 260 263 public void immutable() { 264 immutable = true; 265 } 266 267 274 public abstract boolean includes(IPath key); 275 276 279 public boolean isImmutable() { 280 return immutable; 281 } 282 283 290 public abstract DataTreeLookup lookup(IPath key); 291 292 295 public IPath rootKey() { 296 return Path.ROOT; 297 } 298 299 311 public abstract void setData(IPath key, Object data); 312 313 316 void setImmutable(boolean bool) { 317 immutable = bool; 318 } 319 320 327 void setRootNode(AbstractDataTreeNode node) { 328 throw new Error (Messages.dtree_subclassImplement); 329 } 330 } 331 | Popular Tags |