From 771263eef69bb25952c7ecb8f01946bfc42b2da0 Mon Sep 17 00:00:00 2001 From: caoyixiong Date: Thu, 27 Jun 2019 19:50:19 +0800 Subject: [PATCH] fix --- .../alibaba/nacos/client/naming/utils/Chooser.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java b/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java index 883402184..51e4e6b22 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/utils/Chooser.java @@ -99,13 +99,13 @@ public class Chooser { } public void refresh() { - Double originWeightSum = (double)0; + Double originWeightSum = (double) 0; for (Pair item : itemsWithWeight) { double weight = item.weight(); //ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest - if (!(weight > 0)) { + if (weight <= 0) { continue; } @@ -124,7 +124,7 @@ public class Chooser { for (Pair item : itemsWithWeight) { double singleWeight = item.weight(); //ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest - if (!(singleWeight > 0)) { + if (singleWeight <= 0) { continue; } exactWeights[index++] = singleWeight / originWeightSum; @@ -139,9 +139,9 @@ public class Chooser { double doublePrecisionDelta = 0.0001; if (index == 0 || (Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) { - throw new IllegalStateException( - "Cumulative Weight caculate wrong , the sum of probabilities does not equals 1."); + return; } + throw new IllegalStateException("Cumulative Weight caculate wrong , the sum of probabilities does not equals 1."); } @Override @@ -164,7 +164,7 @@ public class Chooser { if (!(other.getClass().getGenericInterfaces()[0].equals(this.getClass().getGenericInterfaces()[0]))) { return false; } - Ref otherRef = (Ref)other; + Ref otherRef = (Ref) other; if (itemsWithWeight == null) { if (otherRef.itemsWithWeight != null) { return false; @@ -197,7 +197,7 @@ public class Chooser { return false; } - Chooser otherChooser = (Chooser)other; + Chooser otherChooser = (Chooser) other; if (this.uniqueKey == null) { if (otherChooser.getUniqueKey() != null) { return false;