com.ecyrd.speed4j.util
Class SetterUtil

java.lang.Object
  extended by com.ecyrd.speed4j.util.SetterUtil

public final class SetterUtil
extends Object

Provides utility method to invoke a given setter on an object while smartly parsing the given argument.

Currently supports automatic detection of integers, booleans and strings. Is smart enough to recognize the unboxed versions as well (i.e. Integers are treated equal to ints, Booleans like booleans, etc).


Method Summary
static void set(Object obj, String method, String value)
          Sets the given parameter on the object while smartly parsing the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

set

public static void set(Object obj,
                       String method,
                       String value)
                throws NoSuchMethodException
Sets the given parameter on the object while smartly parsing the value. For example, if the value can be interpreted as an integer, will invoke the setFoo(int) or setFoo(Integer) methods of the given object as opposed to just dummily invoking the setFoo(String) method.

The setFoo(String) method is always tried as the last resort.

Parameters:
obj - Object to invoke the setter on
method - The setter (e.g. "setFoo").
value - Value to set.
Throws:
NoSuchMethodException - If there is no applicable method to set this value.


Copyright © 2011. All Rights Reserved.