1 9 package org.jboss.portal.common.value; 10 11 12 16 public class StringValues extends AbstractValues 17 { 18 19 20 private String [] values; 21 22 public StringValues(String [] values) 23 { 24 if (values == null) 25 { 26 throw new IllegalArgumentException (); 27 } 28 this.values = values; 29 } 30 31 public StringValues(String value) 32 { 33 if (value == null) 34 { 35 throw new IllegalArgumentException (); 36 } 37 this.values = new String []{value}; 38 } 39 40 public StringValues() 41 { 42 this.values = new String [1]; 43 } 44 45 public String asString() 46 { 47 if (isNull()) 48 { 49 return null; 50 } 51 return values[0]; 52 } 53 54 public int asInt() throws NullConversionException, FormatConversionException 55 { 56 if (isNull()) 57 { 58 throw new NullConversionException(); 59 } 60 return Helper.toInt(values[0]); 61 } 62 63 public boolean asBoolean() throws NullConversionException, FormatConversionException 64 { 65 if (isNull()) 66 { 67 throw new NullConversionException(); 68 } 69 return Helper.toBoolean(values[0]); 70 } 71 72 public String [] asStringArray() 73 { 74 return values; 75 } 76 77 public int[] asIntArray() throws NullConversionException, FormatConversionException 78 { 79 int[] valuesAsInt = new int[values.length]; 80 for (int i = 0;i < values.length;i++) 81 { 82 valuesAsInt[i] = Helper.toInt(values[i]); 83 } 84 return valuesAsInt; 85 } 86 87 public boolean[] asBooleanArray() throws NullConversionException, FormatConversionException 88 { 89 boolean[] valuesAsBoolean = new boolean[values.length]; 90 for (int i = 0;i < values.length;i++) 91 { 92 valuesAsBoolean[i] = Helper.toBoolean(values[i]); 93 } 94 return valuesAsBoolean; 95 } 96 97 protected Object [] getObjects() 98 { 99 return values; 100 } 101 } 102 | Popular Tags |