136 */ 137 public Object shallowClone() { 138 try { 139 return super.clone(); 140 } catch (Exception e) { 141 // We can't be here since we implement Cloneable. 142 return null; 143 } 144 } 145 146 /** 147 * Creates a copy of a <code>ParameterBlock</code>. The source and parameter 148 * Vectors are cloned, but the actual sources and parameters are 149 * copied by reference. This allows modifications to the order 150 * and number of sources and parameters in the clone to be invisible 151 * to the original <code>ParameterBlock</code>. Changes to the shared sources or 152 * parameters themselves will still be visible. 153 * 154 * @return an Object clone of the <code>ParameterBlock</code>. 155 */ 156 public Object clone() { 157 ParameterBlock theClone; 158 159 try { 160 theClone = (ParameterBlock) super.clone(); 161 } catch (Exception e) { 162 // We can't be here since we implement Cloneable. 163 return null; 164 } 165 166 if (sources != null) { 167 theClone.setSources((Vector)sources.clone()); 168 } 169 if (parameters != null) { 170 theClone.setParameters((Vector)parameters.clone()); 171 } 172 return (Object) theClone; 173 } 174 175 /** 176 * Adds an image to end of the list of sources. The image is 177 * stored as an object in order to allow new node types in the 178 * future. 179 * 180 * @param source an image object to be stored in the source list. 181 * @return a new <code>ParameterBlock</code> containing the specified 182 * <code>source</code>. 183 */ 184 public ParameterBlock addSource(Object source) { 185 sources.addElement(source); 186 return this; 187 } 188 189 /** 190 * Returns a source as a general Object. The caller must cast it into 263 /** 264 * Returns the entire Vector of sources. 265 * @return the <code>sources</code> <code>Vector</code>. 266 * @see #setSources(Vector) 267 */ 268 public Vector<Object> getSources() { 269 return sources; 270 } 271 272 /** 273 * Sets the entire Vector of sources to a given Vector. 274 * @param sources the <code>Vector</code> of source images 275 * @see #getSources 276 */ 277 public void setSources(Vector<Object> sources) { 278 this.sources = sources; 279 } 280 281 /** Clears the list of source images. */ 282 public void removeSources() { 283 sources = new Vector(); 284 } 285 286 /** 287 * Returns the number of parameters (not including source images). 288 * @return the number of parameters in the <code>parameters</code> 289 * <code>Vector</code>. 290 */ 291 public int getNumParameters() { 292 return parameters.size(); 293 } 294 295 /** 296 * Returns the entire Vector of parameters. 297 * @return the <code>parameters</code> <code>Vector</code>. 298 * @see #setParameters(Vector) 299 */ 300 public Vector<Object> getParameters() { 301 return parameters; 302 } 303 304 /** 305 * Sets the entire Vector of parameters to a given Vector. 306 * @param parameters the specified <code>Vector</code> of 307 * parameters 308 * @see #getParameters 309 */ 310 public void setParameters(Vector<Object> parameters) { 311 this.parameters = parameters; 312 } 313 314 /** Clears the list of parameters. */ 315 public void removeParameters() { 316 parameters = new Vector(); 317 } 318 319 /** 320 * Adds an object to the list of parameters. 321 * @param obj the <code>Object</code> to add to the 322 * <code>parameters</code> <code>Vector</code> 323 * @return a new <code>ParameterBlock</code> containing 324 * the specified parameter. 325 */ 326 public ParameterBlock add(Object obj) { 327 parameters.addElement(obj); 328 return this; 329 } 330 331 /** 332 * Adds a Byte to the list of parameters. 333 * @param b the byte to add to the 334 * <code>parameters</code> <code>Vector</code> 335 * @return a new <code>ParameterBlock</code> containing 336 * the specified parameter. 679 * @param index the index of the parameter to be returned. 680 * @return the parameter at the specified index 681 * as a <code>double</code> value. 682 * @throws ClassCastException if the parameter at the 683 * specified index is not a <code>Double</code> 684 * @throws NullPointerException if the parameter at the specified 685 * index is <code>null</code> 686 * @throws ArrayIndexOutOfBoundsException if <code>index</code> 687 * is negative or not less than the current size of this 688 * <code>ParameterBlock</code> object 689 */ 690 public double getDoubleParameter(int index) { 691 return ((Double)parameters.elementAt(index)).doubleValue(); 692 } 693 694 /** 695 * Returns an array of Class objects describing the types 696 * of the parameters. 697 * @return an array of <code>Class</code> objects. 698 */ 699 public Class [] getParamClasses() { 700 int numParams = getNumParameters(); 701 Class [] classes = new Class[numParams]; 702 int i; 703 704 for (i = 0; i < numParams; i++) { 705 Object obj = getObjectParameter(i); 706 if (obj instanceof Byte) { 707 classes[i] = byte.class; 708 } else if (obj instanceof Character) { 709 classes[i] = char.class; 710 } else if (obj instanceof Short) { 711 classes[i] = short.class; 712 } else if (obj instanceof Integer) { 713 classes[i] = int.class; 714 } else if (obj instanceof Long) { 715 classes[i] = long.class; 716 } else if (obj instanceof Float) { 717 classes[i] = float.class; 718 } else if (obj instanceof Double) { 719 classes[i] = double.class; 720 } else { 721 classes[i] = obj.getClass(); | 136 */ 137 public Object shallowClone() { 138 try { 139 return super.clone(); 140 } catch (Exception e) { 141 // We can't be here since we implement Cloneable. 142 return null; 143 } 144 } 145 146 /** 147 * Creates a copy of a <code>ParameterBlock</code>. The source and parameter 148 * Vectors are cloned, but the actual sources and parameters are 149 * copied by reference. This allows modifications to the order 150 * and number of sources and parameters in the clone to be invisible 151 * to the original <code>ParameterBlock</code>. Changes to the shared sources or 152 * parameters themselves will still be visible. 153 * 154 * @return an Object clone of the <code>ParameterBlock</code>. 155 */ 156 @SuppressWarnings("unchecked") // casts from clone 157 public Object clone() { 158 ParameterBlock theClone; 159 160 try { 161 theClone = (ParameterBlock) super.clone(); 162 } catch (Exception e) { 163 // We can't be here since we implement Cloneable. 164 return null; 165 } 166 167 if (sources != null) { 168 theClone.setSources((Vector<Object>)sources.clone()); 169 } 170 if (parameters != null) { 171 theClone.setParameters((Vector<Object>)parameters.clone()); 172 } 173 return (Object) theClone; 174 } 175 176 /** 177 * Adds an image to end of the list of sources. The image is 178 * stored as an object in order to allow new node types in the 179 * future. 180 * 181 * @param source an image object to be stored in the source list. 182 * @return a new <code>ParameterBlock</code> containing the specified 183 * <code>source</code>. 184 */ 185 public ParameterBlock addSource(Object source) { 186 sources.addElement(source); 187 return this; 188 } 189 190 /** 191 * Returns a source as a general Object. The caller must cast it into 264 /** 265 * Returns the entire Vector of sources. 266 * @return the <code>sources</code> <code>Vector</code>. 267 * @see #setSources(Vector) 268 */ 269 public Vector<Object> getSources() { 270 return sources; 271 } 272 273 /** 274 * Sets the entire Vector of sources to a given Vector. 275 * @param sources the <code>Vector</code> of source images 276 * @see #getSources 277 */ 278 public void setSources(Vector<Object> sources) { 279 this.sources = sources; 280 } 281 282 /** Clears the list of source images. */ 283 public void removeSources() { 284 sources = new Vector<>(); 285 } 286 287 /** 288 * Returns the number of parameters (not including source images). 289 * @return the number of parameters in the <code>parameters</code> 290 * <code>Vector</code>. 291 */ 292 public int getNumParameters() { 293 return parameters.size(); 294 } 295 296 /** 297 * Returns the entire Vector of parameters. 298 * @return the <code>parameters</code> <code>Vector</code>. 299 * @see #setParameters(Vector) 300 */ 301 public Vector<Object> getParameters() { 302 return parameters; 303 } 304 305 /** 306 * Sets the entire Vector of parameters to a given Vector. 307 * @param parameters the specified <code>Vector</code> of 308 * parameters 309 * @see #getParameters 310 */ 311 public void setParameters(Vector<Object> parameters) { 312 this.parameters = parameters; 313 } 314 315 /** Clears the list of parameters. */ 316 public void removeParameters() { 317 parameters = new Vector<>(); 318 } 319 320 /** 321 * Adds an object to the list of parameters. 322 * @param obj the <code>Object</code> to add to the 323 * <code>parameters</code> <code>Vector</code> 324 * @return a new <code>ParameterBlock</code> containing 325 * the specified parameter. 326 */ 327 public ParameterBlock add(Object obj) { 328 parameters.addElement(obj); 329 return this; 330 } 331 332 /** 333 * Adds a Byte to the list of parameters. 334 * @param b the byte to add to the 335 * <code>parameters</code> <code>Vector</code> 336 * @return a new <code>ParameterBlock</code> containing 337 * the specified parameter. 680 * @param index the index of the parameter to be returned. 681 * @return the parameter at the specified index 682 * as a <code>double</code> value. 683 * @throws ClassCastException if the parameter at the 684 * specified index is not a <code>Double</code> 685 * @throws NullPointerException if the parameter at the specified 686 * index is <code>null</code> 687 * @throws ArrayIndexOutOfBoundsException if <code>index</code> 688 * is negative or not less than the current size of this 689 * <code>ParameterBlock</code> object 690 */ 691 public double getDoubleParameter(int index) { 692 return ((Double)parameters.elementAt(index)).doubleValue(); 693 } 694 695 /** 696 * Returns an array of Class objects describing the types 697 * of the parameters. 698 * @return an array of <code>Class</code> objects. 699 */ 700 public Class<?>[] getParamClasses() { 701 int numParams = getNumParameters(); 702 Class<?>[] classes = new Class<?>[numParams]; 703 int i; 704 705 for (i = 0; i < numParams; i++) { 706 Object obj = getObjectParameter(i); 707 if (obj instanceof Byte) { 708 classes[i] = byte.class; 709 } else if (obj instanceof Character) { 710 classes[i] = char.class; 711 } else if (obj instanceof Short) { 712 classes[i] = short.class; 713 } else if (obj instanceof Integer) { 714 classes[i] = int.class; 715 } else if (obj instanceof Long) { 716 classes[i] = long.class; 717 } else if (obj instanceof Float) { 718 classes[i] = float.class; 719 } else if (obj instanceof Double) { 720 classes[i] = double.class; 721 } else { 722 classes[i] = obj.getClass(); |