[ 
https://issues.apache.org/jira/browse/WICKET-1596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Doug Donohoe updated WICKET-1596:
---------------------------------

    Attachment: valuemap.v2.patch

Updated patch file attachment.  By the way, here are the APIs I added:

    /**
     * Retrieves a <code>Boolean</code> value by key.
     *
     * @param key
     *            the key
     *
     * @return  the value or null if value is not a valid boolean or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Boolean getAsBoolean(String key);

    /**
     * Retrieves a <code>boolean</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default to return
     *
     * @return  the value or defaultValue if value is not a valid boolean or
     *          no value is in this <code>IValueMap</code>
     *
     */
    boolean getAsBoolean(String key, boolean defaultValue);

    /**
     * Retrieves an <code>Integer</code> value by key.
     *
     * @param key
     *            the key
     *
     * @return  the value or null if value is not a valid integer or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Integer getAsInteger(String key);

    /**
     * Retrieves an <code>integer</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default to return
     *
     * @return  the value or defaultValue if value is not a valid integer or
     *          no value is in this <code>IValueMap</code>
     *
     */
    int getAsInteger(String key, int defaultValue);

    /**
     * Retrieves a <code>Long</code> value by key.
     *
     * @param key
     *            the key
     *
     * @return  the value or null if value is not a valid long or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Long getAsLong(String key);

    /**
     * Retrieves a <code>long</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default to return
     *
     * @return  the value or defaultValue if value is not a valid long or
     *          no value is in this <code>IValueMap</code>
     *
     */
    long getAsLong(String key, long defaultValue);

    /**
     * Retrieves a <code>Double</code> value by key.
     *
     * @param key
     *            the key
     *
     * @return  the value or null if value is not a valid double or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Double getAsDouble(String key);

    /**
     * Retrieves a <code>double</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default to return
     *
     * @return  the value or defaultValue if value is not a valid double or
     *          no value is in this <code>IValueMap</code>
     *
     */
    double getAsDouble(String key, double defaultValue);

    /**
     * Retrieves a <code>Duration</code> value by key.
     *
     * @param key
     *            the key
     *
     * @return  the value or null if value is not a valid Duration or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Duration getAsDuration(String key);

    /**
     * Retrieves a <code>Duration</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default to return
     *
     * @return  the value or defaultValue if value is not a valid Duration or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Duration getAsDuration(String key, Duration defaultValue);

    /**
     * Retrieves a <code>Time</code> value by key.
     *
     * @param key
     *            the key
     *
     * @return  the value or null if value is not a valid Time or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Time getAsTime(String key);

    /**
     * Retrieves a <code>Time</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default to return
     *
     * @return  the value or defaultValue if value is not a valid Time or
     *          no value is in this <code>IValueMap</code>
     *
     */
    Time getAsTime(String key, Time defaultValue);

    /**
     * Retrieves an <code>Enum</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param eClass
     *            the enumeration class
     *
     * @return  the value or null if value is not a valid value of the 
Enumeration or
     *          no value is in this <code>IValueMap</code>
     *
     */
    <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass);

    /**
     * Retrieves an <code>Enum</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param defaultValue
     *            the default value from the Enumeration (cannot be null)
     *
     * @return  the value or defaultValue if value is not a valid value of the 
Enumeration or
     *          no value is in this <code>IValueMap</code>
     *
     */
    <T extends Enum<T>> T getAsEnum(String key, T defaultValue);

    /**
     * Retrieves an <code>Enum</code> value by key.
     *
     * @param key
     *            the key
     *
     * @param eClass
     *            the enumeration class
     *
     * @param defaultValue
     *            the default value from the Enumeration (may be null)
     *
     * @return  the value or defaultValue if value is not a valid value of the 
Enumeration or
     *          no value is in this <code>IValueMap</code>
     *
     */
    <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass, T 
defaultValue);

> New convenience methods for ValueMap
> ------------------------------------
>
>                 Key: WICKET-1596
>                 URL: https://issues.apache.org/jira/browse/WICKET-1596
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.4-M1
>         Environment: Any
>            Reporter: Doug Donohoe
>            Priority: Minor
>             Fix For: 1.4-M2
>
>         Attachments: valuemap.v2.patch
>
>   Original Estimate: 0.17h
>  Remaining Estimate: 0.17h
>
> Methods to get values out of PageParameters (aka ValueMap) as first class 
> Objects (Boolean, Integer, Double, Long, Time, Duration) and to get the same 
> values as primitives if default values are provided without having to worry 
> about StringConversion exceptions.
> This allows one to do:
>   Integer id = params.getAsInteger("id") 
> And not have to worry if id is missing or someone tried to hack the query 
> string by passing in an non-numeric value.   Also, it allows you to check for 
> null without passing in a default value you hope never occurs in practice.
> Also allows you to get Enumerated values as page params.
> public enum TestEnum {
>         one, two, three
>     }
> ValueMap vm  = new ValueMap();
> vm.put("myenum",  "one");
> TestEnum test = vm.getAsEnum("myenum", TestEnum.class, TestEnum.three);
> I have this code done with test cases and a patch ready.  I'll see if I can 
> upload it after I create this issue.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to