KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dtree > DeletedNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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.osgi.util.NLS;
16
17 /**
18  * A <code>DeletedNode</code> represents a node that has been deleted in a
19  * <code>DeltaDataTree</code>. It is a node that existed in the parent tree,
20  * but no longer exists in the current delta tree. It has no children or data.
21  */

22 public class DeletedNode extends AbstractDataTreeNode {
23
24     /**
25      * Creates a new tree with the given name
26      */

27     DeletedNode(String JavaDoc localName) {
28         super(localName, NO_CHILDREN);
29     }
30
31     /**
32      * @see AbstractDataTreeNode#asBackwardDelta(DeltaDataTree, DeltaDataTree, IPath)
33      */

34     AbstractDataTreeNode asBackwardDelta(DeltaDataTree myTree, DeltaDataTree parentTree, IPath key) {
35         if (parentTree.includes(key))
36             return parentTree.copyCompleteSubtree(key);
37         return this;
38     }
39
40     /**
41      * Returns the child with the given local name
42      */

43     AbstractDataTreeNode childAt(String JavaDoc localName) {
44         /* deleted nodes do not have children */
45         throw new ObjectNotFoundException(NLS.bind(Messages.dtree_missingChild, localName));
46     }
47
48     /**
49      * Returns the child with the given local name
50      */

51     AbstractDataTreeNode childAtOrNull(String JavaDoc localName) {
52         /* deleted nodes do not have children */
53         return null;
54     }
55
56     AbstractDataTreeNode compareWithParent(IPath key, DeltaDataTree parent, IComparator comparator) {
57         /**
58          * Just because there is a deleted node, it doesn't mean there must
59          * be a corresponding node in the parent. Deleted nodes can live
60          * in isolation.
61          */

62         if (parent.includes(key))
63             return convertToRemovedComparisonNode(parent.copyCompleteSubtree(key), NodeComparison.K_REMOVED);
64         // Node doesn't exist in either tree. Return an empty comparison.
65
// Empty comparisons are omitted from the delta.
66
return new DataTreeNode(key.lastSegment(), new NodeComparison(null, null, 0, 0));
67     }
68
69     /**
70      * Creates and returns a new copy of the receiver. Makes a deep copy of
71      * children, but a shallow copy of name and data.
72      */

73     AbstractDataTreeNode copy() {
74         return new DeletedNode(name);
75     }
76
77     /**
78      * Returns true if the receiver represents a deleted node, false otherwise.
79      */

80     boolean isDeleted() {
81         return true;
82     }
83
84     /**
85      * Simplifies the given node, and returns its replacement.
86      */

87     AbstractDataTreeNode simplifyWithParent(IPath key, DeltaDataTree parent, IComparator comparer) {
88         if (parent.includes(key))
89             return this;
90         return new NoDataDeltaNode(name);
91     }
92
93     /**
94      * Returns the number of children of the receiver
95      */

96     int size() {
97         /* deleted nodes have no children */
98         return 0;
99     }
100
101     /**
102      * Return a unicode representation of the node. This method
103      * is used for debugging purposes only (no NLS please)
104      */

105     public String JavaDoc toString() {
106         return "a DeletedNode(" + this.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
107
}
108
109     /**
110      * Returns a string describing the type of node.
111      */

112     int type() {
113         return T_DELETED_NODE;
114     }
115
116     AbstractDataTreeNode childAtIgnoreCase(String JavaDoc localName) {
117         /* deleted nodes do not have children */
118         return null;
119     }
120 }
121
Popular Tags