1 9 package org.jboss.portal.common.value; 10 11 12 import java.util.Arrays ; 13 import java.util.List ; 14 15 19 public abstract class AbstractValue implements Value 20 { 21 22 public boolean isNull() 23 { 24 return asObject() == null; 25 } 26 27 public int asInt() throws NullConversionException, FormatConversionException 28 { 29 throw new FormatConversionException(); 30 } 31 32 public boolean asBoolean() throws NullConversionException, FormatConversionException 33 { 34 throw new FormatConversionException(); 35 } 36 37 public boolean isMultiValued() 38 { 39 return false; 40 } 41 42 public String [] asStringArray() 43 { 44 return new String []{asString()}; 45 } 46 47 public int[] asIntArray() throws NullConversionException, FormatConversionException 48 { 49 return new int[]{asInt()}; 50 } 51 52 public boolean[] asBooleanArray() throws NullConversionException, FormatConversionException 53 { 54 return new boolean[]{asBoolean()}; 55 } 56 57 public int hashCode() 58 { 59 Object o = asObject(); 60 return o == null ? 0 : o.hashCode(); 61 } 62 63 public boolean equals(Object obj) 64 { 65 if (obj == this) 66 { 67 return true; 68 } 69 if (obj != null && getClass().isAssignableFrom(obj.getClass())) 70 { 71 AbstractValue other = (AbstractValue)obj; 72 Object o1 = asObject(); 73 Object o2 = other.asObject(); 74 if (o1 == o2) 75 { 76 return true; 77 } 78 return o1 != null && o1.equals(o2); 79 } 80 return false; 81 } 82 83 public List asObjectList() 84 { 85 return Arrays.asList(asObjectArray()); 86 } 87 88 public String toString() 89 { 90 return asString(); 91 } 92 } 93 | Popular Tags |