From e9fb15e66393817109b730752a79ccea2d7e10f2 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 23 Jun 2016 18:19:20 +0200 Subject: [PATCH] chase a few more rules --- examples/java/app/bittorrent/Connection.java | 2 +- examples/java/app/bittorrent/MessageTask.java | 2 +- examples/java/app/bittorrent/Peer.java | 2 +- examples/java/app/pingpong/Sender.java | 2 +- examples/java/cloud/migration/Test.java | 1 - examples/java/dht/chord/Node.java | 43 +++++++++---------- examples/java/trace/pingpong/Sender.java | 2 +- .../java/org/simgrid/msg/RngStream.java | 4 +- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/examples/java/app/bittorrent/Connection.java b/examples/java/app/bittorrent/Connection.java index 3143889710..668283a762 100644 --- a/examples/java/app/bittorrent/Connection.java +++ b/examples/java/app/bittorrent/Connection.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Connection { protected int id; - protected char bitfield[]; + protected char[] bitfield; protected String mailbox; // Indicates if we are interested in something this peer has protected boolean amInterested = false; diff --git a/examples/java/app/bittorrent/MessageTask.java b/examples/java/app/bittorrent/MessageTask.java index 4ff0204a80..d0bac8fa16 100644 --- a/examples/java/app/bittorrent/MessageTask.java +++ b/examples/java/app/bittorrent/MessageTask.java @@ -24,7 +24,7 @@ public class MessageTask extends Task { protected String issuerHostname; protected String mailbox; protected int peerId; - protected char bitfield[]; + protected char[] bitfield; protected int index; protected int blockIndex; protected int blockLength; diff --git a/examples/java/app/bittorrent/Peer.java b/examples/java/app/bittorrent/Peer.java index f20881b15b..58b4b489d4 100644 --- a/examples/java/app/bittorrent/Peer.java +++ b/examples/java/app/bittorrent/Peer.java @@ -365,7 +365,7 @@ public class Peer extends Process { * @brief Updates the list of who has a piece from a bitfield * @param bitfield bitfield */ - private void updatePiecesCountFromBitfield(char bitfield[]) { + private void updatePiecesCountFromBitfield(char[] bitfield) { for (int i = 0; i < Common.FILE_PIECES; i++) { if (bitfield[i] == '1') { piecesCount[i]++; diff --git a/examples/java/app/pingpong/Sender.java b/examples/java/app/pingpong/Sender.java index ab23c66c13..5f00d6f398 100644 --- a/examples/java/app/pingpong/Sender.java +++ b/examples/java/app/pingpong/Sender.java @@ -25,7 +25,7 @@ public class Sender extends Process { int hostCount = args.length; Msg.info("host count: " + hostCount); - String mailboxes[] = new String[hostCount]; + String[] mailboxes = new String[hostCount]; double time; double computeDuration = 0; PingPongTask task; diff --git a/examples/java/cloud/migration/Test.java b/examples/java/cloud/migration/Test.java index 279917e83a..d3d6a09aa1 100644 --- a/examples/java/cloud/migration/Test.java +++ b/examples/java/cloud/migration/Test.java @@ -8,7 +8,6 @@ package cloud.migration; import java.util.ArrayList; import java.util.List; - import org.simgrid.msg.*; import org.simgrid.msg.Process; diff --git a/examples/java/dht/chord/Node.java b/examples/java/dht/chord/Node.java index 021610855c..275c75ec2c 100644 --- a/examples/java/dht/chord/Node.java +++ b/examples/java/dht/chord/Node.java @@ -22,7 +22,7 @@ public class Node extends Process { protected Comm commReceive; ///Last time I changed a finger or my predecessor protected double lastChangeDate; - int fingers[]; + int[] fingers; public Node(Host host, String name, String[] args) { super(host,name,args); @@ -36,7 +36,7 @@ public class Node extends Process { } double initTime = Msg.getClock(); int i; - boolean joinSuccess = false; + boolean joinSuccess; double deadline; double nextStabilizeDate = initTime + Common.PERIODIC_STABILIZE_DELAY; @@ -55,7 +55,7 @@ public class Node extends Process { //First node if (args.length == 2) { - deadline = Integer.valueOf(args[1]); + deadline = Integer.parseInt(args[1]); create(); joinSuccess = true; } else { @@ -115,13 +115,13 @@ public class Node extends Process { Msg.debug("Receiving a 'Find Successor' request from " + fTask.issuerHostName + " for id " + fTask.requestId); // is my successor the successor? if (isInInterval(fTask.requestId, this.id + 1, fingers[0])) { - //Msg.info("Send the request to " + fTask.answerTo + " with answer " + fingers[0]); + Msg.debug("Send the request to " + fTask.answerTo + " with answer " + fingers[0]); FindSuccessorAnswerTask answer = new FindSuccessorAnswerTask(getHost().getName(), mailbox, fingers[0]); answer.dsend(fTask.answerTo); } else { // otherwise, forward the request to the closest preceding finger in my table int closest = closestPrecedingNode(fTask.requestId); - //Msg.info("Forward the request to " + closest); + Msg.debug("Forward the request to " + closest); fTask.dsend(Integer.toString(closest)); } } else if (task instanceof GetPredecessorTask) { @@ -241,11 +241,11 @@ public class Node extends Process { int remoteFindSuccessor(int askTo, int id) { int successor = -1; boolean stop = false; - String mailbox = Integer.toString(askTo); + String askToMailbox = Integer.toString(askTo); Task sendTask = new FindSuccessorTask(getHost().getName(), this.mailbox, id); - Msg.debug("Sending a 'Find Successor' request to " + mailbox + " for id " + id); + Msg.debug("Sending a 'Find Successor' request to " + askToMailbox + " for id " + id); try { - sendTask.send(mailbox, Common.TIMEOUT); + sendTask.send(askToMailbox, Common.TIMEOUT); do { if (commReceive == null) { commReceive = Task.irecv(this.mailbox); @@ -324,10 +324,10 @@ public class Node extends Process { void fixFingers() { Msg.debug("Fixing fingers"); int i = this.nextFingerToFix; - int id = this.findSuccessor(this.id + (int)Math.pow(2,i)); //FIXME: SLOW - if (id != -1) { - if (id != fingers[i]) { - setFinger(i, id); + int successorId = this.findSuccessor(this.id + (int)Math.pow(2,i)); //FIXME: SLOW + if (successorId != -1) { + if (successorId != fingers[i]) { + setFinger(i, successorId); } nextFingerToFix = (i + 1) % Common.NB_BITS; } @@ -352,8 +352,7 @@ public class Node extends Process { * @return the closest preceding finger of that id */ int closestPrecedingNode(int id) { - int i; - for (i = Common.NB_BITS - 1; i >= 0; i--) { + for (int i = Common.NB_BITS - 1; i >= 0; i--) { if (isInInterval(fingers[i], this.id + 1, id - 1)) { return fingers[i]; } @@ -378,18 +377,18 @@ public class Node extends Process { * @return a non-zero value if id in in [start, end] */ static boolean isInInterval(int id, int start, int end) { - id = normalize(id); - start = normalize(start); - end = normalize(end); + int normId = normalize(id); + int normStart = normalize(start); + int normEnd = normalize(end); // make sure end >= start and id >= start - if (end < start) { - end += Common.NB_KEYS; + if (normEnd < normStart) { + normEnd += Common.NB_KEYS; } - if (id < start) { - id += Common.NB_KEYS; + if (normId < normStart) { + normId += Common.NB_KEYS; } - return (id <= end); + return (normId <= normEnd); } /** diff --git a/examples/java/trace/pingpong/Sender.java b/examples/java/trace/pingpong/Sender.java index 5fe2760115..02043167e2 100644 --- a/examples/java/trace/pingpong/Sender.java +++ b/examples/java/trace/pingpong/Sender.java @@ -29,7 +29,7 @@ public class Sender extends Process { int hostCount = args.length; Msg.info("host count: " + hostCount); - String mailboxes[] = new String[hostCount]; + String[] mailboxes = new String[hostCount]; double time; double computeDuration = 0; PingPongTask ping; diff --git a/src/bindings/java/org/simgrid/msg/RngStream.java b/src/bindings/java/org/simgrid/msg/RngStream.java index 23e95cb973..7e6feccd2a 100644 --- a/src/bindings/java/org/simgrid/msg/RngStream.java +++ b/src/bindings/java/org/simgrid/msg/RngStream.java @@ -61,7 +61,7 @@ public class RngStream { * must all be less than m1 = 4294967087, and not all 0; and the last 3 values must all be less * than m2 = 4294944443, and not all 0. Returns false for invalid seeds, and true otherwise. */ - public static native boolean setPackageSeed(int seed[]); + public static native boolean setPackageSeed(int[] seed); /** * Reinitializes the stream g to its initial state: Cg and Bg are set to Ig . */ @@ -87,7 +87,7 @@ public class RngStream { * the initial seeds of the streams are no longer spaced Z values apart. We discourage the use of * this procedure. Returns false for invalid seeds, and true otherwise. */ - public native boolean setSeed(int seed[]); + public native boolean setSeed(int[] seed); /** * Advances the state of the stream by k values, without modifying the states of other streams (as * in RngStream_SetSeed), nor the values of Bg and Ig associated with this stream. If e > 0, then -- 2.20.1