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-2012, 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  
 package org.yaml.snakeyaml.nodes;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.yaml.snakeyaml.error.Mark;
 21  
 
 22  
 /**
 23  
  * Represents a map.
 24  
  * <p>
 25  
  * A map is a collection of unsorted key-value pairs.
 26  
  * </p>
 27  
  */
 28  
 public class MappingNode extends CollectionNode {
 29  
     private List<NodeTuple> value;
 30  78432
     private boolean merged = false;
 31  
 
 32  
     public MappingNode(Tag tag, boolean resolved, List<NodeTuple> value, Mark startMark,
 33  
             Mark endMark, Boolean flowStyle) {
 34  78432
         super(tag, startMark, endMark, flowStyle);
 35  78432
         if (value == null) {
 36  1
             throw new NullPointerException("value in a Node is required.");
 37  
         }
 38  78431
         this.value = value;
 39  78431
         this.resolved = resolved;
 40  78431
     }
 41  
 
 42  
     public MappingNode(Tag tag, List<NodeTuple> value, Boolean flowStyle) {
 43  55230
         this(tag, true, value, null, null, flowStyle);
 44  55230
     }
 45  
 
 46  
     @Override
 47  
     public NodeId getNodeId() {
 48  252680
         return NodeId.mapping;
 49  
     }
 50  
 
 51  
     /**
 52  
      * Returns the entries of this map.
 53  
      * 
 54  
      * @return List of entries.
 55  
      */
 56  
     public List<NodeTuple> getValue() {
 57  136699
         return value;
 58  
     }
 59  
 
 60  
     public void setValue(List<NodeTuple> merge) {
 61  27
         value = merge;
 62  27
     }
 63  
 
 64  
     public void setOnlyKeyType(Class<? extends Object> keyType) {
 65  20
         for (NodeTuple nodes : value) {
 66  33
             nodes.getKeyNode().setType(keyType);
 67  
         }
 68  20
     }
 69  
 
 70  
     public void setTypes(Class<? extends Object> keyType, Class<? extends Object> valueType) {
 71  47
         for (NodeTuple nodes : value) {
 72  78
             nodes.getValueNode().setType(valueType);
 73  78
             nodes.getKeyNode().setType(keyType);
 74  
         }
 75  47
     }
 76  
 
 77  
     @Override
 78  
     public String toString() {
 79  
         String values;
 80  5
         StringBuilder buf = new StringBuilder();
 81  5
         for (NodeTuple node : getValue()) {
 82  9
             buf.append("{ key=");
 83  9
             buf.append(node.getKeyNode());
 84  9
             buf.append("; value=");
 85  9
             if (node.getValueNode() instanceof CollectionNode) {
 86  
                 // to avoid overflow in case of recursive structures
 87  0
                 buf.append(System.identityHashCode(node.getValueNode()));
 88  
             } else {
 89  9
                 buf.append(node.toString());
 90  
             }
 91  9
             buf.append(" }");
 92  
         }
 93  5
         values = buf.toString();
 94  5
         return "<" + this.getClass().getName() + " (tag=" + getTag() + ", values=" + values + ")>";
 95  
     }
 96  
 
 97  
     /**
 98  
      * @param merged
 99  
      *            - true if map contains merge node
 100  
      */
 101  
     public void setMerged(boolean merged) {
 102  30
         this.merged = merged;
 103  30
     }
 104  
 
 105  
     /**
 106  
      * @return true if map contains merge node
 107  
      */
 108  
     public boolean isMerged() {
 109  22921
         return merged;
 110  
     }
 111  
 }