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