Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 83   Methods: 6
NCLOC: 30   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StringPropertySelectionModel.java - 100% 100% 100%
coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.form;
 16   
 17    /**
 18    * Implementation of {@link IPropertySelectionModel} that allows one String from
 19    * an array of Strings to be selected as the property.
 20    *
 21    * <p>Uses a simple index number as the value (used to represent the selected String).
 22    * This assumes that the possible values for the Strings will remain constant between
 23    * request cycles.
 24    *
 25    * @author Howard Lewis Ship
 26    *
 27    **/
 28   
 29    public class StringPropertySelectionModel implements IPropertySelectionModel
 30    {
 31    private String[] options;
 32   
 33    /**
 34    * Standard constructor.
 35    *
 36    * The options are retained (not copied).
 37    **/
 38   
 39  4 public StringPropertySelectionModel(String[] options)
 40    {
 41  4 this.options = options;
 42    }
 43   
 44  8 public int getOptionCount()
 45    {
 46  8 return options.length;
 47    }
 48   
 49  42 public Object getOption(int index)
 50    {
 51  42 return options[index];
 52    }
 53   
 54    /**
 55    * Labels match options.
 56    *
 57    **/
 58   
 59  48 public String getLabel(int index)
 60    {
 61  48 return options[index];
 62    }
 63   
 64    /**
 65    * Values are indexes into the array of options.
 66    *
 67    **/
 68   
 69  48 public String getValue(int index)
 70    {
 71  48 return Integer.toString(index);
 72    }
 73   
 74  8 public Object translateValue(String value)
 75    {
 76  8 int index;
 77   
 78  8 index = Integer.parseInt(value);
 79   
 80  8 return options[index];
 81    }
 82   
 83    }