Java Code Examples for org.yaml.snakeyaml.nodes.SequenceNode#setFlowStyle()

The following examples show how to use org.yaml.snakeyaml.nodes.SequenceNode#setFlowStyle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseRepresenter.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected Node representSequence(Tag tag, Iterable<?> sequence, Boolean flowStyle) {
    int size = 10;// default for ArrayList
    if (sequence instanceof List<?>) {
        size = ((List<?>) sequence).size();
    }
    List<Node> value = new ArrayList<Node>(size);
    SequenceNode node = new SequenceNode(tag, value, flowStyle);
    representedObjects.put(objectToRepresent, node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!((nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
 
Example 2
Source File: BaseRepresenter.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
protected Node representSequence(Tag tag, Iterable<?> sequence, Boolean flowStyle) {
    int size = 10;// default for ArrayList
    if (sequence instanceof List<?>) {
        size = ((List<?>) sequence).size();
    }
    List<Node> value = new ArrayList<Node>(size);
    SequenceNode node = new SequenceNode(tag, value, flowStyle);
    representedObjects.put(objectToRepresent, node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
 
Example 3
Source File: Representer.java    From Diorite with MIT License 4 votes vote down vote up
@Override
    public Node representSequence(Tag tag, Iterable<?> sequence, @Nullable Boolean flowStyle)
    {
        int size = 10;// default for ArrayList
        if (sequence instanceof Collection<?>)
        {
            size = ((Collection<?>) sequence).size();
        }
        List<Node> value = new ArrayList<>(size);
        SequenceNode node = new SequenceNode(tag, value, flowStyle);
        this.representedObjects.put(this.objectToRepresent, node);
        boolean bestStyle = true;
        long width = 0;
        for (Object item : sequence)
        {
            Node nodeItem = this.representData(item);
            if (bestStyle)
            {
                if ((nodeItem instanceof ScalarNode) && (((ScalarNode) nodeItem).getStyle() == null))
                {
                    String val = ((ScalarNode) nodeItem).getValue();
                    width += (val == null) ? 0 : val.length();
                    width += 2; // comma and space.
                    if (width > MAX_WIDTH)
                    {
                        bestStyle = false;
                    }
                }
                else
                {
                    bestStyle = false;
                }
            }
            value.add(nodeItem);
        }
        if (flowStyle == null)
        {
            // we ignore this for diorite representer, configs should look nice.
//            if (this.defaultFlowStyle != FlowStyle.AUTO)
//            {
//                node.setFlowStyle(this.defaultFlowStyle.getStyleBoolean());
//            }
//            else
//            {
            node.setFlowStyle(bestStyle);
//            }
        }
        return node;
    }