| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DataType |
|
| 1.4285714285714286;1.429 | ||||
| DataType$1 |
|
| 1.4285714285714286;1.429 | ||||
| DataType$2 |
|
| 1.4285714285714286;1.429 | ||||
| DataType$3 |
|
| 1.4285714285714286;1.429 |
| 1 | /** | |
| 2 | * Distribution License: | |
| 3 | * JSword is free software; you can redistribute it and/or modify it under | |
| 4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
| 5 | * as published by the Free Software Foundation. This program is distributed | |
| 6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 8 | * See the GNU Lesser General Public License for more details. | |
| 9 | * | |
| 10 | * The License is available on the internet at: | |
| 11 | * http://www.gnu.org/copyleft/lgpl.html | |
| 12 | * or by writing to: | |
| 13 | * Free Software Foundation, Inc. | |
| 14 | * 59 Temple Place - Suite 330 | |
| 15 | * Boston, MA 02111-1307, USA | |
| 16 | * | |
| 17 | * © CrossWire Bible Society, 2008 - 2016 | |
| 18 | * | |
| 19 | */ | |
| 20 | package org.crosswire.common.options; | |
| 21 | ||
| 22 | import org.crosswire.common.util.Convert; | |
| 23 | ||
| 24 | /** | |
| 25 | * A DataType provides the ability to marshal a String value to an object. | |
| 26 | * | |
| 27 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
| 28 | * @author DM Smith | |
| 29 | */ | |
| 30 | 0 | public enum DataType { |
| 31 | /** | |
| 32 | * A string argument. | |
| 33 | */ | |
| 34 | 0 | STRING ("String") { |
| 35 | @Override | |
| 36 | public Object convertFromString(String value) { | |
| 37 | 0 | return value; |
| 38 | } | |
| 39 | }, | |
| 40 | ||
| 41 | /** | |
| 42 | * An integer argument. | |
| 43 | */ | |
| 44 | 0 | INTEGER ("Integer") { |
| 45 | @Override | |
| 46 | public Object convertFromString(String value) { | |
| 47 | 0 | return Integer.valueOf(Convert.string2Int(value)); |
| 48 | } | |
| 49 | }, | |
| 50 | ||
| 51 | /** | |
| 52 | * An boolean argument that allows various values for 'true'. | |
| 53 | */ | |
| 54 | 0 | BOOLEAN ("Boolean") { |
| 55 | @Override | |
| 56 | public Object convertFromString(String value) { | |
| 57 | 0 | return Boolean.valueOf(Convert.string2Boolean(value)); |
| 58 | } | |
| 59 | }; | |
| 60 | ||
| 61 | /** | |
| 62 | * @param name | |
| 63 | * The name of the DataType | |
| 64 | */ | |
| 65 | 0 | DataType(String name) { |
| 66 | 0 | this.name = name; |
| 67 | 0 | } |
| 68 | ||
| 69 | /** | |
| 70 | * Convert a String to an DataType's expected value. | |
| 71 | * @param input the string to convert | |
| 72 | * @return the converted value | |
| 73 | */ | |
| 74 | public abstract Object convertFromString(String input); | |
| 75 | ||
| 76 | /** | |
| 77 | * Find a DataType by name | |
| 78 | * | |
| 79 | * @param name the name of the DataType | |
| 80 | * @return the DataType or null | |
| 81 | */ | |
| 82 | public static DataType fromString(String name) { | |
| 83 | 0 | for (DataType v : values()) { |
| 84 | 0 | if (v.name().equalsIgnoreCase(name)) { |
| 85 | 0 | return v; |
| 86 | } | |
| 87 | } | |
| 88 | // cannot get here | |
| 89 | 0 | assert false; |
| 90 | 0 | return null; |
| 91 | } | |
| 92 | ||
| 93 | /* (non-Javadoc) | |
| 94 | * @see java.lang.Enum#toString() | |
| 95 | */ | |
| 96 | @Override | |
| 97 | public String toString() { | |
| 98 | 0 | return name; |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * The name of the DataType | |
| 103 | */ | |
| 104 | private String name; | |
| 105 | } |