From d0536ccbc1b7234784c5e48288bbac00a60ef821 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Jul 2024 07:33:16 -0700 Subject: Update switch statements --- .../org/traccar/protocol/TaipProtocolDecoder.java | 65 ++++++++-------------- 1 file changed, 22 insertions(+), 43 deletions(-) (limited to 'src/main/java/org/traccar/protocol/TaipProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java b/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java index 448d7ffca..bfa8b10c2 100644 --- a/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java @@ -122,30 +122,21 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(int value) { - switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x02: - return Position.ALARM_POWER_CUT; - default: - return null; - } + return switch (value) { + case 0x01 -> Position.ALARM_SOS; + case 0x02 -> Position.ALARM_POWER_CUT; + default -> null; + }; } private String decodeAlarm2(int value) { - switch (value) { - case 22: - return Position.ALARM_ACCELERATION; - case 23: - return Position.ALARM_BRAKING; - case 24: - return Position.ALARM_ACCIDENT; - case 26: - case 28: - return Position.ALARM_CORNERING; - default: - return null; - } + return switch (value) { + case 22 -> Position.ALARM_ACCELERATION; + case 23 -> Position.ALARM_BRAKING; + case 24 -> Position.ALARM_ACCIDENT; + case 26, 28 -> Position.ALARM_CORNERING; + default -> null; + }; } @Override @@ -273,7 +264,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { String key = attribute.substring(0, index).toLowerCase(); String value = attribute.substring(index + 1); switch (key) { - case "id": + case "id" -> { uniqueId = value; deviceSession = getDeviceSession(channel, remoteAddress, value); if (deviceSession != null) { @@ -282,31 +273,19 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { if (messageIndex == null) { indexFirst = false; } - break; - case "io": + } + case "io" -> { position.set(Position.KEY_IGNITION, BitUtil.check(value.charAt(0) - '0', 0)); position.set(Position.KEY_CHARGE, BitUtil.check(value.charAt(0) - '0', 1)); position.set(Position.KEY_OUTPUT, value.charAt(1) - '0'); position.set(Position.KEY_INPUT, value.charAt(2) - '0'); - break; - case "ix": - position.set(Position.PREFIX_IO + 1, value); - break; - case "ad": - position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value)); - break; - case "sv": - position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); - break; - case "bl": - position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001); - break; - case "vo": - position.set(Position.KEY_ODOMETER, Long.parseLong(value)); - break; - default: - position.set(key, value); - break; + } + case "ix" -> position.set(Position.PREFIX_IO + 1, value); + case "ad" -> position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value)); + case "sv" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + case "bl" -> position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001); + case "vo" -> position.set(Position.KEY_ODOMETER, Long.parseLong(value)); + default -> position.set(key, value); } } else if (attribute.startsWith("#")) { messageIndex = attribute; -- cgit v1.2.3