KickJava   Java API By Example, From Geeks To Geeks.

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


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.runtime.IPath;
14
15 /**
16  * A <code>NoDataDeltaNode</code>is a node in a delta tree whose subtree contains
17  * differences since the delta's parent. Refer to the <code>DeltaDataTree</code>
18  * API and class comment for details.
19  *
20  * @see DeltaDataTree
21  */

22 public class NoDataDeltaNode extends AbstractDataTreeNode {
23     /**
24      * Creates a new empty delta.
25      */

26     public NoDataDeltaNode(String JavaDoc name) {
27         this(name, NO_CHILDREN);
28     }
29
30     /**
31      * Creates a new data tree node
32      *
33      * @param name name of new node
34      * @param children children of the new node
35      */

36     public NoDataDeltaNode(String JavaDoc name, AbstractDataTreeNode[] children) {
37         super(name, children);
38     }
39
40     /**
41      * Creates a new data tree node
42      *
43      * @param localName name of new node
44      * @param childNode single child for new node
45      */

46     NoDataDeltaNode(String JavaDoc localName, AbstractDataTreeNode childNode) {
47         super(localName, new AbstractDataTreeNode[] {childNode});
48     }
49
50     /**
51      * @see AbstractDataTreeNode#asBackwardDelta(DeltaDataTree, DeltaDataTree, IPath)
52      */

53     AbstractDataTreeNode asBackwardDelta(DeltaDataTree myTree, DeltaDataTree parentTree, IPath key) {
54         int numChildren = children.length;
55         if (numChildren == 0)
56             return new NoDataDeltaNode(name, NO_CHILDREN);
57         AbstractDataTreeNode[] newChildren = new AbstractDataTreeNode[numChildren];
58         for (int i = numChildren; --i >= 0;) {
59             newChildren[i] = children[i].asBackwardDelta(myTree, parentTree, key.append(children[i].getName()));
60         }
61         return new NoDataDeltaNode(name, newChildren);
62     }
63
64     /**
65      * @see AbstractDataTreeNode#compareWithParent(IPath, DeltaDataTree, IComparator)
66      */

67     AbstractDataTreeNode compareWithParent(IPath key, DeltaDataTree parent, IComparator comparator) {
68         AbstractDataTreeNode[] comparedChildren = compareWithParent(children, key, parent, comparator);
69         Object JavaDoc oldData = parent.getData(key);
70         return new DataTreeNode(key.lastSegment(), new NodeComparison(oldData, oldData, NodeComparison.K_CHANGED, 0), comparedChildren);
71     }
72
73     /**
74      * Creates and returns a new copy of the receiver. Makes a deep copy of
75      * children, but a shallow copy of name and data.
76      */

77     AbstractDataTreeNode copy() {
78         AbstractDataTreeNode[] childrenCopy;
79         if (children.length == 0) {
80             childrenCopy = NO_CHILDREN;
81         } else {
82             childrenCopy = new AbstractDataTreeNode[children.length];
83             System.arraycopy(children, 0, childrenCopy, 0, children.length);
84         }
85         return new NoDataDeltaNode(name, childrenCopy);
86     }
87
88     /**
89      * Returns true if the receiver represents delta information,
90      * false if it represents the complete information.
91      */

92     boolean isDelta() {
93         return true;
94     }
95
96     /**
97      * Returns true if the receiver is an empty delta node, false otherwise.
98      */

99     boolean isEmptyDelta() {
100         return this.size() == 0;
101     }
102
103     /**
104      * Simplifies the given node, and returns its replacement.
105      */

106     AbstractDataTreeNode simplifyWithParent(IPath key, DeltaDataTree parent, IComparator comparer) {
107         AbstractDataTreeNode[] simplifiedChildren = simplifyWithParent(children, key, parent, comparer);
108         return new NoDataDeltaNode(name, simplifiedChildren);
109     }
110
111     /**
112      * Returns a unicode representation of the node. This method is used
113      * for debugging purposes only (no NLS support needed)
114      */

115     public String JavaDoc toString() {
116         return "a NoDataDeltaNode(" + this.getName() + ") with " + getChildren().length + " children."; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
117
}
118
119     /**
120      * Return a constant describing the type of node.
121      */

122     int type() {
123         return T_NO_DATA_DELTA_NODE;
124     }
125 }
126
Popular Tags