當前位置: 首頁>>代碼示例>>Java>>正文


Java Node類代碼示例

本文整理匯總了Java中org.yaml.snakeyaml.nodes.Node的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Node類屬於org.yaml.snakeyaml.nodes包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addSerializer

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public static final <T> void addSerializer(ExtensibleRepresenter representer, Class<T> type,
		Function<T, String> function) {
	representer.addRepresenter(type, new Represent() {

		@SuppressWarnings("unchecked")
		@Override
		public Node representData(Object data) {
			String txt = function.apply((T) data);
			if (txt == null) {
				return new ScalarNode(Tag.NULL, "null", null, null, null);
			}
			return new ScalarNode(Tag.STR, txt, null, null, null);
		}

	});
}
 
開發者ID:berkesa,項目名稱:datatree-adapters,代碼行數:17,代碼來源:YamlSnakeYaml.java

示例2: representSequence

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
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;
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:26,代碼來源:BaseRepresenter.java

示例3: getSingleNode

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
/**
 * Reads a document from a source that contains only one document.
 * <p>
 * If the stream contains more than one document an exception is thrown.
 * </p>
 *
 * @return The root node of the document or <code>null</code> if no document
 *         is available.
 */
public Node getSingleNode() {
    // Drop the STREAM-START event.
    parser.getEvent();
    // Compose a document if the stream is not empty.
    Node document = null;
    if (!parser.checkEvent(Event.ID.StreamEnd)) {
        document = composeDocument();
    }
    // Ensure that the stream contains no more documents.
    if (!parser.checkEvent(Event.ID.StreamEnd)) {
        Event event = parser.getEvent();
        throw new ComposerException("expected a single document in the stream",
                document.getStartMark(), "but found another document", event.getStartMark());
    }
    // Drop the STREAM-END event.
    parser.getEvent();
    return document;
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:28,代碼來源:Composer.java

示例4: construct

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Override
public Object construct( Node node )
{
	if ( node.isTwoStepsConstruction() ) {
		throw new YAMLException( "Unexpected referential mapping structure. Node: " + node );
	}

	Map<?, ?> raw = (Map<?, ?>) super.construct( node );

	if ( raw.containsKey( ConfigurationSerialization.SERIALIZED_TYPE_KEY ) ) {
		Map<String, Object> typed = new LinkedHashMap<String, Object>( raw.size() );
		for ( Map.Entry<?, ?> entry : raw.entrySet() ) {
			typed.put( entry.getKey().toString(), entry.getValue() );
		}

		try {
			return ConfigurationSerialization.deserializeObject( typed );
		} catch ( IllegalArgumentException ex ) {
			throw new YAMLException( "Could not deserialize object", ex );
		}
	}

	return raw;
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:25,代碼來源:YamlConstructor.java

示例5: construct2ndStep

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void construct2ndStep(Node node, Object object)
{
    if (Map.class.isAssignableFrom(node.getType()))
    {
        this.yamlConstructor.constructMapping2ndStep((MappingNode) node, (Map<Object, Object>) object);
    }
    else if (Set.class.isAssignableFrom(node.getType()))
    {
        this.yamlConstructor.constructSet2ndStep((MappingNode) node, (Set<Object>) object);
    }
    else
    {
        this.constructJavaBean2ndStep((MappingNode) node, object);
    }
}
 
開發者ID:GotoFinal,項目名稱:diorite-configs-java8,代碼行數:18,代碼來源:YamlConstructMapping.java

示例6: representMapping

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
protected Node representMapping(Tag tag, Map<?, ?> mapping, Boolean flowStyle) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
    MappingNode node = new MappingNode(tag, value, flowStyle);
    representedObjects.put(objectToRepresent, node);
    boolean bestStyle = true;
    for (Map.Entry<?, ?> entry : mapping.entrySet()) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        if (!(nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null)) {
            bestStyle = false;
        }
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(new NodeTuple(nodeKey, nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:26,代碼來源:BaseRepresenter.java

示例7: getNode

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@Nullable
private Node getNode(MappingNode node, String key, boolean remove)
{
    for (Iterator<NodeTuple> iterator = node.getValue().iterator(); iterator.hasNext(); )
    {
        NodeTuple tuple = iterator.next();
        Node keyNode = tuple.getKeyNode();
        if (! (keyNode instanceof ScalarNode))
        {
            return null;
        }
        if (key.equals(((ScalarNode) keyNode).getValue()))
        {
            if (remove)
            {
                iterator.remove();
            }
            return tuple.getValueNode();
        }
    }
    return null;
}
 
開發者ID:GotoFinal,項目名稱:diorite-configs-java8,代碼行數:23,代碼來源:YamlDeserializationData.java

示例8: constructObject

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
/**
 * Construct object from the specified Node. Return existing instance if the
 * node is already constructed.
 * 
 * @param node
 *            Node to be constructed
 * @return Java instance
 */
protected Object constructObject(Node node) {
    if (constructedObjects.containsKey(node)) {
        return constructedObjects.get(node);
    }
    if (recursiveObjects.contains(node)) {
        throw new ConstructorException(null, null, "found unconstructable recursive node",
                node.getStartMark());
    }
    recursiveObjects.add(node);
    Construct constructor = getConstructor(node);
    Object data = constructor.construct(node);
    constructedObjects.put(node, data);
    recursiveObjects.remove(node);
    if (node.isTwoStepsConstruction()) {
        constructor.construct2ndStep(node, data);
    }
    return data;
}
 
開發者ID:imkiva,項目名稱:AndroidApktool,代碼行數:27,代碼來源:BaseConstructor.java

示例9: getClassForNode

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
protected Class<?> getClassForNode(Node node) {
    Class<? extends Object> classForTag = typeTags.get(node.getTag());
    if (classForTag == null) {
        String name = node.getTag().getClassName();
        Class<?> cl;
        try {
            cl = getClassForName(name);
        } catch (ClassNotFoundException e) {
            throw new YAMLException("Class not found: " + name);
        }
        typeTags.put(node.getTag(), cl);
        return cl;
    } else {
        return classForTag;
    }
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:17,代碼來源:Constructor.java

示例10: construct

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public Object construct(Node node) {
    ScalarNode scalar = (ScalarNode) node;
    try {
        return nf.parse(scalar.getValue());
    } catch (ParseException e) {
        String lowerCaseValue = scalar.getValue().toLowerCase();
        if (lowerCaseValue.contains("inf") || lowerCaseValue.contains("nan")) {
            /*
             * Non-finites such as (+/-)infinity and NaN are not
             * parseable by NumberFormat when these `Double` values are
             * dumped by snakeyaml. Delegate to the `Tag.FLOAT`
             * constructor when for this expected failure cause.
             */
            return (Number) yamlConstructors.get(Tag.FLOAT).construct(node);
        } else {
            throw new IllegalArgumentException("Unable to parse as Number: "
                    + scalar.getValue());
        }
    }
}
 
開發者ID:imkiva,項目名稱:AndroidApktool,代碼行數:21,代碼來源:SafeConstructor.java

示例11: serialize

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public void serialize(Node node) throws IOException {
    if (closed == null) {
        throw new SerializerException("serializer is not opened");
    } else if (closed) {
        throw new SerializerException("serializer is closed");
    }
    this.emitter.emit(new DocumentStartEvent(null, null, this.explicitStart, this.useVersion,
            useTags));
    anchorNode(node);
    if (explicitRoot != null) {
        node.setTag(explicitRoot);
    }
    serializeNode(node, null);
    this.emitter.emit(new DocumentEndEvent(null, null, this.explicitEnd));
    this.serializedNodes.clear();
    this.anchors.clear();
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:18,代碼來源:Serializer.java

示例12: construct2ndStep

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:17,代碼來源:CompactConstructor.java

示例13: nextAnchor

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
public String nextAnchor(Node node) {
    this.lastAnchorId++;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMinimumIntegerDigits(3);
    format.setMaximumFractionDigits(0);// issue 172
    format.setGroupingUsed(false);
    String anchorId = format.format(this.lastAnchorId);
    return "id" + anchorId;
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:10,代碼來源:NumberAnchorGenerator.java

示例14: construct

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
@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;
}
 
開發者ID:fabric8-launcher,項目名稱:launcher-backend,代碼行數:15,代碼來源:OpenShiftClusterConstructor.java

示例15: getNode

import org.yaml.snakeyaml.nodes.Node; //導入依賴的package包/類
/**
 * Reads and composes the next document.
 *
 * @return The root node of the document or <code>null</code> if no more
 *         documents are available.
 */
public Node getNode() {
    // Get the root node of the next document.
    if (!parser.checkEvent(Event.ID.StreamEnd)) {
        return composeDocument();
    } else {
        return null;
    }
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:15,代碼來源:Composer.java


注:本文中的org.yaml.snakeyaml.nodes.Node類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。