001// 002// Name 003// $RCSfile: Parameter.java,v $ 004// 005// Copyright 006// Confidential Property of Kabira Technologies, Inc. 007// Copyright 2007, 2010 by Kabira Technologies, Inc. 008// All rights reserved. 009// 010// History 011// $Revision: 1.1.2.3 $ $Date: 2010/05/12 14:15:17 $ 012// 013 014package com.kabira.platform; 015 016/** 017 * Generic holder class for parameters. 018 * <p> 019 * This is the base class for input/output and output parameters. 020 */ 021@SuppressWarnings("unchecked") 022public class Parameter<T> 023{ 024 private T value; 025 026 /** 027 * Creates an empty Parameter. 028 */ 029 public Parameter() 030 { 031 this.value = null; 032 } 033 034 /** 035 * Creates a Parameter containing a value. 036 * 037 * @param value Parameter value. 038 */ 039 public Parameter(T value) 040 { 041 this.value = value; 042 } 043 044 /** 045 * Returns the value of this Parameter. 046 * 047 * @return The value of this Parameter. 048 */ 049 public T getValue() 050 { 051 return value; 052 } 053 054 /** 055 * Sets the value of this Parameter. 056 * 057 * @param value Parameter value to set. 058 */ 059 public void setValue(T value) 060 { 061 this.value = value; 062 } 063 064 /** 065 * Returns a String object representing this Parameter's value. 066 * {@inheritDoc} 067 */ 068 @Override 069 public String toString() 070 { 071 return value.toString(); 072 } 073 074 /** 075 * Returns the boolean value of this Parameter. 076 * 077 * @return boolean 078 */ 079 protected boolean getBooleanValue() 080 { 081 Boolean b = (Boolean)getValue(); 082 if (b != null) 083 { 084 return b.booleanValue(); 085 } 086 087 return false; 088 } 089 090 /** 091 * Sets the value of this Parameter to 092 * the passed in boolean. 093 * 094 * @param value boolean value. 095 */ 096 protected void setBooleanValue(boolean value) 097 { 098 Boolean bValue = value; 099 setValue((T)bValue); 100 } 101 102 /** 103 * Returns the byte value of this Parameter. 104 * 105 * @return byte 106 */ 107 protected byte getByteValue() 108 { 109 Byte b = (Byte)getValue(); 110 if (b != null) 111 { 112 return b.byteValue(); 113 } 114 115 return (byte)0; 116 } 117 118 /** 119 * Sets the value of this Parameter to the passed in byte. 120 * 121 * @param value byte value. 122 */ 123 protected void setByteValue(byte value) 124 { 125 Byte bValue = value; 126 setValue((T)bValue); 127 } 128 129 /** 130 * Returns the char value of this Parameter. 131 * 132 * @return char 133 */ 134 protected char getCharValue() 135 { 136 Character b = (Character)getValue(); 137 if (b != null) 138 { 139 return b.charValue(); 140 } 141 142 return (char)0; 143 } 144 145 /** 146 * Sets the value of this Parameter to the passed in char. 147 * 148 * @param value char value. 149 * 150 */ 151 protected void setCharValue(char value) 152 { 153 Character bValue = value; 154 setValue((T)bValue); 155 } 156 157 /** 158 * Returns the short value of this Parameter. 159 * 160 * @return short 161 */ 162 protected short getShortValue() 163 { 164 Short b = (Short)getValue(); 165 if (b != null) 166 { 167 return b.shortValue(); 168 } 169 170 return (short)0; 171 } 172 173 /** 174 * Sets the value of this Parameter to the passed in short. 175 * 176 * @param value short value. 177 * 178 */ 179 protected void setShortValue(short value) 180 { 181 Short bValue = value; 182 setValue((T)bValue); 183 } 184 185 /** 186 * Returns the int value of this Parameter. 187 * 188 * @return int 189 */ 190 protected int getIntValue() 191 { 192 Integer b = (Integer)getValue(); 193 if (b != null) 194 { 195 return b.intValue(); 196 } 197 198 return 0; 199 } 200 201 /** 202 * Sets the value of this Parameter to the passed in int. 203 * 204 * @param value int value. 205 * 206 */ 207 protected void setIntValue(int value) 208 { 209 Integer bValue = value; 210 setValue((T)bValue); 211 } 212 213 /** 214 * Returns the long value of this Parameter. 215 * 216 * @return long 217 */ 218 protected long getLongValue() 219 { 220 Long b = (Long)getValue(); 221 if (b != null) 222 { 223 return b.longValue(); 224 } 225 226 return 0L; 227 } 228 229 /** 230 * Sets the value of this Parameter to the passed in long. 231 * 232 * @param value long value. 233 */ 234 protected void setLongValue(long value) 235 { 236 Long bValue = value; 237 setValue((T)bValue); 238 } 239 240 /** 241 * Returns the float value of this Parameter. 242 * 243 * @return float 244 */ 245 protected float getFloatValue() 246 { 247 Float b = (Float)getValue(); 248 if (b != null) 249 { 250 return b.floatValue(); 251 } 252 253 return (float)0.0; 254 } 255 256 /** 257 * Sets the value of this Parameter to the passed in float. 258 * 259 * @param value float value. 260 * 261 */ 262 protected void setFloatValue(float value) 263 { 264 Float bValue = value; 265 setValue((T)bValue); 266 } 267 268 /** 269 * Returns the double value of this Parameter. 270 * 271 * @return double 272 */ 273 protected double getDoubleValue() 274 { 275 Double b = (Double)getValue(); 276 if (b != null) 277 { 278 return b.doubleValue(); 279 } 280 281 return 0.0; 282 } 283 284 /** 285 * Set the value of this Parameter to the passed in double. 286 * 287 * @param value double value. 288 * 289 */ 290 protected void setDoubleValue(double value) 291 { 292 Double bValue = value; 293 setValue((T)bValue); 294 } 295 296 /** 297 * Returns a String object containing the 298 * string value of this Parameter. 299 * 300 * @return String 301 */ 302 protected String getObjectValue() 303 { 304 String b = (String)getValue(); 305 if (b == null) 306 { 307 b = ""; 308 } 309 310 return b; 311 } 312 313 /** 314 * Sets the value of this Parameter to the passed in String. 315 * 316 * @param value String value. 317 * 318 */ 319 protected void setObjectValue(String value) 320 { 321 setValue((T)value); 322 } 323}