Skip to content

Commit

Permalink
Code cleanup (extract common parts from if statements, etc).
Browse files Browse the repository at this point in the history
  • Loading branch information
syermakov committed Apr 20, 2018
1 parent e79c2d1 commit e345120
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions hekate-core/src/main/java/io/hekate/codec/CodecUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ public LockControllerClient lock(long timeout, DistributedLock lock, AsyncLockCa
}

lockClient.unlockFuture().complete(true);

return lockClient;
} else {
if (activeMapping == null) {
if (DEBUG) {
Expand All @@ -337,9 +335,9 @@ public LockControllerClient lock(long timeout, DistributedLock lock, AsyncLockCa

lockClient.becomeLocking();
}

return lockClient;
}

return lockClient;
} finally {
readLock.unlock();
}
Expand Down Expand Up @@ -512,7 +510,7 @@ public void processMigrationPrepare(Message<LockProtocol> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions hekate-core/src/main/java/io/hekate/util/format/ToString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ private void gossipTillSameVersion(List<GossipManager> nodes) {

int i = 0;

while (true) {
do {
say("Round: " + i);

i++;
Expand All @@ -967,11 +967,7 @@ private void gossipTillSameVersion(List<GossipManager> nodes) {

processGossipConversation(to, mgr, gossip);
}

if (isSameGossipVersion(nodes)) {
break;
}
}
} while (!isSameGossipVersion(nodes));
}

private void gossipTillConvergence(List<GossipManager> nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,11 @@ private void doFailoverDelay(MessagingChannel<String> 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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;

class CloudWatchClientRequestCaptor implements CloudWatchMetricsPublisher.CloudWatchClient {
private List<PutMetricDataRequest> requests = Collections.synchronizedList(new ArrayList<>());
private final List<PutMetricDataRequest> requests = Collections.synchronizedList(new ArrayList<>());

@Override
public void putMetrics(PutMetricDataRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e345120

Please sign in to comment.