Clover coverage report - Code Coverage for tapestry release 4.0-beta-12
Coverage timestamp: Sun Oct 30 2005 16:22:01 EST
file stats: LOC: 103   Methods: 8
NCLOC: 62   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
StringConvertedPropertySelectionModel.java 100% 94.1% 87.5% 93.1%
coverage coverage
 1    // Copyright 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.coerce;
 16   
 17    import java.util.ArrayList;
 18    import java.util.List;
 19   
 20    import org.apache.hivemind.util.Defense;
 21    import org.apache.tapestry.form.IPropertySelectionModel;
 22   
 23    /**
 24    * {@link org.apache.tapestry.form.IPropertySelectionModel} created from a comma-seperated string by
 25    * {@link org.apache.tapestry.coerce.StringToPropertySelectionModelConverter}.
 26    *
 27    * @author Howard M. Lewis Ship
 28    * @since 4.0
 29    */
 30    public final class StringConvertedPropertySelectionModel implements IPropertySelectionModel
 31    {
 32    private static class Entry
 33    {
 34    String _label;
 35   
 36    String _value;
 37   
 38  14 Entry(String term)
 39    {
 40  14 Defense.notNull(term, "term");
 41   
 42  14 int equalx = term.indexOf('=');
 43   
 44  14 if (equalx < 0)
 45    {
 46  3 _label = term.trim();
 47  3 _value = _label;
 48    }
 49    else
 50    {
 51  11 _label = term.substring(0, equalx).trim();
 52  11 _value = term.substring(equalx + 1).trim();
 53    }
 54    }
 55    }
 56   
 57    private final List _entries;
 58   
 59  4 public StringConvertedPropertySelectionModel(String[] terms)
 60    {
 61  4 Defense.notNull(terms, "terms");
 62   
 63  4 _entries = new ArrayList(terms.length);
 64   
 65  4 for (int i = 0; i < terms.length; i++)
 66    {
 67  14 _entries.add(new Entry(terms[i]));
 68    }
 69    }
 70   
 71  8 public int getOptionCount()
 72    {
 73  8 return _entries.size();
 74    }
 75   
 76  42 private Entry getEntry(int index)
 77    {
 78  42 return (Entry) _entries.get(index);
 79    }
 80   
 81  14 public Object getOption(int index)
 82    {
 83  14 return getValue(index);
 84    }
 85   
 86  14 public String getLabel(int index)
 87    {
 88    // TODO Auto-generated method stub
 89  14 return getEntry(index)._label;
 90    }
 91   
 92  28 public String getValue(int index)
 93    {
 94  28 return getEntry(index)._value;
 95    }
 96   
 97  0 public Object translateValue(String value)
 98    {
 99    // Values are the same on the client and the server, so no translation needed.
 100  0 return value;
 101    }
 102   
 103    }