From 3bd50c1ea09eac6cb2121b46087c9643b6086d57 Mon Sep 17 00:00:00 2001 From: Tihomir Mateev Date: Mon, 5 Aug 2024 17:05:45 +0300 Subject: [PATCH] Addressed Ali's comment on calling the .getDynamicMap only once --- .../parsers/tracking/TrackingInfoParser.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/lettuce/core/api/parsers/tracking/TrackingInfoParser.java b/src/main/java/io/lettuce/core/api/parsers/tracking/TrackingInfoParser.java index eaa5da890c..38a92c0ee3 100644 --- a/src/main/java/io/lettuce/core/api/parsers/tracking/TrackingInfoParser.java +++ b/src/main/java/io/lettuce/core/api/parsers/tracking/TrackingInfoParser.java @@ -50,10 +50,7 @@ private TrackingInfoParser() { * @return an {@link TrackingInfo} instance */ public static TrackingInfo parse(DynamicAggregateData trackinginfoOutput) { - - verifyStructure(trackinginfoOutput); - - Map data = trackinginfoOutput.getDynamicMap(); + Map data = verifyStructure(trackinginfoOutput); Set flags = ((DynamicAggregateData) data.get(CommandKeyword.FLAGS.toString().toLowerCase())).getDynamicSet(); Long clientId = (Long) data.get(CommandKeyword.REDIRECT.toString().toLowerCase()); List prefixes = ((DynamicAggregateData) data.get(CommandKeyword.PREFIXES.toString().toLowerCase())).getDynamicList(); @@ -73,19 +70,25 @@ public static TrackingInfo parse(DynamicAggregateData trackinginfoOutput) { return new TrackingInfo(parsedFlags, clientId, parsedPrefixes); } - private static void verifyStructure(DynamicAggregateData trackinginfoOutput) { + private static Map verifyStructure(DynamicAggregateData trackinginfoOutput) { - if (trackinginfoOutput == null || trackinginfoOutput.getDynamicMap().isEmpty()) { - throw new IllegalArgumentException("trackinginfoOutput must not be null or empty"); + if (trackinginfoOutput == null) { + throw new IllegalArgumentException("Failed while parsing CLIENT TRACKINGINFO: trackinginfoOutput must not be null"); } Map data = trackinginfoOutput.getDynamicMap(); + if (data == null || data.isEmpty()) { + throw new IllegalArgumentException("Failed while parsing CLIENT TRACKINGINFO: data must not be null or empty"); + } if (!data.containsKey(CommandKeyword.FLAGS.toString().toLowerCase()) || !data.containsKey(CommandKeyword.REDIRECT.toString().toLowerCase()) || !data.containsKey(CommandKeyword.PREFIXES.toString().toLowerCase())) { - throw new IllegalArgumentException("trackinginfoOutput has missing flags"); + throw new IllegalArgumentException( + "Failed while parsing CLIENT TRACKINGINFO: trackinginfoOutput has missing flags"); } + + return data; } }