[jira] [Created] (CHAIN-56) clever Context with generic type "auto-cast" feature

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (CHAIN-56) clever Context with generic type "auto-cast" feature

Gilles (Jira)
clever Context with generic type "auto-cast" feature
----------------------------------------------------

                 Key: CHAIN-56
                 URL: https://issues.apache.org/jira/browse/CHAIN-56
             Project: Commons Chain
          Issue Type: Improvement
    Affects Versions: 2.0
            Reporter: Simone Tripodi
             Fix For: 2.0


Generics could help us on improving the Context class; since it is clear that Context is a place where storing/retrieving objects identified by a key, I propose adding two helper methods:

{code}
   /** @since 2.0 */
   <T> T retrieve( String key );

   /** @since 2.0 */
   <T> void store( String key, T object );
{code}

that would help users avoid the redundant code of type cast/checking when assignments are already known (it throws a {{ClassCastException}} if types are not assignable). At the same time, old pattern is supported, users can choose their
preferred way to go, depending on their needs.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (CHAIN-56) clever Context with generic type "auto-cast" feature

Gilles (Jira)

    [ https://issues.apache.org/jira/browse/CHAIN-56?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13096897#comment-13096897 ]

Simone Tripodi commented on CHAIN-56:
-------------------------------------

the proposed {{store}} method is useless, since {{Context}} already inherits from {{Map<String,Object>}} where {{put(String,Object)}} already perform the same feature.
OTOH, {{retrieve(String)}} does the magic.

> clever Context with generic type "auto-cast" feature
> ----------------------------------------------------
>
>                 Key: CHAIN-56
>                 URL: https://issues.apache.org/jira/browse/CHAIN-56
>             Project: Commons Chain
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Simone Tripodi
>            Assignee: Simone Tripodi
>             Fix For: 2.0
>
>
> Generics could help us on improving the Context class; since it is clear that Context is a place where storing/retrieving objects identified by a key, I propose adding two helper methods:
> {code}
>    /** @since 2.0 */
>    <T> T retrieve( String key );
>    /** @since 2.0 */
>    <T> void store( String key, T object );
> {code}
> that would help users avoid the redundant code of type cast/checking when assignments are already known (it throws a {{ClassCastException}} if types are not assignable). At the same time, old pattern is supported, users can choose their
> preferred way to go, depending on their needs.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (CHAIN-56) clever Context with generic type "auto-cast" feature

Gilles (Jira)
In reply to this post by Gilles (Jira)

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

Simone Tripodi resolved CHAIN-56.
---------------------------------

    Resolution: Fixed

fixed on [version-2.0-work|https://svn.apache.org/repos/asf/commons/proper/chain/branches/version-2.0-work] branch, see [r1165075|https://svn.apache.org/viewvc?view=revision&revision=1165075]

> clever Context with generic type "auto-cast" feature
> ----------------------------------------------------
>
>                 Key: CHAIN-56
>                 URL: https://issues.apache.org/jira/browse/CHAIN-56
>             Project: Commons Chain
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Simone Tripodi
>            Assignee: Simone Tripodi
>             Fix For: 2.0
>
>
> Generics could help us on improving the Context class; since it is clear that Context is a place where storing/retrieving objects identified by a key, I propose adding two helper methods:
> {code}
>    /** @since 2.0 */
>    <T> T retrieve( String key );
>    /** @since 2.0 */
>    <T> void store( String key, T object );
> {code}
> that would help users avoid the redundant code of type cast/checking when assignments are already known (it throws a {{ClassCastException}} if types are not assignable). At the same time, old pattern is supported, users can choose their
> preferred way to go, depending on their needs.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira