1 9 package org.jboss.portal.common.value; 10 11 12 16 public class BooleanValues extends AbstractValues 17 { 18 19 20 private Boolean [] values; 21 22 23 private boolean[] _values; 24 25 public BooleanValues(String [] values) throws IllegalArgumentException 26 { 27 if (values == null) 28 { 29 throw new IllegalArgumentException (); 30 } 31 this.values = new Boolean [values.length]; 32 for (int i = 0;i < values.length;i++) 33 { 34 String value = values[i]; 35 if (value == null) 36 { 37 this.values[i] = null; 38 } 39 else if ("true".equals(value)) 40 { 41 this.values[i] = Boolean.TRUE; 42 } 43 else if ("false".equals(value)) 44 { 45 this.values[i] = Boolean.FALSE; 46 } 47 else 48 { 49 throw new IllegalArgumentException (); 50 } 51 } 52 } 53 54 public BooleanValues(Boolean value) 55 { 56 if (value == null) 57 { 58 throw new IllegalArgumentException (); 59 } 60 values = new Boolean []{value}; 61 } 62 63 public BooleanValues(Boolean [] values) 64 { 65 if (values == null) 66 { 67 throw new IllegalArgumentException (); 68 } 69 this.values = values; 70 } 71 72 public BooleanValues(boolean value) 73 { 74 this(Boolean.valueOf(value)); 75 } 76 77 public BooleanValues(boolean[] _values) 78 { 79 if (_values == null) 80 { 81 throw new IllegalArgumentException (); 82 } 83 values = new Boolean [_values.length]; 84 for (int i = 0;i < _values.length;i++) 85 { 86 values[i] = Boolean.valueOf(_values[i]); 87 } 88 } 89 90 public String [] asStringArray() 91 { 92 try 93 { 94 return Helper.toStringArray(values, Helper.BOOLEAN_CONVERTER); 95 } 96 catch (ConversionException impossible) 97 { 98 throw new Error (impossible); 99 } 100 } 101 102 public boolean[] asBooleanArray() throws NullConversionException, FormatConversionException 103 { 104 if (_values == null) 105 { 106 _values = new boolean[values.length]; 107 for (int i = 0;i < values.length;i++) 108 { 109 Boolean b = values[i]; 110 if (b == null) 111 { 112 throw new NullConversionException(); 113 } 114 _values[i] = b.booleanValue(); 115 } 116 } 117 return _values; 118 } 119 120 public String asString() 121 { 122 if (isNull()) 123 { 124 return null; 125 } 126 return values[0].toString(); 127 } 128 129 public boolean asBoolean() throws NullConversionException, FormatConversionException 130 { 131 if (isNull()) 132 { 133 throw new NullConversionException(); 134 } 135 return values[0].booleanValue(); 136 } 137 138 protected Object [] getObjects() 139 { 140 return values; 141 } 142 } 143 | Popular Tags |