Coverage Report - org.yaml.snakeyaml.nodes.MappingNode
 
Classes in this File Line Coverage Branch Coverage Complexity
MappingNode
97%
33/34
90%
9/10
1.6
 
 1  
 /**
 2  
  * Copyright (c) 2008-2011, http://www.snakeyaml.org
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.yaml.snakeyaml.nodes;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.yaml.snakeyaml.error.Mark;
 22  
 
 23  
 /**
 24  
  * Represents a map.
 25  
  * <p>
 26  
  * A map is a collection of unsorted key-value pairs.
 27  
  * </p>
 28  
  */
 29  
 public class MappingNode extends CollectionNode {
 30  
     private List<NodeTuple> value;
 31  74746
     private boolean merged = false;
 32  
 
 33  
     public MappingNode(Tag tag, boolean resolved, List<NodeTuple> value, Mark startMark,
 34  
             Mark endMark, Boolean flowStyle) {
 35  74746
         super(tag, startMark, endMark, flowStyle);
 36  74746
         if (value == null) {
 37  1
             throw new NullPointerException("value in a Node is required.");
 38  
         }
 39  74745
         this.value = value;
 40  74745
         this.resolved = resolved;
 41  74745
     }
 42  
 
 43  
     public MappingNode(Tag tag, List<NodeTuple> value, Boolean flowStyle) {
 44  51577
         this(tag, true, value, null, null, flowStyle);
 45  51577
     }
 46  
 
 47  
     @Override
 48  
     public NodeId getNodeId() {
 49  252607
         return NodeId.mapping;
 50  
     }
 51  
 
 52  
     /**
 53  
      * Returns the entries of this map.
 54  
      * 
 55  
      * @return List of entries.
 56  
      */
 57  
     public List<NodeTuple> getValue() {
 58  136629
         return value;
 59  
     }
 60  
 
 61  
     public void setValue(List<NodeTuple> merge) {
 62  24
         value = merge;
 63  24
     }
 64  
 
 65  
     public void setOnlyKeyType(Class<? extends Object> keyType) {
 66  20
         for (NodeTuple nodes : value) {
 67  33
             nodes.getKeyNode().setType(keyType);
 68  
         }
 69  20
     }
 70  
 
 71  
     public void setTypes(Class<? extends Object> keyType, Class<? extends Object> valueType) {
 72  45
         for (NodeTuple nodes : value) {
 73  74
             nodes.getValueNode().setType(valueType);
 74  74
             nodes.getKeyNode().setType(keyType);
 75  
         }
 76  45
     }
 77  
 
 78  
     @Override
 79  
     public String toString() {
 80  
         String values;
 81  5
         StringBuilder buf = new StringBuilder();
 82  5
         for (NodeTuple node : getValue()) {
 83  9
             buf.append("{ key=");
 84  9
             buf.append(node.getKeyNode());
 85  9
             buf.append("; value=");
 86  9
             if (node.getValueNode() instanceof CollectionNode) {
 87  
                 // to avoid overflow in case of recursive structures
 88  0
                 buf.append(System.identityHashCode(node.getValueNode()));
 89  
             } else {
 90  9
                 buf.append(node.toString());
 91  
             }
 92  9
             buf.append(" }");
 93  
         }
 94  5
         values = buf.toString();
 95  5
         return "<" + this.getClass().getName() + " (tag=" + getTag() + ", values=" + values + ")>";
 96  
     }
 97  
 
 98  
     /**
 99  
      * @param merged
 100  
      *            - true if map contains merge node
 101  
      */
 102  
     public void setMerged(boolean merged) {
 103  27
         this.merged = merged;
 104  27
     }
 105  
 
 106  
     /**
 107  
      * @return true if map contains merge node
 108  
      */
 109  
     public boolean isMerged() {
 110  22912
         return merged;
 111  
     }
 112  
 }