Coverage Report - org.kuali.db.DelimiterType
 
Classes in this File Line Coverage Branch Coverage Complexity
DelimiterType
0%
0/21
0%
0/12
2
 
 1  
 package org.kuali.db;
 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  
         public static final String NORMAL = "normal";
 27  
 
 28  
         public static final String ROW = "row";
 29  
 
 30  
         /**
 31  
          * The selected value in this enumeration.
 32  
          */
 33  
         protected String value;
 34  
 
 35  
         /**
 36  
          * the index of the selected value in the array.
 37  
          */
 38  0
         private int index = -1;
 39  
 
 40  
         /**
 41  
          * This is the only method a subclass needs to implement.
 42  
          * 
 43  
          * @return an array holding all possible values of the enumeration. The order of elements must be fixed so that
 44  
          *         <tt>indexOfValue(String)</tt> always return the same index for the same value.
 45  
          */
 46  
         public String[] getValues() {
 47  0
                 return new String[] { NORMAL, ROW };
 48  
         }
 49  
 
 50  
         /** bean constructor */
 51  0
         protected DelimiterType() {
 52  0
         }
 53  
 
 54  
         /**
 55  
          * Set the delimiterValue. Use DelimiterType.NORMAL or DelimiterType.ROW
 56  
          * 
 57  
          * @param value
 58  
          */
 59  
         public final void setValue(String value) {
 60  0
                 int index = indexOfValue(value);
 61  0
                 if (index == -1) {
 62  0
                         throw new IllegalArgumentException(value + " is not a legal value for this attribute");
 63  
                 }
 64  0
                 this.index = index;
 65  0
                 this.value = value;
 66  0
         }
 67  
 
 68  
         /**
 69  
          * Is this value included in the enumeration?
 70  
          * 
 71  
          * @param value
 72  
          * @return true if this value is supported
 73  
          */
 74  
         public final boolean containsValue(String value) {
 75  0
                 return (indexOfValue(value) != -1);
 76  
         }
 77  
 
 78  
         /**
 79  
          * get the index of a value in this enumeration.
 80  
          * 
 81  
          * @param value
 82  
          *            the string value to look for.
 83  
          * @return the index of the value in the array of strings or -1 if it cannot be found.
 84  
          * @see #getValues()
 85  
          */
 86  
         public final int indexOfValue(String value) {
 87  0
                 String[] values = getValues();
 88  0
                 if (values == null || value == null) {
 89  0
                         return -1;
 90  
                 }
 91  0
                 for (int i = 0; i < values.length; i++) {
 92  0
                         if (value.equals(values[i])) {
 93  0
                                 return i;
 94  
                         }
 95  
                 }
 96  0
                 return -1;
 97  
         }
 98  
 
 99  
         /**
 100  
          * @return the selected value.
 101  
          */
 102  
         public final String getValue() {
 103  0
                 return value;
 104  
         }
 105  
 
 106  
         /**
 107  
          * @return the index of the selected value in the array.
 108  
          * @see #getValues()
 109  
          */
 110  
         public final int getIndex() {
 111  0
                 return index;
 112  
         }
 113  
 
 114  
         /**
 115  
          * Convert the value to its string form.
 116  
          * 
 117  
          * @return the string form of the value.
 118  
          */
 119  
         public String toString() {
 120  0
                 return getValue();
 121  
         }
 122  
 
 123  
 }