1 11 package org.eclipse.core.internal.dtree; 12 13 import org.eclipse.core.runtime.IPath; 14 15 22 public class DataDeltaNode extends DataTreeNode { 23 26 DataDeltaNode(String name, Object data) { 27 super(name, data); 28 } 29 30 33 DataDeltaNode(String name, Object data, AbstractDataTreeNode[] children) { 34 super(name, data, children); 35 } 36 37 40 AbstractDataTreeNode asBackwardDelta(DeltaDataTree myTree, DeltaDataTree parentTree, IPath key) { 41 AbstractDataTreeNode[] newChildren; 42 if (children.length == 0) { 43 newChildren = NO_CHILDREN; 44 } else { 45 newChildren = new AbstractDataTreeNode[children.length]; 46 for (int i = children.length; --i >= 0;) { 47 newChildren[i] = children[i].asBackwardDelta(myTree, parentTree, key.append(children[i].getName())); 48 } 49 } 50 return new DataDeltaNode(name, parentTree.getData(key), newChildren); 51 } 52 53 AbstractDataTreeNode compareWithParent(IPath key, DeltaDataTree parent, IComparator comparator) { 54 AbstractDataTreeNode[] comparedChildren = compareWithParent(children, key, parent, comparator); 55 Object oldData = parent.getData(key); 56 Object newData = data; 57 58 int userComparison = 0; 59 if (key != parent.rootKey()) { 60 61 userComparison = comparator.compare(oldData, newData); 62 } 63 return new DataTreeNode(key.lastSegment(), new NodeComparison(oldData, newData, NodeComparison.K_CHANGED, userComparison), comparedChildren); 64 } 65 66 70 AbstractDataTreeNode copy() { 71 AbstractDataTreeNode[] childrenCopy; 72 if (children.length == 0) { 73 childrenCopy = NO_CHILDREN; 74 } else { 75 childrenCopy = new AbstractDataTreeNode[children.length]; 76 System.arraycopy(children, 0, childrenCopy, 0, children.length); 77 } 78 return new DataDeltaNode(name, data, childrenCopy); 79 } 80 81 85 boolean isDelta() { 86 return true; 87 } 88 89 92 AbstractDataTreeNode simplifyWithParent(IPath key, DeltaDataTree parent, IComparator comparer) { 93 AbstractDataTreeNode[] simplifiedChildren = simplifyWithParent(children, key, parent, comparer); 94 95 if (!key.isRoot() && comparer.compare(parent.getData(key), data) == 0) 96 return new NoDataDeltaNode(name, simplifiedChildren); 97 return new DataDeltaNode(name, data, simplifiedChildren); 98 } 99 100 104 public String toString() { 105 return "a DataDeltaNode(" + this.getName() + ") with " + getChildren().length + " children."; } 107 108 111 int type() { 112 return T_DELTA_NODE; 113 } 114 } 115 | Popular Tags |