qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PROTON-1352) Trivial casting from UnsignedByte to ReceiverSettleMode and SenderSettleMode
Date Wed, 16 Nov 2016 15:37:58 GMT

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

ASF GitHub Bot commented on PROTON-1352:
----------------------------------------

Github user ppatierno commented on a diff in the pull request:

    https://github.com/apache/qpid-proton/pull/89#discussion_r88260293
  
    --- Diff: proton-j/src/main/java/org/apache/qpid/proton/amqp/transport/ReceiverSettleMode.java
---
    @@ -25,13 +25,32 @@
     
     import org.apache.qpid.proton.amqp.UnsignedByte;
     
    +import java.util.HashMap;
    +import java.util.Map;
    +
     public enum ReceiverSettleMode
     {
    -    FIRST, SECOND;
    +    FIRST(0),
    +    SECOND(1);
    +
    +    private UnsignedByte value;
    +    private static Map<UnsignedByte, ReceiverSettleMode> map = new HashMap<>();
    +
    +    private ReceiverSettleMode(int value) {
    +        this.value = UnsignedByte.valueOf((byte)value);
    +    }
     
    -    public UnsignedByte getValue()
    -    {
    -        return UnsignedByte.valueOf((byte)ordinal());
    +    static {
    +        for (ReceiverSettleMode mode: ReceiverSettleMode.values()) {
    +            map.put(mode.value, mode);
    +        }
         }
     
    +    public static ReceiverSettleMode valueOf(UnsignedByte value) {
    +        return map.get(value);
    --- End diff --
    
    It's true but it works in our case just because enum values go from 0,1 to 2 (so they
are good as indexes in the array). If one of the value was 100 for example, using value.intValue()
as index for the values() array will throw an out of bound exception. Your suggestion was
the way I was using outside this enum in my application before opening the PR for doing the
cast. :-) 


> Trivial casting from UnsignedByte to ReceiverSettleMode and SenderSettleMode
> ----------------------------------------------------------------------------
>
>                 Key: PROTON-1352
>                 URL: https://issues.apache.org/jira/browse/PROTON-1352
>             Project: Qpid Proton
>          Issue Type: Improvement
>          Components: proton-j
>    Affects Versions: 0.15.0
>            Reporter: Paolo Patierno
>            Priority: Minor
>
> Currently it's not trivial at application level execute casting from UnsignedByte to
SenderSettleMode or ReceiverSettleMode.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Mime
View raw message