| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LabelMap |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * LabelMap.java July 2006 | |
| 3 | * | |
| 4 | * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net> | |
| 5 | * | |
| 6 | * This library is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU Lesser General Public | |
| 8 | * License as published by the Free Software Foundation. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General | |
| 16 | * Public License along with this library; if not, write to the | |
| 17 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
| 18 | * Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
| 21 | package org.simpleframework.xml.load; | |
| 22 | ||
| 23 | import java.util.LinkedHashMap; | |
| 24 | import java.util.Iterator; | |
| 25 | ||
| 26 | /** | |
| 27 | * The <code>LabelMap</code> object represents a map that contains | |
| 28 | * string label mappings. This is used for convinience as a typedef | |
| 29 | * like construct to avoid having declare the generic type whenever | |
| 30 | * it is referenced. Also this allows <code>Label</code> values | |
| 31 | * from the map to be iterated within for each loops. | |
| 32 | * | |
| 33 | * @author Niall Gallagher | |
| 34 | * | |
| 35 | * @see org.simpleframework.xml.load.Label | |
| 36 | */ | |
| 37 | 0 | class LabelMap extends LinkedHashMap<String, Label> implements Iterable<Label> { |
| 38 | ||
| 39 | /** | |
| 40 | * This is the scanner object that represents the scanner used. | |
| 41 | */ | |
| 42 | private Scanner source; | |
| 43 | ||
| 44 | /** | |
| 45 | * Constructor for the <code>LabelMap</code> object is used to | |
| 46 | * create an empty map. This is used for convinience as a typedef | |
| 47 | * like construct which avoids having to use the generic type. | |
| 48 | */ | |
| 49 | 1220238 | public LabelMap(Scanner source) { |
| 50 | 1220238 | this.source = source; |
| 51 | 1220238 | } |
| 52 | ||
| 53 | /** | |
| 54 | * This allows the <code>Label</code> objects within the label map | |
| 55 | * to be iterated within for each loops. This will provide all | |
| 56 | * remaining label objects within the map. The iteration order is | |
| 57 | * not maintained so label objects may be given in any sequence. | |
| 58 | * | |
| 59 | * @return this returns an iterator for existing label objects | |
| 60 | */ | |
| 61 | public Iterator<Label> iterator() { | |
| 62 | 825330 | return values().iterator(); |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * This performs a <code>remove</code> that will remove the label | |
| 67 | * from the map and return that label. This method allows the | |
| 68 | * values within the map to be exclusively taken one at a time, | |
| 69 | * which enables the user to determine which labels remain. | |
| 70 | * | |
| 71 | * @param name this is the name of the element of attribute | |
| 72 | * | |
| 73 | * @return this is the label object representing the XML node | |
| 74 | */ | |
| 75 | public Label take(String name) { | |
| 76 | 883090 | return remove(name); |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * This method is used to clone the label map such that mappings | |
| 81 | * can be maintained in the original even if they are modified | |
| 82 | * in the clone. This is used to that the <code>Schema</code> can | |
| 83 | * remove mappings from the label map as they are visited. | |
| 84 | * | |
| 85 | * @return this returns a cloned representation of this map | |
| 86 | */ | |
| 87 | public LabelMap clone() { | |
| 88 | 1219638 | LabelMap clone = new LabelMap(source); |
| 89 | ||
| 90 | 1219638 | if(!isEmpty()) { |
| 91 | 852933 | clone.putAll(this); |
| 92 | } | |
| 93 | 1219638 | return clone; |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * This method is used to determine whether strict mappings are | |
| 98 | * required. Strict mapping means that all labels in the class | |
| 99 | * schema must match the XML elements and attributes in the | |
| 100 | * source XML document. When strict mapping is disabled, then | |
| 101 | * XML elements and attributes that do not exist in the schema | |
| 102 | * class will be ignored without breaking the parser. | |
| 103 | * | |
| 104 | * @return true if strict parsing is enabled, false otherwise | |
| 105 | */ | |
| 106 | public boolean isStrict() { | |
| 107 | 11 | return source.isStrict(); |
| 108 | } | |
| 109 | } |