From 1581a014a27b7f0534fe4db89d9d30fd39dabcbc Mon Sep 17 00:00:00 2001 From: "DESKTOP-MIRQB93\\user" Date: Wed, 5 Apr 2023 17:22:21 +0800 Subject: [PATCH] refine with static list 1. refine with static varirable, instead of compare value one by one --- .../util/earlybird/EarlybirdResponseUtil.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/java/com/twitter/search/common/util/earlybird/EarlybirdResponseUtil.java b/src/java/com/twitter/search/common/util/earlybird/EarlybirdResponseUtil.java index 51c81edfa..eda6533e4 100644 --- a/src/java/com/twitter/search/common/util/earlybird/EarlybirdResponseUtil.java +++ b/src/java/com/twitter/search/common/util/earlybird/EarlybirdResponseUtil.java @@ -22,6 +22,12 @@ import com.twitter.search.earlybird.thrift.ThriftTweetSource; /** Utility methods that work on EarlybirdResponses. */ public final class EarlybirdResponseUtil { + + static private List successfulResponseCodeList + = Arrays.asList(EarlybirdResponseCode.SUCCESS, + EarlybirdResponseCode.TIER_SKIPPED, + EarlybirdResponseCode.REQUEST_BLOCKED_ERROR); + private EarlybirdResponseUtil() { } @@ -77,9 +83,7 @@ public final class EarlybirdResponseUtil { * Returns if the response should be considered failed for purposes of stats and logging. */ public static boolean responseConsideredFailed(EarlybirdResponseCode code) { - return code != EarlybirdResponseCode.SUCCESS - && code != EarlybirdResponseCode.REQUEST_BLOCKED_ERROR - && code != EarlybirdResponseCode.TIER_SKIPPED; + return !successfulResponseCodeList.contains(code); } /** @@ -171,9 +175,7 @@ public final class EarlybirdResponseUtil { */ public static boolean isSuccessfulResponse(EarlybirdResponse response) { return response != null - && (response.getResponseCode() == EarlybirdResponseCode.SUCCESS - || response.getResponseCode() == EarlybirdResponseCode.TIER_SKIPPED - || response.getResponseCode() == EarlybirdResponseCode.REQUEST_BLOCKED_ERROR); + && successfulResponseCodeList.contains(response.getResponseCode()); } /**