Coverage Report - org.codehaus.mojo.sql.DelimiterType
 
Classes in this File Line Coverage Branch Coverage Complexity
DelimiterType
0%
0/21
0%
0/12
2
 
 1  
 package org.codehaus.mojo.sql;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 /**
 23  
  * @author Brian Topping
 24  
  */
 25  
 public class DelimiterType
 26  
 {
 27  
     public static final String NORMAL = "normal";
 28  
 
 29  
     public static final String ROW = "row";
 30  
 
 31  
     /**
 32  
      * The selected value in this enumeration.
 33  
      */
 34  
     protected String value;
 35  
 
 36  
     /**
 37  
      * the index of the selected value in the array.
 38  
      */
 39  0
     private int index = -1;
 40  
 
 41  
     /**
 42  
      * This is the only method a subclass needs to implement.
 43  
      *
 44  
      * @return an array holding all possible values of the enumeration.
 45  
      * The order of elements must be fixed so that <tt>indexOfValue(String)</tt>
 46  
      * always return the same index for the same value.
 47  
      */
 48  
     public String[] getValues()
 49  
     {
 50  0
         return new String[] { NORMAL, ROW };
 51  
     }
 52  
 
 53  
     /** bean constructor */
 54  
     protected DelimiterType()
 55  0
     {
 56  0
     }
 57  
 
 58  
     /**
 59  
      * Set the delimiterValue. Use DelimiterType.NORMAL or DelimiterType.ROW
 60  
      * 
 61  
      * @param value
 62  
      */
 63  
     public final void setValue( String value )
 64  
     {
 65  0
         int index = indexOfValue( value );
 66  0
         if ( index == -1 )
 67  
         {
 68  0
             throw new IllegalArgumentException( value + " is not a legal value for this attribute" );
 69  
         }
 70  0
         this.index = index;
 71  0
         this.value = value;
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Is this value included in the enumeration?
 76  
      * @param value
 77  
      * @return true if this value is supported
 78  
      */
 79  
     public final boolean containsValue( String value )
 80  
     {
 81  0
         return ( indexOfValue( value ) != -1 );
 82  
     }
 83  
 
 84  
     /**
 85  
      * get the index of a value in this enumeration.
 86  
      * @param value the string value to look for.
 87  
      * @return the index of the value in the array of strings
 88  
      * or -1 if it cannot be found.
 89  
      * @see #getValues()
 90  
      */
 91  
     public final int indexOfValue( String value )
 92  
     {
 93  0
         String[] values = getValues();
 94  0
         if ( values == null || value == null )
 95  
         {
 96  0
             return -1;
 97  
         }
 98  0
         for ( int i = 0; i < values.length; i++ )
 99  
         {
 100  0
             if ( value.equals( values[i] ) )
 101  
             {
 102  0
                 return i;
 103  
             }
 104  
         }
 105  0
         return -1;
 106  
     }
 107  
 
 108  
     /**
 109  
      * @return the selected value.
 110  
      */
 111  
     public final String getValue()
 112  
     {
 113  0
         return value;
 114  
     }
 115  
 
 116  
     /**
 117  
      * @return the index of the selected value in the array.
 118  
      * @see #getValues()
 119  
      */
 120  
     public final int getIndex()
 121  
     {
 122  0
         return index;
 123  
     }
 124  
 
 125  
     /**
 126  
      * Convert the value to its string form.
 127  
      *
 128  
      * @return the string form of the value.
 129  
      */
 130  
     public String toString()
 131  
     {
 132  0
         return getValue();
 133  
     }
 134  
 
 135  
 }