Coverage Report - org.simpleframework.xml.strategy.ArrayValue
 
Classes in this File Line Coverage Branch Coverage Complexity
ArrayValue
90%
9/10
N/A
1
 
 1  
 /*
 2  
  * ArrayValue.java April 2007
 3  
  *
 4  
  * Copyright (C) 2007, 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.strategy;
 20  
 
 21  
 /**
 22  
  * The <code>ArrayValue</code> object is a value used for describing
 23  
  * arrays for a specified component type object. This provides the
 24  
  * component type for the array as well as the length of the array,
 25  
  * which allows the deserialization process to build a suitable length
 26  
  * array from the criteria taken from the XML element.
 27  
  * 
 28  
  * @author Niall Gallagher
 29  
  * 
 30  
  * @see org.simpleframework.xml.strategy.Allocate
 31  
  */
 32  
 class ArrayValue implements Value {
 33  
    
 34  
    /**
 35  
     * This is the value that has been set within this value object.
 36  
     */
 37  
    private Object value;
 38  
    
 39  
    /**
 40  
     * This is the optional field type for the array to be created. 
 41  
     */
 42  
    private Class type;
 43  
    
 44  
    /**
 45  
     * This is used to determine the size of the array to be created.
 46  
     */
 47  
    private int size;
 48  
    
 49  
    /**
 50  
     * Constructor for the <code>ArrayValue</code> object. This will
 51  
     * provide sufficient criteria to the deserialization process 
 52  
     * to instantiate an array of the specified size an type.
 53  
     * 
 54  
     * @param type this is the component type for the array
 55  
     * @param size this is the size of the array to instantiate
 56  
     */
 57  182
    public ArrayValue(Class type, int size) {
 58  182
       this.type = type;      
 59  182
       this.size = size;
 60  182
    }
 61  
    
 62  
    /**
 63  
     * This is the instance that is acquired from this value. This is
 64  
     * typically used if the <code>isReference</code> method is true.
 65  
     * If there was no value reference provided then this returns null.
 66  
     * 
 67  
     * @return this returns a reference to an existing array
 68  
     */
 69  
    public Object getValue() {
 70  0
       return value;
 71  
    }
 72  
    
 73  
    /**
 74  
     * This method is set the value so that future calls provide the
 75  
     * value that was provided. Setting the value ensures that the
 76  
     * value used is consistent across invocations of this object.
 77  
     * 
 78  
     * @param value this is the value to inserted to this object
 79  
     */
 80  
    public void setValue(Object value) {
 81  181
       this.value = value;
 82  181
    }
 83  
    
 84  
    /**
 85  
     * This will return the component type for the array instance 
 86  
     * that is described by this object. This is used to ensure that
 87  
     * an array with the correct component type can be instantiated.
 88  
     * 
 89  
     * @return this returns the component type for the array
 90  
     */
 91  
    public Class getType() {
 92  488
       return type;
 93  
    }
 94  
 
 95  
    /**
 96  
     * This returns the length of the array that is to be allocated.
 97  
     * For various <code>Strategy</code> implementations the length
 98  
     * is provided as an attribute on the array XML element.
 99  
     * 
 100  
     * @return this returns the number of elements for the array
 101  
     */
 102  
    public int getLength() {
 103  126
       return size;
 104  
    } 
 105  
    
 106  
    /**
 107  
     * This will return false for the array value because the array
 108  
     * is not a reference type. Only <code>Reference</code> values 
 109  
     * will have this set to true as they read from the graph.
 110  
     * 
 111  
     * @return this returns false as this is not a reference value
 112  
     */
 113  
    public boolean isReference() {
 114  102
       return false;
 115  
    }  
 116  
 }