diff --git a/hekate-core/src/main/java/io/hekate/cluster/ClusterFilters.java b/hekate-core/src/main/java/io/hekate/cluster/ClusterFilters.java index b5ae7ef78..5d7e2d843 100644 --- a/hekate-core/src/main/java/io/hekate/cluster/ClusterFilters.java +++ b/hekate-core/src/main/java/io/hekate/cluster/ClusterFilters.java @@ -166,17 +166,15 @@ public static ClusterFilter forNode(ClusterNodeId nodeId) { ArgAssert.notNull(nodeId, "Node"); return nodes -> { - if (nodes.isEmpty()) { - return emptyList(); - } else { + if (!nodes.isEmpty()) { for (ClusterNode node : nodes) { if (node.id().equals(nodeId)) { return singletonList(node); } } - - return emptyList(); } + + return emptyList(); }; } diff --git a/hekate-core/src/main/java/io/hekate/cluster/internal/gossip/GossipCommManager.java b/hekate-core/src/main/java/io/hekate/cluster/internal/gossip/GossipCommManager.java index a71213022..3a8a018bd 100644 --- a/hekate-core/src/main/java/io/hekate/cluster/internal/gossip/GossipCommManager.java +++ b/hekate-core/src/main/java/io/hekate/cluster/internal/gossip/GossipCommManager.java @@ -183,16 +183,12 @@ public void send(GossipMessage msg, Runnable onComplete) { } callback.onSendFailure(sent, err.get()); - - if (onComplete != null) { - onComplete.run(); - } } else { callback.onSendSuccess(sent); + } - if (onComplete != null) { - onComplete.run(); - } + if (onComplete != null) { + onComplete.run(); } }); } diff --git a/hekate-core/src/main/java/io/hekate/codec/CodecUtils.java b/hekate-core/src/main/java/io/hekate/codec/CodecUtils.java index 8f2fe2807..59a286831 100644 --- a/hekate-core/src/main/java/io/hekate/codec/CodecUtils.java +++ b/hekate-core/src/main/java/io/hekate/codec/CodecUtils.java @@ -289,12 +289,12 @@ public static void writeBigDecimal(BigDecimal val, DataOutput out) throws IOExce if (bits <= 63) { if (scale == 0) { out.writeByte(DECIMAL_SMALL_UNSCALED); - writeVarLong(unscaled.longValue(), out); } else { out.writeByte(DECIMAL_SMALL_SCALED); writeVarIntUnsigned(scale, out); - writeVarLong(unscaled.longValue(), out); } + + writeVarLong(unscaled.longValue(), out); } else { byte[] bytes = unscaled.toByteArray(); diff --git a/hekate-core/src/main/java/io/hekate/lock/internal/DefaultLockRegion.java b/hekate-core/src/main/java/io/hekate/lock/internal/DefaultLockRegion.java index 06777284b..e5e547d78 100644 --- a/hekate-core/src/main/java/io/hekate/lock/internal/DefaultLockRegion.java +++ b/hekate-core/src/main/java/io/hekate/lock/internal/DefaultLockRegion.java @@ -315,8 +315,6 @@ public LockControllerClient lock(long timeout, DistributedLock lock, AsyncLockCa } lockClient.unlockFuture().complete(true); - - return lockClient; } else { if (activeMapping == null) { if (DEBUG) { @@ -337,9 +335,9 @@ public LockControllerClient lock(long timeout, DistributedLock lock, AsyncLockCa lockClient.becomeLocking(); } - - return lockClient; } + + return lockClient; } finally { readLock.unlock(); } @@ -512,7 +510,7 @@ public void processMigrationPrepare(Message msg) { } else if (key.isSameCoordinator(localNode)) { replyMigrationOk(msg); - if (migrationKey != null && key.equals(migrationKey) && key.isSameTopology(latestMapping)) { + if (key.equals(migrationKey) && key.isSameTopology(latestMapping)) { if (DEBUG) { log.debug("Coordinator received migration prepare request [request={}]", request); } diff --git a/hekate-core/src/main/java/io/hekate/util/format/ToString.java b/hekate-core/src/main/java/io/hekate/util/format/ToString.java index 7fe00ae78..ace8f2865 100644 --- a/hekate-core/src/main/java/io/hekate/util/format/ToString.java +++ b/hekate-core/src/main/java/io/hekate/util/format/ToString.java @@ -212,12 +212,12 @@ public String format(Class alias, boolean propertiesOnly, Object obj) throws if (alias == null) { realName = name; - realApproxSize = approxSize + realName.length() + 2/* this is for '[' ']' */; } else { realName = alias.getSimpleName(); - realApproxSize = approxSize + realName.length() + 2/* this is for '[' ']' */; } + realApproxSize = approxSize + realName.length() + 2/* this is for '[' ']' */; + buf = new StringBuilder(realApproxSize); buf.append(realName); diff --git a/hekate-core/src/test/java/io/hekate/cluster/internal/gossip/GossipManagerTest.java b/hekate-core/src/test/java/io/hekate/cluster/internal/gossip/GossipManagerTest.java index 21d11dd8f..311223d49 100644 --- a/hekate-core/src/test/java/io/hekate/cluster/internal/gossip/GossipManagerTest.java +++ b/hekate-core/src/test/java/io/hekate/cluster/internal/gossip/GossipManagerTest.java @@ -949,7 +949,7 @@ private void gossipTillSameVersion(List nodes) { int i = 0; - while (true) { + do { say("Round: " + i); i++; @@ -967,11 +967,7 @@ private void gossipTillSameVersion(List nodes) { processGossipConversation(to, mgr, gossip); } - - if (isSameGossipVersion(nodes)) { - break; - } - } + } while (!isSameGossipVersion(nodes)); } private void gossipTillConvergence(List nodes) { diff --git a/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverAggregateTest.java b/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverAggregateTest.java index a8079d028..0ca9beca9 100644 --- a/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverAggregateTest.java +++ b/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverAggregateTest.java @@ -105,13 +105,11 @@ public void testDelay() throws Exception { long prevTime = 0; for (Long time : series) { - if (prevTime == 0) { - prevTime = time; - } else { + if (prevTime != 0) { assertTrue(time - prevTime >= failoverDelay); - - prevTime = time; } + + prevTime = time; } }); diff --git a/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverRequestTest.java b/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverRequestTest.java index 819520de2..54caa8072 100644 --- a/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverRequestTest.java +++ b/hekate-core/src/test/java/io/hekate/messaging/internal/FailoverRequestTest.java @@ -238,13 +238,11 @@ private void doFailoverDelay(MessagingChannel channel) throws Exception long prevTime = 0; for (Long time : times) { - if (prevTime == 0) { - prevTime = time; - } else { + if (prevTime != 0) { assertTrue(time - prevTime >= TimeUnit.MILLISECONDS.toNanos(failoverDelay)); - - prevTime = time; } + + prevTime = time; } } diff --git a/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchClientRequestCaptor.java b/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchClientRequestCaptor.java index bcb34f07c..b2b355b35 100644 --- a/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchClientRequestCaptor.java +++ b/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchClientRequestCaptor.java @@ -22,7 +22,7 @@ import java.util.List; class CloudWatchClientRequestCaptor implements CloudWatchMetricsPublisher.CloudWatchClient { - private List requests = Collections.synchronizedList(new ArrayList<>()); + private final List requests = Collections.synchronizedList(new ArrayList<>()); @Override public void putMetrics(PutMetricDataRequest request) { diff --git a/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchMetricsConfigTest.java b/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchMetricsConfigTest.java index beeb9a4e5..21a1c49fa 100644 --- a/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchMetricsConfigTest.java +++ b/hekate-metrics-cloudwatch/src/test/java/io/hekate/metrics/cloudwatch/CloudWatchMetricsConfigTest.java @@ -26,7 +26,7 @@ import static org.junit.Assert.assertSame; public class CloudWatchMetricsConfigTest extends HekateTestBase { - private CloudWatchMetricsConfig cfg = new CloudWatchMetricsConfig(); + private final CloudWatchMetricsConfig cfg = new CloudWatchMetricsConfig(); @Test public void testNamespace() {