org.yaml.snakeyaml.nodes.SequenceNode Java Examples
The following examples show how to use
org.yaml.snakeyaml.nodes.SequenceNode.
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 |
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: BaseConstructor.java From snake-yaml with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected Set<? extends Object> constructSet(SequenceNode node) { Set<Object> result; if (!node.getType().isInterface()) { // the root class may be defined try { result = (Set<Object>) node.getType().newInstance(); } catch (Exception e) { throw new YAMLException(e); } } else { result = createDefaultSet(node.getValue().size()); } constructSequenceStep2(node, result); return result; }
Example #3
Source File: BaseConstructor.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") protected List<? extends Object> constructSequence(SequenceNode node) { List<Object> result; if (List.class.isAssignableFrom(node.getType()) && !node.getType().isInterface()) { // the root class may be defined (Vector for instance) try { result = (List<Object>) node.getType().newInstance(); } catch (Exception e) { throw new YAMLException(e); } } else { result = createDefaultList(node.getValue().size()); } constructSequenceStep2(node, result); return result; }
Example #4
Source File: BaseConstructor.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") protected Set<? extends Object> constructSet(SequenceNode node) { Set<Object> result; if (!node.getType().isInterface()) { // the root class may be defined try { result = (Set<Object>) node.getType().newInstance(); } catch (Exception e) { throw new YAMLException(e); } } else { result = createDefaultSet(node.getValue().size()); } constructSequenceStep2(node, result); return result; }
Example #5
Source File: YamlConstructSequence.java From Diorite with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object object) { SequenceNode snode = (SequenceNode) node; if (List.class.isAssignableFrom(node.getType())) { List<Object> list = (List<Object>) object; this.yamlConstructor.constructSequenceStep2(snode, list); } else if (node.getType().isArray()) { this.yamlConstructor.constructArrayStep2(snode, object); } else { throw new YAMLException("Immutable objects cannot be recursive."); } }
Example #6
Source File: XmlBuildSpecMigrator.java From onedev with MIT License | 6 votes |
private static Node migrateJobDependency(Element jobDependencyElement) { List<NodeTuple> tuples = new ArrayList<>(); tuples.add(new NodeTuple( new ScalarNode(Tag.STR, "jobName"), new ScalarNode(Tag.STR, jobDependencyElement.elementText("jobName").trim()))); tuples.add(new NodeTuple( new ScalarNode(Tag.STR, "requireSuccessful"), new ScalarNode(Tag.STR, jobDependencyElement.elementText("requireSuccessful").trim()))); Element artifactsElement = jobDependencyElement.element("artifacts"); if (artifactsElement != null) { tuples.add(new NodeTuple( new ScalarNode(Tag.STR, "artifacts"), new ScalarNode(Tag.STR, artifactsElement.getText().trim()))); } List<Node> paramSupplyNodes = migrateParamSupplies(jobDependencyElement.element("jobParams").elements()); if (!paramSupplyNodes.isEmpty()) { tuples.add(new NodeTuple( new ScalarNode(Tag.STR, "jobParams"), new SequenceNode(Tag.SEQ, paramSupplyNodes, FlowStyle.BLOCK))); } return new MappingNode(Tag.MAP, tuples, FlowStyle.BLOCK); }
Example #7
Source File: YamlDeserializationData.java From Diorite with MIT License | 6 votes |
@Override public boolean containsKey(String key) { if (this.node instanceof MappingNode) { return this.getNode((MappingNode) this.node, key) != null; } if (this.node instanceof SequenceNode) { int i = DioriteMathUtils.asInt(key, - 1); if (i == - 1) { return false; } return i < ((SequenceNode) this.node).getValue().size(); } return false; }
Example #8
Source File: BaseConstructor.java From snake-yaml with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected List<? extends Object> constructSequence(SequenceNode node) { List<Object> result; if (List.class.isAssignableFrom(node.getType()) && !node.getType().isInterface()) { // the root class may be defined (Vector for instance) try { result = (List<Object>) node.getType().newInstance(); } catch (Exception e) { throw new YAMLException(e); } } else { result = createDefaultList(node.getValue().size()); } constructSequenceStep2(node, result); return result; }
Example #9
Source File: YamlDeserializationData.java From Diorite with MIT License | 6 votes |
@Nullable private Node getNode(Node node, String key) { if (key.isEmpty()) { return node; } if (node instanceof SequenceNode) { SequenceNode sequenceNode = (SequenceNode) node; List<Node> sequenceNodeValue = sequenceNode.getValue(); int i = DioriteMathUtils.asInt(key, - 1); if ((i == - 1) || (i < sequenceNodeValue.size())) { return null; } return sequenceNodeValue.get(i); } if (node instanceof MappingNode) { return this.getNode((MappingNode) node, key); } return null; }
Example #10
Source File: XmlBuildSpecMigrator.java From onedev with MIT License | 6 votes |
private static Node migrateDefaultMultiValueProvider(Element defaultMultiValueProviderElement) { List<NodeTuple> tuples = new ArrayList<>(); String classTag = getClassTag(defaultMultiValueProviderElement.attributeValue("class")); Element scriptNameElement = defaultMultiValueProviderElement.element("scriptName"); if (scriptNameElement != null) { tuples.add(new NodeTuple( new ScalarNode(Tag.STR, "scriptName"), new ScalarNode(Tag.STR, scriptNameElement.getText().trim()))); } Element valueElement = defaultMultiValueProviderElement.element("value"); if (valueElement != null) { List<Node> valueItemNodes = new ArrayList<>(); for (Element valueItemElement: valueElement.elements()) valueItemNodes.add(new ScalarNode(Tag.STR, valueItemElement.getText().trim())); tuples.add(new NodeTuple( new ScalarNode(Tag.STR, "value"), new SequenceNode(Tag.SEQ, valueItemNodes, FlowStyle.BLOCK))); } return new MappingNode(new Tag(classTag), tuples, FlowStyle.BLOCK); }
Example #11
Source File: CompactConstructor.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override public void construct2ndStep(Node node, Object object) { // Compact Object Notation may contain only one entry MappingNode mnode = (MappingNode) node; NodeTuple nodeTuple = mnode.getValue().iterator().next(); Node valueNode = nodeTuple.getValueNode(); if (valueNode instanceof MappingNode) { valueNode.setType(object.getClass()); constructJavaBean2ndStep((MappingNode) valueNode, object); } else { // value is a list applySequence(object, constructSequence((SequenceNode) valueNode)); } }
Example #12
Source File: YamlLoadAsIssueTest.java From snake-yaml with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public Car construct(Node node) { Car car = new Car(); MappingNode mapping = (MappingNode) node; List<NodeTuple> list = mapping.getValue(); for (NodeTuple tuple : list) { String field = toScalarString(tuple.getKeyNode()); if ("plate".equals(field)) { car.setPlate(toScalarString(tuple.getValueNode())); } if ("wheels".equals(field)) { SequenceNode snode = (SequenceNode) tuple.getValueNode(); List<Wheel> wheels = (List<Wheel>) constructSequence(snode); car.setWheels(wheels); } } return car; }
Example #13
Source File: CompactConstructor.java From snake-yaml with Apache License 2.0 | 6 votes |
@Override public void construct2ndStep(Node node, Object object) { // Compact Object Notation may contain only one entry MappingNode mnode = (MappingNode) node; NodeTuple nodeTuple = mnode.getValue().iterator().next(); Node valueNode = nodeTuple.getValueNode(); if (valueNode instanceof MappingNode) { valueNode.setType(object.getClass()); constructJavaBean2ndStep((MappingNode) valueNode, object); } else { // value is a list applySequence(object, constructSequence((SequenceNode) valueNode)); } }
Example #14
Source File: BaseRepresenter.java From snake-yaml with Apache License 2.0 | 6 votes |
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 #15
Source File: Example2_24Test.java From snake-yaml with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public Object construct(Node node) { SequenceNode snode = (SequenceNode) node; List<Entity> values = (List<Entity>) constructSequence(snode); Shape shape = new Shape(values); return shape; }
Example #16
Source File: AbstractUserAgentAnalyzerDirect.java From yauaa with Apache License 2.0 | 5 votes |
private void loadYamlLookupSets(MappingNode entry, String filename) { String name = null; Set<String> lookupSet = new LinkedHashSet<>(); Set<String> merge = new LinkedHashSet<>(); for (NodeTuple tuple : entry.getValue()) { switch (getKeyAsString(tuple, filename)) { case "name": name = getValueAsString(tuple, filename); break; case "merge": merge.addAll(getStringValues(getValueAsSequenceNode(tuple, filename), filename)); break; case "values": SequenceNode node = getValueAsSequenceNode(tuple, filename); for (String value: getStringValues(node, filename)) { lookupSet.add(value.toLowerCase(Locale.ENGLISH)); } break; default: break; } } if (!merge.isEmpty()) { lookupSetMerge.put(name, merge); } lookupSets.put(name, lookupSet); }
Example #17
Source File: NodeConverterUtils.java From api-compiler with Apache License 2.0 | 5 votes |
public static SequenceNode expectList(YamlReaderHelper config, FieldDescriptor field, Node node) { if (isEmpty(node)) { return new SequenceNode(Tag.SEQ, ImmutableList.<Node>of(), false); } else if (node instanceof ScalarNode) { // Allow a singleton as a list. return new SequenceNode(Tag.SEQ, ImmutableList.<Node>of(node), false); } else if (node instanceof SequenceNode) { return (SequenceNode) node; } else { config.error(node, "Expected a list for field '%s', found '%s'.", field.getFullName(), node.getNodeId()); return new SequenceNode(Tag.SEQ, ImmutableList.<Node>of(), false); } }
Example #18
Source File: YamlSortedSetTest.java From snake-yaml with Apache License 2.0 | 5 votes |
@Override public Object construct(Node node) { if (SortedSet.class.isAssignableFrom(node.getType())) { if (node.isTwoStepsConstruction()) { throw new YAMLException("Set cannot be recursive."); } else { Collection<Object> result = new TreeSet<Object>(); SetContructor.this.constructSequenceStep2((SequenceNode) node, result); return result; } } else { return super.construct(node); } }
Example #19
Source File: SafeConstructor.java From snake-yaml with Apache License 2.0 | 5 votes |
public Object construct(Node node) { // Note: we do not check for duplicate keys, because it's too // CPU-expensive. if (!(node instanceof SequenceNode)) { throw new ConstructorException("while constructing pairs", node.getStartMark(), "expected a sequence, but found " + node.getNodeId(), node.getStartMark()); } SequenceNode snode = (SequenceNode) node; List<Object[]> pairs = new ArrayList<Object[]>(snode.getValue().size()); for (Node subnode : snode.getValue()) { if (!(subnode instanceof MappingNode)) { throw new ConstructorException("while constructingpairs", node.getStartMark(), "expected a mapping of length 1, but found " + subnode.getNodeId(), subnode.getStartMark()); } MappingNode mnode = (MappingNode) subnode; if (mnode.getValue().size() != 1) { throw new ConstructorException("while constructing pairs", node.getStartMark(), "expected a single mapping item, but found " + mnode.getValue().size() + " items", mnode.getStartMark()); } Node keyNode = mnode.getValue().get(0).getKeyNode(); Node valueNode = mnode.getValue().get(0).getValueNode(); Object key = constructObject(keyNode); Object value = constructObject(valueNode); pairs.add(new Object[] { key, value }); } return pairs; }
Example #20
Source File: YamlNodeReader.java From api-compiler with Apache License 2.0 | 5 votes |
private void handleMessageField(ConfigSource.Builder builder, FieldDescriptor field, Node value, String path){ if (field.isMapField()) { MappingNode map = NodeConverterUtils.expectMap(helper, field, value); FieldDescriptor keyField = field.getMessageType().getFields().get(0); FieldDescriptor valueField = field.getMessageType().getFields().get(1); boolean isNested = field.getMessageType().getFields().get(1).getType() == FieldDescriptor.Type.MESSAGE; for (NodeTuple entry : map.getValue()) { Object keyObj = NodeConverterUtils.convert(helper, keyField, entry.getKeyNode()); if (keyObj == null) { continue; } if (isNested) { String nestedPath = appendToPath(path, keyObj); helper.checkAndAddPath(nestedPath, value, field); builder.withBuilder(field, keyObj, new ReadNodeBuildAction(helper, entry.getValueNode(), appendToPath(nestedPath, keyObj))); } else { Object valueObj = NodeConverterUtils.convert(helper, valueField, entry.getValueNode()); if (valueObj != null) { builder.setValue(field, keyObj, valueObj, helper.getLocation(entry.getValueNode())); } } } } else if (field.isRepeated()) { SequenceNode list = NodeConverterUtils.expectList(helper, field, value); int index = 0; for (Node elem : list.getValue()) { String indexedPath = String.format("%s[%s]", path, index++); builder.withAddedBuilder(field, new ReadNodeBuildAction(helper, elem, indexedPath)); } } else { builder.withBuilder(field, new ReadNodeBuildAction(helper, value, path)); } addExplicitLocationField(builder, field, value); }
Example #21
Source File: YamlConstructor.java From Diorite with MIT License | 5 votes |
@Override public List<?> constructSequence(SequenceNode node) { Collection<Object> collection; if (List.class.isAssignableFrom(node.getType())) { collection = YamlCollectionCreator.createCollection(node.getType(), node.getValue().size()); } else { collection = YamlCollectionCreator.createCollection(List.class, node.getValue().size()); } this.constructSequenceStep2(node, collection); return (List<?>) collection; }
Example #22
Source File: SafeConstructor.java From snake-yaml with Apache License 2.0 | 5 votes |
public Object construct(Node node) { // Note: we do not check for duplicate keys, because it's too // CPU-expensive. Map<Object, Object> omap = new LinkedHashMap<Object, Object>(); if (!(node instanceof SequenceNode)) { throw new ConstructorException("while constructing an ordered map", node.getStartMark(), "expected a sequence, but found " + node.getNodeId(), node.getStartMark()); } SequenceNode snode = (SequenceNode) node; for (Node subnode : snode.getValue()) { if (!(subnode instanceof MappingNode)) { throw new ConstructorException("while constructing an ordered map", node.getStartMark(), "expected a mapping of length 1, but found " + subnode.getNodeId(), subnode.getStartMark()); } MappingNode mnode = (MappingNode) subnode; if (mnode.getValue().size() != 1) { throw new ConstructorException("while constructing an ordered map", node.getStartMark(), "expected a single mapping item, but found " + mnode.getValue().size() + " items", mnode.getStartMark()); } Node keyNode = mnode.getValue().get(0).getKeyNode(); Node valueNode = mnode.getValue().get(0).getValueNode(); Object key = constructObject(keyNode); Object value = constructObject(valueNode); omap.put(key, value); } return omap; }
Example #23
Source File: YauaaVersion.java From yauaa with Apache License 2.0 | 5 votes |
public static void assertSameVersion(NodeTuple versionNodeTuple, String filename) { // Check the version information from the Yaml files SequenceNode versionNode = getValueAsSequenceNode(versionNodeTuple, filename); String gitCommitIdDescribeShort = null; String buildTimestamp = null; String projectVersion = null; List<Node> versionList = versionNode.getValue(); for (Node versionEntry : versionList) { requireNodeInstanceOf(MappingNode.class, versionEntry, filename, "The entry MUST be a mapping"); NodeTuple entry = getExactlyOneNodeTuple((MappingNode) versionEntry, filename); String key = getKeyAsString(entry, filename); String value = getValueAsString(entry, filename); switch (key) { case "git_commit_id_describe_short": gitCommitIdDescribeShort = value; break; case "build_timestamp": buildTimestamp = value; break; case "project_version": projectVersion = value; break; case "copyright": case "license": case "url": // Ignore those two when comparing. break; default: throw new InvalidParserConfigurationException( "Yaml config.(" + filename + ":" + versionNode.getStartMark().getLine() + "): " + "Found unexpected config entry: " + key + ", allowed are " + "'git_commit_id_describe_short', 'build_timestamp' and 'project_version'"); } } assertSameVersion(gitCommitIdDescribeShort, buildTimestamp, projectVersion); }
Example #24
Source File: YamlUtils.java From yauaa with Apache License 2.0 | 5 votes |
public static List<String> getStringValues(Node sequenceNode, String filename) { requireNodeInstanceOf(SequenceNode.class, sequenceNode, filename, "The provided node must be a sequence but it is a " + sequenceNode.getNodeId().name()); List<Node> valueNodes = ((SequenceNode)sequenceNode).getValue(); List<String> values = new ArrayList<>(valueNodes.size()); for (Node node: valueNodes) { requireNodeInstanceOf(ScalarNode.class, node, filename, "The value should be a string but it is a " + node.getNodeId().name()); values.add(((ScalarNode)node).getValue()); } return values; }
Example #25
Source File: SafeConstructor.java From snake-yaml with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object data) { if (node.isTwoStepsConstruction()) { constructSequenceStep2((SequenceNode) node, (List<Object>) data); } else { throw new YAMLException("Unexpected recursive sequence structure. Node: " + node); } }
Example #26
Source File: OpenShiftClusterConstructor.java From launchpad-missioncontrol with Apache License 2.0 | 5 votes |
@Override public List<OpenShiftCluster> construct(Node node) { List<OpenShiftCluster> clusters = new ArrayList<>(); SequenceNode sequenceNode = (SequenceNode) node; for (Node n : sequenceNode.getValue()) { MappingNode mapNode = (MappingNode) n; Map<Object, Object> valueMap = constructMapping(mapNode); String id = (String) valueMap.get("id"); String apiUrl = (String) valueMap.get("apiUrl"); String consoleUrl = (String) valueMap.get("consoleUrl"); clusters.add(new OpenShiftCluster(id, apiUrl, consoleUrl)); } return clusters; }
Example #27
Source File: Constructor.java From snake-yaml with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object object) { SequenceNode snode = (SequenceNode) node; if (List.class.isAssignableFrom(node.getType())) { List<Object> list = (List<Object>) object; constructSequenceStep2(snode, list); } else if (node.getType().isArray()) { constructArrayStep2(snode, object); } else { throw new YAMLException("Immutable objects cannot be recursive."); } }
Example #28
Source File: Homography.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
public Object construct(Node node) { @SuppressWarnings("unchecked") List<Double> sequence = (List<Double>) constructSequence((SequenceNode) node); if (sequence == null || sequence.size() != 9) return null; double[][] mat = new double[3][3]; for (int r = 0, i = 0; r < 3; r++) { for (int c = 0; c < 3; c++, i++) { mat[r][c] = sequence.get(i); } } return TransformationMatrix.createFrom(new Array2DRowRealMatrix(mat)); }
Example #29
Source File: AdvancedRepresenterTest.java From waggle-dance with Apache License 2.0 | 5 votes |
@Test public void notNullCollectionProperty() { bean.setCollectionProperty(ImmutableList.<String>builder().add("1").add("2").build()); Property property = new MethodProperty(getPropertyDescriptor("collectionProperty")); NodeTuple nodeTuple = representer.representJavaBeanProperty(bean, property, bean.getCollectionProperty(), null); assertThat(nodeTuple, is(notNullValue())); assertThat(nodeTuple.getKeyNode(), is(instanceOf(ScalarNode.class))); assertThat(((ScalarNode) nodeTuple.getKeyNode()).getValue(), is("collection-property")); assertThat(nodeTuple.getValueNode(), is(instanceOf(SequenceNode.class))); assertThat(((SequenceNode) nodeTuple.getValueNode()).getValue().size(), is(2)); assertThat(((SequenceNode) nodeTuple.getValueNode()).getValue().get(0), is(instanceOf(ScalarNode.class))); assertThat(((ScalarNode) ((SequenceNode) nodeTuple.getValueNode()).getValue().get(0)).getValue(), is("1")); assertThat(((SequenceNode) nodeTuple.getValueNode()).getValue().get(1), is(instanceOf(ScalarNode.class))); assertThat(((ScalarNode) ((SequenceNode) nodeTuple.getValueNode()).getValue().get(1)).getValue(), is("2")); }
Example #30
Source File: SafeConstructor.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") public void construct2ndStep(Node node, Object data) { if (node.isTwoStepsConstruction()) { constructSequenceStep2((SequenceNode) node, (List<Object>) data); } else { throw new YAMLException("Unexpected recursive sequence structure. Node: " + node); } }