From cb140ba93fc8847691a3234eb79b1972aabfbefb Mon Sep 17 00:00:00 2001 From: Alphonse Mariya Date: Mon, 26 Nov 2018 18:41:30 +0100 Subject: [PATCH] Use isEmpty() instead of comparing size() --- src/Coordinator.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Coordinator.java b/src/Coordinator.java index 1e3ac2d..9a242bf 100644 --- a/src/Coordinator.java +++ b/src/Coordinator.java @@ -269,7 +269,8 @@ private void checkVotes() throws IOException { } - if(socketsToRemove.size() > 0) this.removeSockets(socketsToRemove); + if (!socketsToRemove.isEmpty()) + this.removeSockets(socketsToRemove); if (!illegalAnswer) { @@ -293,7 +294,7 @@ private void checkVotes() throws IOException { } - if(this.sockets.size() == 0) { + if (this.sockets.isEmpty()) { this.coordinatorLog.log("END", false, true, true); this.failedSubordinatesLog.emptyLog(); @@ -303,7 +304,8 @@ private void checkVotes() throws IOException { Printer.print("=============== END OF PHASE 1 =================\n", "blue"); - if (this.sockets.size() > 0) this.phaseTwo(decision); + if (!this.sockets.isEmpty()) + this.phaseTwo(decision); } else { @@ -401,7 +403,7 @@ private void checkAcknowledgements(List subordinatesToBeChecked) throws } - if (crashedSubordinateIndices.size() > 0 && !invalidAcknowledgement) { + if (!crashedSubordinateIndices.isEmpty() && !invalidAcknowledgement) { Printer.print("\nSubordinate crash(es) detected!\n", "red"); @@ -486,11 +488,13 @@ private void recoveryProcess(List crashedSubordinateIndices) throws IOE } } - if(unreachableSubordinatesIndices.size() > 0) this.recoveryProcess(unreachableSubordinatesIndices); + if (!unreachableSubordinatesIndices.isEmpty()) + this.recoveryProcess(unreachableSubordinatesIndices); Printer.print("", "white"); - if(reachableSubordinatesIndices.size() > 0) this.checkAcknowledgements(reachableSubordinatesIndices); + if (!reachableSubordinatesIndices.isEmpty()) + this.checkAcknowledgements(reachableSubordinatesIndices); }