Coverage Report - org.simpleframework.xml.core.ParameterMap
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterMap
100%
8/8
100%
2/2
1.5
 
 1  
 /*
 2  
  * ParameterMap.java May 2012
 3  
  *
 4  
  * Copyright (C) 2012, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.core;
 20  
 
 21  
 import static java.util.Collections.emptyList;
 22  
 
 23  
 import java.util.ArrayList;
 24  
 import java.util.Collection;
 25  
 import java.util.Iterator;
 26  
 import java.util.LinkedHashMap;
 27  
 import java.util.List;
 28  
 
 29  
 /**
 30  
  * The <code>ParameterMap</code> object represents of parameters
 31  
  * that are present within an objects constructors. This is used
 32  
  * for convenience to iterate over parameters and also to acquire
 33  
  * parameters by index, that is, the position they appear in the
 34  
  * constructor signature.
 35  
  * 
 36  
  * @author Niall Gallagher
 37  
  */
 38  
 class ParameterMap extends LinkedHashMap<Object, Parameter> implements Iterable<Parameter>{
 39  
 
 40  
    /**
 41  
     * Constructor for the <code>ParameterMap</code> object. This 
 42  
     * is used to create a linked hash map of parameters where each
 43  
     * parameter can be acquired by its index within a constructor.
 44  
     */
 45  
    public ParameterMap() {
 46  6954
       super();
 47  6954
    }
 48  
    
 49  
    /**
 50  
     * This is used to iterate over <code>Parameter</code> objects.
 51  
     * Parameters are iterated in the order that they are added to
 52  
     * the map. This is primarily used for convenience iteration. 
 53  
     * 
 54  
     * @return this returns an iterator for the parameters
 55  
     */
 56  
    public Iterator<Parameter> iterator() {
 57  2419
       return values().iterator();
 58  
    }
 59  
    
 60  
    /**
 61  
     * This is used to acquire a <code>Parameter</code> using the
 62  
     * position of that parameter within the constructors. This 
 63  
     * allows a builder to determine which parameters to use.
 64  
     * 
 65  
     * @param ordinal this is the position of the parameter
 66  
     * 
 67  
     * @return this returns the parameter for the position
 68  
     */
 69  
    public Parameter get(int ordinal) {
 70  48
       return getAll().get(ordinal);
 71  
    }
 72  
    
 73  
    /**
 74  
     * This is used to acquire an list of <code>Parameter</code>
 75  
     * objects in declaration order. This list will help with the
 76  
     * resolution of the correct constructor for deserialization
 77  
     * of the XML. It also provides a faster method of iteration.
 78  
     * 
 79  
     * @return this returns the parameters in declaration order
 80  
     */
 81  
    public List<Parameter> getAll() {
 82  6544
       Collection<Parameter> list = values();
 83  
       
 84  6544
       if(!list.isEmpty()) {
 85  792
          return new ArrayList(list);
 86  
       }
 87  5752
       return emptyList();
 88  
    }
 89  
 }