当前位置: 首页>>代码示例>>Java>>正文


Java MappingNode类代码示例

本文整理汇总了Java中org.yaml.snakeyaml.nodes.MappingNode的典型用法代码示例。如果您正苦于以下问题:Java MappingNode类的具体用法?Java MappingNode怎么用?Java MappingNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MappingNode类属于org.yaml.snakeyaml.nodes包,在下文中一共展示了MappingNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: representMapping

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的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:imkiva,项目名称:AndroidApktool,代码行数:26,代码来源:BaseRepresenter.java

示例2: construct2ndStep

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的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:imkiva,项目名称:AndroidApktool,代码行数:17,代码来源:CompactConstructor.java

示例3: createEmptyJavaBean

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
protected Object createEmptyJavaBean(MappingNode node) {
    try {
        /**
         * Using only default constructor. Everything else will be
         * initialized on 2nd step. If we do here some partial
         * initialization, how do we then track what need to be done on
         * 2nd step? I think it is better to get only object here (to
         * have it as reference for recursion) and do all other thing on
         * 2nd step.
         */
        java.lang.reflect.Constructor<?> c = node.getType().getDeclaredConstructor();
        c.setAccessible(true);
        return c.newInstance();
    } catch (Exception e) {
        throw new YAMLException(e);
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:18,代码来源:Constructor.java

示例4: constructSet2ndStep

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:27,代码来源:BaseConstructor.java

示例5: constructSet2ndStep

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
开发者ID:RoccoDev,项目名称:5zig-TIMV-Plugin,代码行数:27,代码来源:BaseConstructor.java

示例6: notNullMapProperty

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@Test
public void notNullMapProperty() {
  bean.setMapProperty(ImmutableMap.<String, Long> builder().put("first", 1L).put("second", 2L).build());
  Property property = new MethodProperty(getPropertyDescriptor("mapProperty"));
  NodeTuple nodeTuple = representer.representJavaBeanProperty(bean, property, bean.getMapProperty(), null);
  assertThat(nodeTuple, is(notNullValue()));
  assertThat(nodeTuple.getKeyNode(), is(instanceOf(ScalarNode.class)));
  assertThat(((ScalarNode) nodeTuple.getKeyNode()).getValue(), is("map-property"));
  assertThat(nodeTuple.getValueNode(), is(instanceOf(MappingNode.class)));
  assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().size(), is(2));
  assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().get(0), is(instanceOf(NodeTuple.class)));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getKeyNode()).getValue(),
      is("first"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getValueNode()).getValue(),
      is("1"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getKeyNode()).getValue(),
      is("second"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getValueNode()).getValue(),
      is("2"));
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:21,代码来源:AdvancedRepresenterTest.java

示例7: constructMapping

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Map<Object, Object> constructMapping(MappingNode node)
{
    Object collection;
    if (Map.class.isAssignableFrom(node.getType()))
    {
        collection = YamlCollectionCreator.createCollection(node.getType(), node.getValue().size());
    }
    else
    {
        collection = YamlCollectionCreator.createCollection(Map.class, node.getValue().size());
    }
    this.constructMapping2ndStep(node, (Map<Object, Object>) collection);
    return super.constructMapping(node);
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:17,代码来源:YamlConstructor.java

示例8: construct2ndStep

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的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

示例9: createEmptyJavaBean

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
protected Object createEmptyJavaBean(MappingNode node)
{
    try
    {
        /*
         * Using only default constructor. Everything else will be
         * initialized on 2nd step. If we do here some partial
         * initialization, how do we then track what need to be done on
         * 2nd step? I think it is better to get only object here (to
         * have it as reference for recursion) and do all other thing on
         * 2nd step.
         */
        java.lang.reflect.Constructor<?> c = node.getType().getDeclaredConstructor();
        c.setAccessible(true);
        return c.newInstance();
    }
    catch (Exception e)
    {
        throw new YAMLException(e);
    }
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:22,代码来源:YamlConstructMapping.java

示例10: getKeys

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@Override
public Set<String> getKeys()
{
    if (this.node instanceof MappingNode)
    {
        List<NodeTuple> tuples = ((MappingNode) this.node).getValue();
        Set<String> result = new LinkedHashSet<>(tuples.size());
        for (NodeTuple tuple : tuples)
        {
            Node keyNode = tuple.getKeyNode();
            if (keyNode instanceof ScalarNode)
            {
                result.add(((ScalarNode) keyNode).getValue());
            }
        }
        return result;
    }
    return Collections.emptySet();
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:20,代码来源:YamlDeserializationData.java

示例11: containsKey

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@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;
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:19,代码来源:YamlDeserializationData.java

示例12: getNode

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@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;
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:25,代码来源:YamlDeserializationData.java

示例13: getMap

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <K, T, M extends Map<K, T>> void getMap(String key, Function<String, K> keyMapper, Class<T> type, M map)
{
    Node node = this.getNode(this.node, key);
    if (! (node instanceof MappingNode))
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }
    MappingNode mappingNode = (MappingNode) node;
    Tag typeTag = new Tag(type);
    for (NodeTuple tuple : mappingNode.getValue())
    {
        Node keyNode = tuple.getKeyNode();
        keyNode.setTag(Tag.STR);
        K keyObj = keyMapper.apply(this.constructor.constructObject(keyNode).toString());

        Node valueNode = tuple.getValueNode();
        if (type != Object.class)
        {
            valueNode.setTag(typeTag);
        }

        map.put(keyObj, (T) this.constructor.constructObject(valueNode));
    }
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:27,代码来源:YamlDeserializationData.java

示例14: composeMappingNode

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
protected Node composeMappingNode(String anchor) {
    MappingStartEvent startEvent = (MappingStartEvent) parser.getEvent();
    String tag = startEvent.getTag();
    Tag nodeTag;
    boolean resolved = false;
    if (tag == null || tag.equals("!")) {
        nodeTag = resolver.resolve(NodeId.mapping, null, startEvent.getImplicit());
        resolved = true;
    } else {
        nodeTag = new Tag(tag);
    }

    final List<NodeTuple> children = new ArrayList<NodeTuple>();
    MappingNode node = new MappingNode(nodeTag, resolved, children, startEvent.getStartMark(),
            null, startEvent.getFlowStyle());
    if (anchor != null) {
        anchors.put(anchor, node);
    }
    while (!parser.checkEvent(Event.ID.MappingEnd)) {
        composeMappingChildren(children, node);
    }
    Event endEvent = parser.getEvent();
    node.setEndMark(endEvent.getEndMark());
    return node;
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:26,代码来源:Composer.java

示例15: constructMapping2ndStep

import org.yaml.snakeyaml.nodes.MappingNode; //导入依赖的package包/类
@Override
protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Node valueNode = tuple.getValueNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            key.hashCode();// check circular dependencies
        }
        Object value = constructObject(valueNode);
        Object old = mapping.put(key, value);
        if (old != null) {
            throw new YAMLException("The key is not unique " + key);
        }
    }
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:18,代码来源:UniqueKeyTest.java


注:本文中的org.yaml.snakeyaml.nodes.MappingNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。