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/TotemProtocolEncoder.java | 43 +++++++++++----------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/main/java/org/traccar/protocol/TotemProtocolEncoder.java') diff --git a/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java b/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java index 4b22ade03..fea9e2d2c 100644 --- a/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java @@ -28,28 +28,27 @@ public class TotemProtocolEncoder extends StringProtocolEncoder { } public static String formatContent(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return String.format("%s,%s", - command.getAttributes().get(Command.KEY_DEVICE_PASSWORD), - command.getAttributes().get(Command.KEY_DATA) - ); - case Command.TYPE_REBOOT_DEVICE: - return String.format("%s,006", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); - case Command.TYPE_FACTORY_RESET: - return String.format("%s,007", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); - case Command.TYPE_GET_VERSION: - return String.format("%s,056", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); - case Command.TYPE_POSITION_SINGLE: - return String.format("%s,012", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); - // Assuming PIN 8 (Output C) is the power wire, like manual says but it can be PIN 5,7,8 - case Command.TYPE_ENGINE_STOP: - return String.format("%s,025,C,1", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); - case Command.TYPE_ENGINE_RESUME: - return String.format("%s,025,C,0", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> + String.format( + "%s,%s", + command.getAttributes().get(Command.KEY_DEVICE_PASSWORD), + command.getAttributes().get(Command.KEY_DATA)); + case Command.TYPE_REBOOT_DEVICE -> + String.format("%s,006", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); + case Command.TYPE_FACTORY_RESET -> + String.format("%s,007", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); + case Command.TYPE_GET_VERSION -> + String.format("%s,056", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); + case Command.TYPE_POSITION_SINGLE -> + String.format("%s,012", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); + // Assuming PIN 8 (Output C) is the power wire, like manual says, but it can be PIN 5,7,8 + case Command.TYPE_ENGINE_STOP -> + String.format("%s,025,C,1", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); + case Command.TYPE_ENGINE_RESUME -> + String.format("%s,025,C,0", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD)); + default -> null; + }; } @Override -- cgit v1.2.3