| 1 28 29 package com.idaremedia.antx.helpers; 30 31 import java.io.Serializable ; 32 33 45 46 public class ObjectHandle implements Serializable  47 { 48 49 private Object m_underlying; 50 51 52 55 public ObjectHandle() 56 { 57 super(); 58 m_underlying=null; 59 } 60 61 62 65 public ObjectHandle(Object o) 66 { 67 super(); 68 m_underlying= o; 69 } 70 71 72 75 public ObjectHandle(char c) 76 { 77 this(new Character (c)); 78 } 79 80 81 84 public ObjectHandle(int i) 85 { 86 this(new Integer (i)); 87 } 88 89 90 93 public ObjectHandle(long l) 94 { 95 this(new Long (l)); 96 } 97 98 99 102 public ObjectHandle(float e) 103 { 104 this(new Float (e)); 105 } 106 107 108 111 public ObjectHandle(double d) 112 { 113 this(new Double (d)); 114 } 115 116 117 120 public ObjectHandle(boolean b) 121 { 122 this(b ? Boolean.TRUE : Boolean.FALSE); 123 } 124 125 126 129 public Object get() 130 { 131 return m_underlying; 132 } 133 134 135 139 public void set(Object o) 140 { 141 m_underlying= o; 142 } 143 144 145 149 public void set(int i) 150 { 151 m_underlying= new Integer (i); 152 } 153 154 155 159 public void set(long l) 160 { 161 m_underlying= new Long (l); 162 } 163 164 165 169 public void set(float e) 170 { 171 m_underlying= new Float (e); 172 } 173 174 175 179 public void set(double d) 180 { 181 m_underlying= new Double (d); 182 } 183 184 185 189 public void set(boolean b) 190 { 191 m_underlying= b ? Boolean.TRUE : Boolean.FALSE; 192 } 193 194 195 199 public void set(char c) 200 { 201 m_underlying= new Character (c); 202 } 203 204 205 208 public String asString() 209 { 210 return (m_underlying==null) ? null : m_underlying.toString(); 211 } 212 213 214 218 public String toString() 219 { 220 return String.valueOf(m_underlying); 221 } 222 223 227 public String asNonNullString() 228 { 229 return (m_underlying instanceof String ) ? m_underlying.toString() : ""; 230 } 231 232 233 236 public final boolean isnull() 237 { 238 return (m_underlying==null) ? true : false; 239 } 240 241 242 248 public boolean equals(Object o) 249 { 250 if (o==null) { 251 return false; 252 } 253 if (o==this) { 254 return true; 255 } 256 if (getClass().equals(o.getClass())) { 257 ObjectHandle oh= (ObjectHandle)o; 258 if (m_underlying==null) { 259 return oh.m_underlying==null; 260 } 261 if (oh.m_underlying==null) { 262 return false; 263 } 264 return m_underlying.equals(oh.m_underlying); 265 } 266 return false; 267 } 268 269 270 275 public int hashCode() 276 { 277 return (m_underlying==null) ? 13 : m_underlying.hashCode(); 278 } 279 } 280 281 282 | Popular Tags |