import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
/**
* @author michal.rehak
- *
+ *
*/
public abstract class NodeUtils {
* @param node
* @return node path up till root node
*/
- public static String buildPath(Node<?> node) {
+ public static String buildPath(final Node<?> node) {
List<String> breadCrumbs = new ArrayList<>();
Node<?> tmpNode = node;
while (tmpNode != null) {
* @return dom tree, containing same node structure, yang nodes are
* associated to dom nodes as user data
*/
- public static org.w3c.dom.Document buildShadowDomTree(CompositeNode treeRootNode) {
+ public static org.w3c.dom.Document buildShadowDomTree(final CompositeNode treeRootNode) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
org.w3c.dom.Document doc = null;
try {
jointPlace.appendChild(itemEl);
if (item instanceof CompositeNode) {
- for (Node<?> child : ((CompositeNode) item).getChildren()) {
+ for (Node<?> child : ((CompositeNode) item).getValue()) {
jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(itemEl, child));
}
}
* @throws XPathExpressionException
*/
@SuppressWarnings("unchecked")
- public static <T> T findNodeByXpath(org.w3c.dom.Document doc, String xpathEx) throws XPathExpressionException {
+ public static <T> T findNodeByXpath(final org.w3c.dom.Document doc, final String xpathEx) throws XPathExpressionException {
T userNode = null;
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
/**
* build NodeMap, where key = qName; value = node
- *
+ *
* @param value
* @return map of children, where key = qName and value is list of children
* groupped by qName
*/
- public static Map<QName, List<Node<?>>> buildNodeMap(List<Node<?>> value) {
- Map<QName, List<Node<?>>> nodeMapTmp = new HashMap<>();
+ public static Map<QName, List<Node<?>>> buildNodeMap(final List<Node<?>> value) {
+ Map<QName, List<Node<?>>> nodeMapTmp = Maps.newLinkedHashMap();
if (value == null) {
throw new IllegalStateException("nodeList should not be null or empty");
}
* @param context
* @return map of lists, where key = path; value = {@link DataSchemaNode}
*/
- public static Map<String, ListSchemaNode> buildMapOfListNodes(SchemaContext context) {
+ public static Map<String, ListSchemaNode> buildMapOfListNodes(final SchemaContext context) {
Map<String, ListSchemaNode> mapOfLists = new HashMap<>();
Stack<DataSchemaNode> jobQueue = new Stack<>();
* @param qNamesPath
* @return path
*/
- private static String schemaPathToPath(List<QName> qNamesPath) {
+ private static String schemaPathToPath(final List<QName> qNamesPath) {
List<String> pathSeed = new ArrayList<>();
for (QName qNameItem : qNamesPath) {
pathSeed.add(qNameItem.getLocalName());
/**
* add given node to it's parent's list of children
- *
+ *
* @param newNode
*/
- public static void fixParentRelation(Node<?> newNode) {
+ public static void fixParentRelation(final Node<?> newNode) {
if (newNode.getParent() != null) {
- List<Node<?>> siblings = newNode.getParent().getChildren();
+ List<Node<?>> siblings = newNode.getParent().getValue();
if (!siblings.contains(newNode)) {
siblings.add(newNode);
}
/**
* crawl all children of given node and assign it as their parent
- *
+ *
* @param parentNode
*/
- public static void fixChildrenRelation(CompositeNode parentNode) {
- if (parentNode.getChildren() != null) {
- for (Node<?> child : parentNode.getChildren()) {
+ public static void fixChildrenRelation(final CompositeNode parentNode) {
+ if (parentNode.getValue() != null) {
+ for (Node<?> child : parentNode.getValue()) {
if (child instanceof AbstractNodeTO<?>) {
((AbstractNodeTO<?>) child).setParent(parentNode);
}
* @param dataMap
* @return list of values of map, found by given keys
*/
- public static <T, K> List<K> collectMapValues(List<T> keys, Map<T, K> dataMap) {
+ public static <T, K> List<K> collectMapValues(final List<T> keys, final Map<T, K> dataMap) {
List<K> valueSubList = new ArrayList<>();
for (T key : keys) {
valueSubList.add(dataMap.get(key));
* @param nodes
* @return list of children in list of appropriate type
*/
- public static List<Node<?>> buildChildrenList(Node<?>... nodes) {
+ public static List<Node<?>> buildChildrenList(final Node<?>... nodes) {
return Lists.newArrayList(nodes);
}