1 9 package org.jboss.portal.common.value; 10 11 12 16 public class IntegerValue extends AbstractValue 17 { 18 19 private static final Integer [] EMPTY_ARRAY_INTEGER = new Integer [0]; 20 21 private Integer value; 22 23 public IntegerValue() 24 { 25 this.value = null; 26 } 27 28 public IntegerValue(String value) 29 { 30 if (value == null) 31 { 32 throw new IllegalArgumentException (); 33 } 34 try 35 { 36 this.value = new Integer (value); 37 } 38 catch (NumberFormatException e) 39 { 40 throw new IllegalArgumentException (); 41 } 42 } 43 44 public IntegerValue(int _value) 45 { 46 this.value = new Integer (_value); 47 } 48 49 public IntegerValue(Integer value) 50 { 51 if (value == null) 52 { 53 throw new IllegalArgumentException (); 54 } 55 this.value = value; 56 } 57 58 public String asString() 59 { 60 return String.valueOf(value); 61 } 62 63 public int asInt() throws NullConversionException, FormatConversionException 64 { 65 if (value == null) 66 { 67 throw new NullConversionException(); 68 } 69 return value.intValue(); 70 } 71 72 public Object asObject() 73 { 74 return value; 75 } 76 77 public Object [] asObjectArray() 78 { 79 if (isNull()) 80 { 81 return EMPTY_ARRAY_INTEGER; 82 } 83 return new Integer []{value}; 84 } 85 } 86 | Popular Tags |