You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Mathias Herberts (JIRA)" <ji...@apache.org> on 2010/10/08 11:03:31 UTC

[jira] Created: (THRIFT-949) Modify the TEnum interface so it defines a method similar to findByValue

Modify the TEnum interface so it defines a method similar to findByValue
------------------------------------------------------------------------

                 Key: THRIFT-949
                 URL: https://issues.apache.org/jira/browse/THRIFT-949
             Project: Thrift
          Issue Type: Improvement
          Components: Java - Compiler, Java - Library
            Reporter: Mathias Herberts
            Priority: Trivial


In some cases, Thrift instances are converted into more simple types. This is made easy by the existence of the meta data map.

TEnum fields are usually converted to 'int' using getValue.

When converting back to Thrift, those 'int' need to be converted back to TEnum.

The generated TEnum classes have a static method findByValue, but as it is static it is not defined in the TEnum interface and therefore can only be accessed using reflection if the enum type is not know before runtime.

By adding a simple 'public TEnum getByValue(int value)' method in the TEnum interface, we could get rid of the reflection part. 

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


[jira] Closed: (THRIFT-949) Modify the TEnum interface so it defines a method similar to findByValue

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-949?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury closed THRIFT-949.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 0.6
         Assignee: Mathias Herberts

I just committed this. Thanks for the patch, Mathias!

> Modify the TEnum interface so it defines a method similar to findByValue
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-949
>                 URL: https://issues.apache.org/jira/browse/THRIFT-949
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler, Java - Library
>            Reporter: Mathias Herberts
>            Assignee: Mathias Herberts
>            Priority: Trivial
>             Fix For: 0.6
>
>         Attachments: THRIFT-949-1
>
>
> In some cases, Thrift instances are converted into more simple types. This is made easy by the existence of the meta data map.
> TEnum fields are usually converted to 'int' using getValue.
> When converting back to Thrift, those 'int' need to be converted back to TEnum.
> The generated TEnum classes have a static method findByValue, but as it is static it is not defined in the TEnum interface and therefore can only be accessed using reflection if the enum type is not know before runtime.
> By adding a simple 'public TEnum getByValue(int value)' method in the TEnum interface, we could get rid of the reflection part. 

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


[jira] Commented: (THRIFT-949) Modify the TEnum interface so it defines a method similar to findByValue

Posted by "Mathias Herberts (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919345#action_12919345 ] 

Mathias Herberts commented on THRIFT-949:
-----------------------------------------

The EnumMetaData contains the class, you can then either instantiate an instance and call the additional method I propose, or rely on reflection to call 'findByValue'. I'm not a big fan of reflection as it makes refactoring harder.



> Modify the TEnum interface so it defines a method similar to findByValue
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-949
>                 URL: https://issues.apache.org/jira/browse/THRIFT-949
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler, Java - Library
>            Reporter: Mathias Herberts
>            Priority: Trivial
>
> In some cases, Thrift instances are converted into more simple types. This is made easy by the existence of the meta data map.
> TEnum fields are usually converted to 'int' using getValue.
> When converting back to Thrift, those 'int' need to be converted back to TEnum.
> The generated TEnum classes have a static method findByValue, but as it is static it is not defined in the TEnum interface and therefore can only be accessed using reflection if the enum type is not know before runtime.
> By adding a simple 'public TEnum getByValue(int value)' method in the TEnum interface, we could get rid of the reflection part. 

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


[jira] Commented: (THRIFT-949) Modify the TEnum interface so it defines a method similar to findByValue

Posted by "Mathias Herberts (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12925127#action_12925127 ] 

Mathias Herberts commented on THRIFT-949:
-----------------------------------------

Ok, changed my perspective on this one.

What bothered me was having to use the 'findByValue' method outside of thrift code, which would mean trouble in case this method changed either its name or its signature (we never know).

To alleviate this problem, I've created a new TEnumHelper class with a getByValue method. In case 'findByValue' changes, only this class will be affected.

> Modify the TEnum interface so it defines a method similar to findByValue
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-949
>                 URL: https://issues.apache.org/jira/browse/THRIFT-949
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler, Java - Library
>            Reporter: Mathias Herberts
>            Priority: Trivial
>         Attachments: THRIFT-949-1
>
>
> In some cases, Thrift instances are converted into more simple types. This is made easy by the existence of the meta data map.
> TEnum fields are usually converted to 'int' using getValue.
> When converting back to Thrift, those 'int' need to be converted back to TEnum.
> The generated TEnum classes have a static method findByValue, but as it is static it is not defined in the TEnum interface and therefore can only be accessed using reflection if the enum type is not know before runtime.
> By adding a simple 'public TEnum getByValue(int value)' method in the TEnum interface, we could get rid of the reflection part. 

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


[jira] Commented: (THRIFT-949) Modify the TEnum interface so it defines a method similar to findByValue

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919320#action_12919320 ] 

Bryan Duxbury commented on THRIFT-949:
--------------------------------------

Wouldn't this mean you'd have to have an instance of the TEnum-inheriting class in order to get one of it's neighbors? How will you get the first instance?

> Modify the TEnum interface so it defines a method similar to findByValue
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-949
>                 URL: https://issues.apache.org/jira/browse/THRIFT-949
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler, Java - Library
>            Reporter: Mathias Herberts
>            Priority: Trivial
>
> In some cases, Thrift instances are converted into more simple types. This is made easy by the existence of the meta data map.
> TEnum fields are usually converted to 'int' using getValue.
> When converting back to Thrift, those 'int' need to be converted back to TEnum.
> The generated TEnum classes have a static method findByValue, but as it is static it is not defined in the TEnum interface and therefore can only be accessed using reflection if the enum type is not know before runtime.
> By adding a simple 'public TEnum getByValue(int value)' method in the TEnum interface, we could get rid of the reflection part. 

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


[jira] Updated: (THRIFT-949) Modify the TEnum interface so it defines a method similar to findByValue

Posted by "Mathias Herberts (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-949?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mathias Herberts updated THRIFT-949:
------------------------------------

    Attachment: THRIFT-949-1

Adds TEnumHelper.java and associated tests.

> Modify the TEnum interface so it defines a method similar to findByValue
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-949
>                 URL: https://issues.apache.org/jira/browse/THRIFT-949
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler, Java - Library
>            Reporter: Mathias Herberts
>            Priority: Trivial
>         Attachments: THRIFT-949-1
>
>
> In some cases, Thrift instances are converted into more simple types. This is made easy by the existence of the meta data map.
> TEnum fields are usually converted to 'int' using getValue.
> When converting back to Thrift, those 'int' need to be converted back to TEnum.
> The generated TEnum classes have a static method findByValue, but as it is static it is not defined in the TEnum interface and therefore can only be accessed using reflection if the enum type is not know before runtime.
> By adding a simple 'public TEnum getByValue(int value)' method in the TEnum interface, we could get rid of the reflection part. 

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