【问题标题】:How do I change these to a valid switch statement?如何将这些更改为有效的 switch 语句?
【发布时间】:2020-01-31 02:40:44
【问题描述】:

所以,我有从以前开发的类中复制的 switch 语句,它们显然不是有效的语句。如何将它们更改为有效代码?它们如下:

    switch($SWITCH_TABLE$hotsdk_a$communication$HotInterface$HotResultData$val_rcv_kind()[HotInterface.HotResultData.val_rcv_kind.valueOf(hotResultData.rcv_kind).ordinal()]){
            case 1:
            case 2:
    } //valueOf is a method in the enum

    switch($SWITCH_TABLE$hotsdk_a$game$AppMessage()[AppMessage.valueOf(rSendMsg.what).ordinal()]){ 
            case 1:
            case 2:
    } //rSendMsg.what is obtained from the Message returned by the first switch case above

    switch($SWITCH_TABLE$hotsdk_a$communication$HOTDeviceInterface$DataFormat$Command()[command.ordinal()]){
            case 1:
            case 2:
    }

,其中 AppMessageval_rcv_kindcommand 是枚举。

val_rcv_kind

    public static enum val_rcv_kind {
        rcv_Beacon(0),
        rcv_Measuring(1),
        rcv_FwVer(2),
        rcv_AGC(3),
        rcv_GetGain(4),
        rcv_GetLed(5),
        rcv_SetGain(6),
        rcv_Stop(7);

        private int value;

        private val_rcv_kind(int i) {
            this.value = i;
        }

        public int getValue() {
            return this.value;
        }

        public static HotInterface.HotResultData.val_rcv_kind valueOf(int i) {
            HotInterface.HotResultData.val_rcv_kind[] var4;
            int var3 = (var4 = values()).length;

            for(int var2 = 0; var2 < var3; ++var2) {
                HotInterface.HotResultData.val_rcv_kind kind = var4[var2];
                if (kind.getValue() == i) {
                    return kind;
                }
            }

            return null;
        }
    }

命令

    public static enum Command {
        ConfigureProbe("!AT C"),
        ResetProbe("!AT D"),
        StartAGC("!AT G"),
        GetAGCParameter("!AT P"),
        GetData("!AT R 0"),
        GetDebugData("!AT R 1"),
        StopData("!AT S"),
        GetMGCParameter("!AT M"),
        GetLEDParameter("!AT L");

        private String value;

        private Command(String command) {
            this.value = command;
        }

        public String getValue() {
            return this.value;
        }
    }

AppMessage

    public enum AppMessage {
        StartButtonClicked(0),
        StopButtonClicked(1),
        UpdateView(10),
        BluetoothConnected(100),
        BluetoothDisconnected(101),
        BluetoothConnectionFailed(102),
        BluetoothNotified(103),
        DataReceived(111),
        DebugDataReceived(112),
        BeaconReceived(113),
        BluetoothServiceConnected(500),
        DebugPutError(900),
        OnEnterWaiting(1000),
        AGCStarted(1101),
        AGCSucceeded(1102),
        AGCFailed(1103),
        AGCOnTheWay(1104),
        AGCParameterReceived(1110),
        ProbeCheckStarted(1201),
        ProbeCheckSucceeded(1202),
        ProbeCheckFailed(1203),
        CalibrationStarted(1301),
        CalibrationSucceeded(1302),
        CalibrationFailed(1303),
        MeasurementStarted(1401),
        MeasurementStopped(1402),
        OnMarkingEvent(1500),
        SetGainSucceeded(1601),
        SetGainFailed(1602),
        GetGainReceived(1603),
        SetLedSucceeded(1701),
        SetLedFailed(1702),
        GetLedReceived(1703),
        StopMeasuring(1801),
        SetGainEnd(1802),
        LoginReceivedCallback(1900),
        SessionReceivedCallback(1901),
        DataReceivedCallback(1911),
        CoinReceivedCallback(1921),
        StartGame00(2000),
        StartGame01(2001),
        StartGame02(2002),
        StartGame03(2003),
        StartGame04(2004),
        StartGame05(2005),
        StartGame06(2006),
        StartGame07(2007),
        StartGame08(2008),
        StartGame09(2009),
        GetItem00(9000),
        GetItem01(9001),
        GetItem02(9002),
        GetItem03(9003),
        GetItem04(9004);

        private final int value;

        AppMessage(int i) {
            this.value = i;
        }

        public int getValue() {
            return this.value;
        }

        public static AppMessage valueOf(int i) {
            AppMessage[] var4;
            int var3 = (var4 = values()).length;

            for(int var2 = 0; var2 < var3; ++var2) {
                AppMessage event = var4[var2];
                if (event.getValue() == i) {
                    return event;
                }
            }

            return null;
        }
    }

谁能帮我解决这个问题。我需要尽快完成我的项目。

【问题讨论】:

    标签: java enums switch-statement


    【解决方案1】:

    这看起来像是反汇编代码,来自不理解枚举的反汇编程序。

    我相信第一个应该是从:

    //                                                                                                               ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    switch($SWITCH_TABLE$hotsdk_a$communication$HotInterface$HotResultData$val_rcv_kind()[HotInterface.HotResultData.val_rcv_kind.valueOf(hotResultData.rcv_kind).ordinal()]){
        case 1:
        case 2:
    }
    

    到:

    switch (val_rcv_kind.valueOf(hotResultData.rcv_kind)) {
        case rcv_Measuring:
        case rcv_FwVer:
    }
    

    大概hotResultData.rcv_kindString

    从这个例子中你应该可以自己做另外两个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      相关资源
      最近更新 更多