1 17 package org.apache.ws.jaxme.sqls.impl; 18 19 import org.apache.ws.jaxme.sqls.Value; 20 21 25 public class ValueImpl implements Value { 26 private final Value.Type type; 27 private final Object value; 28 29 public ValueImpl(Value pValue) { 30 this(pValue.getType(), pValue.getValue()); 31 } 32 public ValueImpl(Value.Type pType, Object pValue) { 33 if (pType == null) { 34 throw new NullPointerException ("The value type must not be null."); 35 } 36 if ((pType.equals(Type.PLACEHOLDER) || pType.equals(Type.NULL)) && 37 pValue != null) { 38 throw new IllegalArgumentException ("The value argument must be null for the type " + 39 pType + "."); 40 } 41 type = pType; 42 value = pValue; 43 } 44 45 public Value.Type getType() { return type; } 46 public Object getValue() { return value; } 47 public int hashCode() { 48 int result = type.hashCode(); 49 if (value != null) { 50 result = value.hashCode(); 51 } 52 return result; 53 } 54 public boolean equals(Object o) { 55 if (o == null || !(o instanceof Value)) { 56 return false; 57 } 58 Value v = (Value) o; 59 if (!type.equals(v.getType())) { return false; } 60 if (value == null) { 61 return v.getValue() == null; 62 } else { 63 return value.equals(v.getValue()); 64 } 65 } 66 67 public static Object asValue(Object pValue) { 68 if (pValue == null) { 69 return new ValueImpl(Value.Type.NULL, pValue); 70 } else if (pValue instanceof String ) { 71 return new ValueImpl(Value.Type.STRING, pValue); 72 } else if (pValue instanceof Boolean ) { 73 return new ValueImpl(Value.Type.BOOLEAN, pValue); 74 } else if (pValue instanceof Byte ) { 75 return new ValueImpl(Value.Type.BYTE, pValue); 76 } else if (pValue instanceof Short ) { 77 return new ValueImpl(Value.Type.SHORT, pValue); 78 } else if (pValue instanceof Integer ) { 79 return new ValueImpl(Value.Type.INT, pValue); 80 } else if (pValue instanceof Long ) { 81 return new ValueImpl(Value.Type.LONG, pValue); 82 } else if (pValue instanceof Float ) { 83 return new ValueImpl(Value.Type.FLOAT, pValue); 84 } else if (pValue instanceof Double ) { 85 return new ValueImpl(Value.Type.DOUBLE, pValue); 86 } else { 87 return pValue; 88 } 89 } 90 } 91 | Popular Tags |