/** * Constructs a YAML map, i.e. String -> Object from a given configuration * node. * * @param node The configuration node to create a map from. * @return A Map that contains the configuration node information. */ protected Map<String, Object> constructMap(final ImmutableNode node) { final Map<String, Object> map = new HashMap<>(node.getChildren().size()); for (final ImmutableNode cNode : node.getChildren()) { final Object value = cNode.getChildren().isEmpty() ? cNode.getValue() : constructMap(cNode); addEntry(map, cNode.getNodeName(), value); } return map; }
/** * Checks if the passed in node is defined. Result is <b>true</b> if the * node contains any data. * * @param node the node in question * @return <b>true</b> if the node is defined, <b>false</b> otherwise */ static boolean checkIfNodeDefined(final ImmutableNode node) { return node.getValue() != null || !node.getChildren().isEmpty() || !node.getAttributes().isEmpty(); }
/** * Creates a new {@code ImmutableNode} instance based on the properties * set for this builder. * * @return the newly created {@code ImmutableNode} */ public ImmutableNode create() { final ImmutableNode newNode = new ImmutableNode(this); children = null; attributes = null; return newNode; }
private static void printTree(final PrintStream stream, final String indent, final ImmutableNode result) { final StringBuilder buffer = new StringBuilder(indent).append("<").append(result.getNodeName()); for (final Map.Entry<String, Object> e : result.getAttributes().entrySet()) { buffer.append(' ').append(e.getKey()).append("='").append(e.getValue()).append("'"); } buffer.append(">"); stream.print(buffer.toString()); if (result.getValue() != null) { stream.print(result.getValue()); } boolean newline = false; if (!result.getChildren().isEmpty()) { stream.print("\n"); for (final ImmutableNode child : result.getChildren()) { printTree(stream, indent + " ", child); } newline = true; } if (newline) { stream.print(indent); } stream.println("</" + result.getNodeName() + ">"); } }
final ImmutableNode node2, final ImmutableNode child) if (child.getValue() == null && !isListNode(child) && HANDLER.getChildrenCount(node1, child.getNodeName()) == 1 && HANDLER.getChildrenCount(node2, child.getNodeName()) == 1) HANDLER.getChildren(node2, child.getNodeName()).get(0); if (child2.getValue() == null)
@Override public String nodeName(final ImmutableNode node) { return node.getNodeName(); }
@Override public List<ImmutableNode> getChildren(final ImmutableNode node) { return node.getChildren(); }
result.name(node1.getNodeName()); result.addAttributes(node2.getAttributes()); result.addAttributes(node1.getAttributes()); final List<ImmutableNode> children2 = new LinkedList<>(node2.getChildren()); for (final ImmutableNode child1 : node1.getChildren())
.getChildren()) sections.add(node.getNodeName());
@Override public Object getValue(final ImmutableNode node) { return node.getValue(); }
final ImmutableNode child, final List<ImmutableNode> children2) final Map<String, Object> attrs1 = child.getAttributes(); final List<ImmutableNode> nodes = new ArrayList<>(); HANDLER.getChildren(node2, child.getNodeName()); for (final ImmutableNode node : children)
@Override public Set<String> getAttributes(final ImmutableNode node) { return node.getAttributes().keySet(); }
private Map<String, Object> constructMap(ImmutableNode node) { final Map<String, Object> map = new HashMap<>(node.getChildren().size()); map.putAll(node.getAttributes()); MutableListMultimap<String, ImmutableNode> nodesByName = ListAdapter.adapt(node.getChildren()).groupBy(new Function<ImmutableNode, String>() { @Override public String valueOf(ImmutableNode immutableNode) {
final List<ImmutableNode> resultNodes = new LinkedList<>(); for (final ImmutableNode nd : target.getChildren()) return target.replaceChildren(resultNodes);
/** * Creates a new {@code ImmutableNode} instance which is a copy of this * object, but has the given child node added. * * @param child the child node to be added (must not be <b>null</b>) * @return the new node with the child node added * @throws IllegalArgumentException if the child node is <b>null</b> */ public ImmutableNode addChild(final ImmutableNode child) { checkChildNode(child); final Builder builder = new Builder(children.size() + 1, attributes); builder.addChildren(children).addChild(child); return createWithBasicProperties(builder); }
/** * Creates a new {@code ImmutableNode} instance with the same properties as * this object, but with the given new attributes. * * @param newAttrs the new attributes * @return the new node instance */ private ImmutableNode createWithNewAttributes(final Map<String, Object> newAttrs) { return createWithBasicProperties(new Builder(children, null) .addAttributes(newAttrs)); }
/** * Returns a new {@code ImmutableNode} instance which is a copy of this * object, but with the specified attribute set to the given value. If an * attribute with this name does not exist, it is created now. Otherwise, * the new value overrides the old one. * * @param name the name of the attribute * @param value the attribute value * @return the new node with this attribute */ public ImmutableNode setAttribute(final String name, final Object value) { final Map<String, Object> newAttrs = new HashMap<>(attributes); newAttrs.put(name, value); return createWithNewAttributes(newAttrs); }
@Override protected ImmutableNode apply(final ImmutableNode target, final Operations operations) { return target.removeAttribute(attributeName); } }
nodeHandler.getChildren(parent, node.getNodeName()); final List<Object> values = new ArrayList<>(items.size()); for (final ImmutableNode n : items) values.add(n.getValue());
/** * Helper method for comparing the names of two nodes. * * @param n1 node 1 * @param n2 node 2 * @return a flag whether these nodes have equal names */ private static boolean nameEquals(final ImmutableNode n1, final ImmutableNode n2) { return StringUtils.equals(n2.getNodeName(), n1.getNodeName()); } }