1 19 20 package org.netbeans.modules.xml.xdm.diff; 21 22 import java.util.Collections ; 23 import java.util.List ; 24 import org.netbeans.modules.xml.xdm.nodes.Document; 25 import org.netbeans.modules.xml.xdm.nodes.Node; 26 27 32 public class NodeInfo { 33 34 public NodeInfo(Node n, int pos, List <Node> ancestors1, List <Node> ancestors2) { 35 if (! (n instanceof Document)) { 36 assert ancestors1 != null && ! ancestors1.isEmpty() : "bad ancestors1"; 37 assert ancestors2 != null && ! ancestors2.isEmpty() : "bad ancestors1"; 38 } 39 this.n = n; 40 this.pos = pos; 41 this.ancestors1 = ancestors1; 42 this.ancestors2 = ancestors2; 43 } 44 45 public Node getNode() { 46 return n; 47 } 48 49 52 void setNode(Node node) { 53 if (updated) { 54 assert node.getId() == n.getId() : "expect id="+n.getId()+" got id="+node.getId(); 55 } 56 updated = true; 57 n = node; 58 } 59 60 64 public int getPosition() { 65 return pos; 66 } 67 68 public Node getParent() { 69 if (ancestors1 != null && ancestors1.size() > 0) { 70 return ancestors1.get(0); 71 } 72 return null; 73 } 74 75 79 public Document getDocument() { 80 return (Document) ancestors1.get(ancestors1.size()-1); 81 } 82 83 86 public List <Node> getOriginalAncestors() { 87 return Collections.unmodifiableList(ancestors1); 88 } 89 90 94 public List <Node> getNewAncestors() { 95 if (ancestors2 == null) { 96 assert parent2 != null : "expect parent2 is set"; 97 ancestors2 = DiffFinder.getPathToRoot(parent2); 98 } 99 return Collections.unmodifiableList(ancestors2); 100 } 101 102 public void setNewAncestors(List <Node> ancestors2) { 103 assert ancestors2 != null && ! ancestors2.isEmpty(); 104 this.ancestors2 = ancestors2; 105 parent2 = ancestors2.get(0); 106 } 107 108 public void setNewParent(Node parent) { 109 assert parent != null && parent.isInTree() : "new parent should be not null and inTree"; 110 ancestors2 = null; 111 parent2 = parent; 112 } 113 114 public Node getNewParent() { 115 if (parent2 == null && ! (getNode() instanceof Document)) { 116 assert ancestors2 != null && ancestors2.size() > 0; 117 return ancestors2.get(0); 118 } 119 return parent2; 120 } 121 122 public String toString() { 123 int parentId = getParent() == null ? -1 : getParent().getId(); 124 return DiffFinder.getNodeType(n) + "." + pos + " ids[" + n.getId() + "," + 125 parentId + "]"; 126 } 127 128 132 public static enum NodeType { ELEMENT, ATTRIBUTE, TEXT, WHITE_SPACE }; 133 134 138 private Node n; 139 140 private boolean updated = false; 141 142 private final int pos; 143 144 private final List <Node> ancestors1; 145 146 private List <Node> ancestors2; 148 private Node parent2; 149 } 150 | Popular Tags |