Commit f01a5679 authored by Britta Heymann's avatar Britta Heymann
Browse files

Fix some SonarLint issues

refs #40
parent 109488d4
Pipeline #8232 failed with stages
in 3 minutes and 39 seconds
......@@ -14,9 +14,9 @@ public class OneToOneMessage extends Message implements ISpecificRecipientsMessa
/**
* Creates a new OneToOneMessage.
* @param from Who the message is (originally) from
* @param to Who the message is (originally) to
* @param id Message identifier (must be unique for message but
* will be the same for all replicates of the message)
* @param to Who the message is (originally) to
* @param id Message identifier (must be unique for message but
* will be the same for all replicates of the message)
* @param size Size of the message (in bytes)
*/
public OneToOneMessage(DTNHost from, DTNHost to, String id, int size) {
......@@ -31,7 +31,7 @@ public class OneToOneMessage extends Message implements ISpecificRecipientsMessa
*/
@Override
public boolean isFinalRecipient(DTNHost host) {
return this.to == host;
return this.to.equals(host);
}
/**
......
......@@ -5,7 +5,6 @@
package report;
import java.util.HashMap;
import java.util.List;
import javafx.util.Pair;
......@@ -69,12 +68,12 @@ public class DistanceDelayReport extends Report implements MessageListener {
}
if (!(m instanceof ISpecificRecipientsMessage)) {
return;
return;
}
ISpecificRecipientsMessage msg = (ISpecificRecipientsMessage)m;
for(DTNHost node : msg.getFinalRecipients()) {
this.creationInfos.put(new Pair<String, Integer>(m.getId(), node.getAddress()),
this.creationInfos.put(new Pair(m.getId(), node.getAddress()),
new InfoTuple(getSimTime(),
m.getFrom().getLocation().clone(),
node.getLocation().clone()) );
......@@ -111,9 +110,9 @@ public class DistanceDelayReport extends Report implements MessageListener {
public void done() {
// report rest of the messages as 'not delivered' (time == -1)
for (Pair<String, Integer> messageIdAndDestination : creationInfos.keySet()) {
InfoTuple info = creationInfos.get(messageIdAndDestination);
report(
for (Pair<String, Integer> messageIdAndDestination : creationInfos.keySet()) {
InfoTuple info = creationInfos.get(messageIdAndDestination);
report(
messageIdAndDestination.getKey(),
info.getLoc1().distance(info.getLoc2()),
-1,
......
......@@ -112,7 +112,7 @@ public abstract class ActiveRouter extends MessageRouter {
ArrayList<Message> temp =
new ArrayList<Message>(this.getMessageCollection());
for (Message m : temp) {
if (m.isFinalRecipient(other)) {
if (m.isFinalRecipient(other)) {
if (startTransfer(m, con) == RCV_OK) {
return true;
}
......@@ -150,7 +150,7 @@ public abstract class ActiveRouter extends MessageRouter {
// check if msg was for this host and a response was requested
if (m.isFinalRecipient(getHost()) && m.getResponseSize() > 0) {
// generate a response message
Message res = new OneToOneMessage(this.getHost(),m.getFrom(),
Message res = new OneToOneMessage(this.getHost(),m.getFrom(),
RESPONSE_PREFIX+m.getId(), m.getResponseSize());
this.createNewMessage(res);
this.getMessage(RESPONSE_PREFIX+m.getId()).setRequest(m);
......
......@@ -116,7 +116,7 @@ public class EpidemicOracleRouter extends ActiveRouter {
if (m.isFinalRecipient(this.getHost())) {
for (EpidemicOracleRouter r : allRouters) {
if (r != this && r != from.getRouter()) {
this.ensureMessageHasSingleRecipient(m);
EpidemicOracleRouter.ensureMessageHasSingleRecipient(m);
r.removeDeliveredMessage(id);
}
}
......@@ -157,7 +157,7 @@ public class EpidemicOracleRouter extends ActiveRouter {
/* was the message delivered to the final recipient? */
if (m.isFinalRecipient(con.getOtherNode(getHost()))) {
this.ensureMessageHasSingleRecipient(m);
EpidemicOracleRouter.ensureMessageHasSingleRecipient(m);
this.deleteMessage(m.getId(), false);
}
}
......@@ -166,8 +166,8 @@ public class EpidemicOracleRouter extends ActiveRouter {
* Ensures that the given message only has a single recipient.
* @param msg Message to check.
*/
private void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage :
private static void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage :
"EpidemicOracleRouter only works with one to one messages";
}
......
......@@ -217,7 +217,7 @@ public class MaxPropRouter extends ActiveRouter {
/* was the message delivered to the final recipient? */
if (m.isFinalRecipient(recipient)) {
this.ensureMessageHasSingleRecipient(m);
MaxPropRouter.ensureMessageHasSingleRecipient(m);
this.ackedMessageIds.add(m.getId()); // yes, add to ACKed messages
this.deleteMessage(m.getId(), false); // delete from buffer
}
......@@ -278,7 +278,7 @@ public class MaxPropRouter extends ActiveRouter {
if (excludeMsgBeingSent && isSending(m.getId())) {
continue; // skip the message(s) that router is sending
}
validMessages.add(this.castMessageToOneToOne(m));
validMessages.add(MaxPropRouter.castMessageToOneToOne(m));
}
Collections.sort(validMessages,
......@@ -323,8 +323,8 @@ public class MaxPropRouter extends ActiveRouter {
* (optimization) */
Set<Integer> toSet = new HashSet<Integer>();
for (Message m : getMessageCollection()) {
OneToOneMessage singleRecipientMessage = this.castMessageToOneToOne(m);
toSet.add(singleRecipientMessage.getTo().getAddress());
OneToOneMessage singleRecipientMessage = MaxPropRouter.castMessageToOneToOne(m);
toSet.add(singleRecipientMessage.getTo().getAddress());
}
this.costsForMessages = dijkstra.getCosts(fromIndex, toSet);
......@@ -346,7 +346,7 @@ public class MaxPropRouter extends ActiveRouter {
* @return The return value of {@link #tryMessagesForConnected(List)}
*/
private Tuple<? extends Message, Connection> tryOtherMessages() {
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
Collection<Message> msgCollection = getMessageCollection();
......@@ -374,7 +374,7 @@ public class MaxPropRouter extends ActiveRouter {
continue;
}
/* message was a good candidate for sending */
messages.add(new Tuple(this.castMessageToOneToOne(m),con));
messages.add(new Tuple(MaxPropRouter.castMessageToOneToOne(m),con));
}
}
......@@ -454,18 +454,18 @@ public class MaxPropRouter extends ActiveRouter {
* @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage.
*/
private OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
"MaxPropRouter only works with one to one messages";
return (OneToOneMessage) msg;
return (OneToOneMessage) msg;
}
/**
* Ensures that the given message only has a single recipient.
* @param msg Message to check.
*/
private void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage :
private static void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage :
"MaxPropRouter only works with one to one messages";
}
......@@ -475,7 +475,7 @@ public class MaxPropRouter extends ActiveRouter {
* threshold are given priority and they are ordered by their hop count.
* Other messages are ordered by their delivery cost.
*/
private class MaxPropComparator implements Comparator<OneToOneMessage> {
private class MaxPropComparator implements Comparator<OneToOneMessage> {
private int threshold;
private DTNHost from1;
private DTNHost from2;
......
......@@ -353,7 +353,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
Message m = con.getMessage();
/* was the message delivered to the final recipient? */
if (m.isFinalRecipient(con.getOtherNode(getHost()))) {
this.ensureMessageHasSingleRecipient(m);
MaxPropRouterWithEstimation.ensureMessageHasSingleRecipient(m);
this.ackedMessageIds.add(m.getId()); // yes, add to ACKed messages
this.deleteMessage(m.getId(), false); // delete from buffer
}
......@@ -406,7 +406,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
if (excludeMsgBeingSent && isSending(m.getId())) {
continue; // skip the message(s) that router is sending
}
validMessages.add(this.castMessageToOneToOne(m));
validMessages.add(MaxPropRouterWithEstimation.castMessageToOneToOne(m));
}
Collections.sort(validMessages,
......@@ -451,8 +451,8 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* (optimization) */
Set<Integer> toSet = new HashSet<Integer>();
for (Message m : getMessageCollection()) {
OneToOneMessage singleRecipientMessage = this.castMessageToOneToOne(m);
toSet.add(singleRecipientMessage.getTo().getAddress());
OneToOneMessage singleRecipientMessage = MaxPropRouterWithEstimation.castMessageToOneToOne(m);
toSet.add(singleRecipientMessage.getTo().getAddress());
}
this.costsForMessages = dijkstra.getCosts(fromIndex, toSet);
......@@ -474,7 +474,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* @return The return value of {@link #tryMessagesForConnected(List)}
*/
private Tuple<? extends Message, Connection> tryOtherMessages() {
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
Collection<Message> msgCollection = getMessageCollection();
......@@ -495,7 +495,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
m.getHops().contains(other)) {
continue;
}
messages.add(new Tuple<OneToOneMessage, Connection>(this.castMessageToOneToOne(m),con));
messages.add(new Tuple<>(MaxPropRouterWithEstimation.castMessageToOneToOne(m),con));
}
}
......@@ -572,18 +572,18 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage.
*/
private OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
"MaxPropRouterWithEstimation only works with one to one messages";
return (OneToOneMessage) msg;
return (OneToOneMessage) msg;
}
/**
* Ensures that the given message only has a single recipient.
* @param msg Message to check.
*/
private void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage :
private static void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage :
"MaxPropRouterWithEstimation only works with one to one messages";
}
......@@ -593,7 +593,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* threshold are given priority and they are ordered by their hop count.
* Other messages are ordered by their delivery cost.
*/
private class MaxPropComparator implements Comparator<OneToOneMessage> {
private class MaxPropComparator implements Comparator<OneToOneMessage> {
private int threshold;
private DTNHost from1;
private DTNHost from2;
......
......@@ -213,7 +213,7 @@ public class ProphetRouter extends ActiveRouter {
* @return The return value of {@link #tryMessagesForConnected(List)}
*/
private Tuple<? extends Message, Connection> tryOtherMessages() {
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
Collection<Message> msgCollection = getMessageCollection();
......@@ -228,13 +228,13 @@ public class ProphetRouter extends ActiveRouter {
}
for (Message m : msgCollection) {
OneToOneMessage msg = this.castMessageToOneToOne(m);
OneToOneMessage msg = ProphetRouter.castMessageToOneToOne(m);
if (othRouter.hasMessage(msg.getId())) {
continue; // skip messages that the other one has
}
if (othRouter.getPredFor(msg.getTo()) > getPredFor(msg.getTo())) {
// the other node has higher probability of delivery
messages.add(new Tuple<OneToOneMessage, Connection>(msg,con));
messages.add(new Tuple<>(msg,con));
}
}
}
......@@ -254,7 +254,7 @@ public class ProphetRouter extends ActiveRouter {
* @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage.
*/
private OneToOneMessage castMessageToOneToOne(Message msg) {
private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
"ProphetRouter only works with one to one messages";
return (OneToOneMessage) msg;
......@@ -268,7 +268,7 @@ public class ProphetRouter extends ActiveRouter {
private class TupleComparator implements Comparator
<Tuple<OneToOneMessage, Connection>> {
public int compare(Tuple<OneToOneMessage, Connection> tuple1,
public int compare(Tuple<OneToOneMessage, Connection> tuple1,
Tuple<OneToOneMessage, Connection> tuple2) {
// delivery probability of tuple1's message with tuple1's connection
double p1 = ((ProphetRouter)tuple1.getValue().
......
......@@ -423,7 +423,7 @@ public class ProphetRouterWithEstimation extends ActiveRouter {
* @return The return value of {@link #tryMessagesForConnected(List)}
*/
private Tuple<? extends Message, Connection> tryOtherMessages() {
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
Collection<Message> msgCollection = getMessageCollection();
......@@ -438,13 +438,13 @@ public class ProphetRouterWithEstimation extends ActiveRouter {
}
for (Message m : msgCollection) {
OneToOneMessage msg = this.castMessageToOneToOne(m);
OneToOneMessage msg = ProphetRouterWithEstimation.castMessageToOneToOne(m);
if (othRouter.hasMessage(msg.getId())) {
continue; // skip messages that the other one has
}
if (othRouter.getPredFor(msg.getTo()) > getPredFor(msg.getTo())) {
// the other node has higher probability of delivery
messages.add(new Tuple<OneToOneMessage, Connection>(msg,con));
messages.add(new Tuple<>(msg,con));
}
}
}
......@@ -466,7 +466,7 @@ public class ProphetRouterWithEstimation extends ActiveRouter {
private class TupleComparator implements Comparator
<Tuple<OneToOneMessage, Connection>> {
public int compare(Tuple<OneToOneMessage, Connection> tuple1,
public int compare(Tuple<OneToOneMessage, Connection> tuple1,
Tuple<OneToOneMessage, Connection> tuple2) {
// delivery probability of tuple1's message with tuple1's connection
double p1 = ((ProphetRouterWithEstimation)tuple1.getValue().
......@@ -497,10 +497,10 @@ public class ProphetRouterWithEstimation extends ActiveRouter {
* @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage.
*/
private OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
"ProphetRouterWithEstimation only works with one to one messages";
return (OneToOneMessage) msg;
return (OneToOneMessage) msg;
}
@Override
......
......@@ -266,7 +266,7 @@ public class ProphetV2Router extends ActiveRouter {
* @return The return value of {@link #tryMessagesForConnected(List)}
*/
private Tuple<? extends Message, Connection> tryOtherMessages() {
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
List<Tuple<OneToOneMessage, Connection>> messages = new ArrayList<>();
Collection<Message> msgCollection = getMessageCollection();
......@@ -281,14 +281,13 @@ public class ProphetV2Router extends ActiveRouter {
}
for (Message m : msgCollection) {
OneToOneMessage msg = this.castMessageToOneToOne(m);
OneToOneMessage msg = ProphetV2Router.castMessageToOneToOne(m);
if (othRouter.hasMessage(msg.getId())) {
continue; // skip messages that the other one has
}
if((othRouter.getPredFor(msg.getTo()) >= getPredFor(msg.getTo())))
{
messages.add(new Tuple<OneToOneMessage, Connection>(msg,con));
messages.add(new Tuple<>(msg,con));
}
}
}
......@@ -308,7 +307,7 @@ public class ProphetV2Router extends ActiveRouter {
* @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage.
*/
private OneToOneMessage castMessageToOneToOne(Message msg) {
private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage :
"ProphetV2Router only works with one to one messages";
return (OneToOneMessage) msg;
......@@ -322,7 +321,7 @@ public class ProphetV2Router extends ActiveRouter {
private class TupleComparator implements Comparator
<Tuple<OneToOneMessage, Connection>> {
public int compare(Tuple<OneToOneMessage, Connection> tuple1,
public int compare(Tuple<OneToOneMessage, Connection> tuple1,
Tuple<OneToOneMessage, Connection> tuple2) {
// delivery probability of tuple1's message with tuple1's connection
double p1 = ((ProphetV2Router)tuple1.getValue().
......
......@@ -229,13 +229,13 @@ public class MessageTransferAcceptPolicy {
* @return true if both conditions evaluated to true
*/
private boolean checkSimplePolicy(Message m, int ownAddress) {
boolean checkRecipients = true;
if (m instanceof ISpecificRecipientsMessage) {
List<DTNHost> recipients = ((ISpecificRecipientsMessage)m).getFinalRecipients();
checkRecipients = this.checkSimplePolicy(recipients, this.toSendPolicy, ownAddress);
boolean checkRecipients = true;
if (m instanceof ISpecificRecipientsMessage) {
List<DTNHost> recipients = ((ISpecificRecipientsMessage)m).getFinalRecipients();
checkRecipients = MessageTransferAcceptPolicy.checkSimplePolicy(recipients, this.toSendPolicy, ownAddress);
}
return checkRecipients && checkSimplePolicy(m.getFrom(), this.fromSendPolicy, ownAddress);
return checkRecipients && checkSimplePolicy(m.getFrom(), this.fromSendPolicy, ownAddress);
}
/**
......@@ -248,10 +248,10 @@ public class MessageTransferAcceptPolicy {
* @return True if the address was in the policy list, or the policy list
* was null
*/
private boolean checkSimplePolicy(DTNHost host, Range [] policy, int thisHost) {
List<DTNHost> hosts = new ArrayList<>(1);
hosts.add(host);
return this.checkSimplePolicy(hosts, policy, thisHost);
private static boolean checkSimplePolicy(DTNHost host, Range [] policy, int thisHost) {
List<DTNHost> hosts = new ArrayList<>(1);
hosts.add(host);
return MessageTransferAcceptPolicy.checkSimplePolicy(hosts, policy, thisHost);
}
/**
......@@ -264,22 +264,20 @@ public class MessageTransferAcceptPolicy {
* @return True if one of the addresses was in the policy list, or the policy list
* was null
*/
private boolean checkSimplePolicy(List<DTNHost> hosts, Range [] policy, int thisHost) {
if (policy == null) {
private static boolean checkSimplePolicy(List<DTNHost> hosts, Range [] policy, int thisHost) {
if (policy == null) {
return true;
}
for (Range r : policy) {
for (DTNHost host : hosts) {
if (r.isInRange(TO_ME_VALUE) && host.getAddress() == thisHost) {
return true;
}
else if (r.isInRange(host.getAddress())) {
return true;
}
for (Range r : policy) {
for (DTNHost host : hosts) {
boolean checkIsTrueBecauseOfOwnAddress = r.isInRange(TO_ME_VALUE) && host.getAddress() == thisHost;
if (checkIsTrueBecauseOfOwnAddress || r.isInRange(host.getAddress())) {
return true;
}
}
}
return false;
return false;
}
/**
......
  • SonarQube analysis reported 5 issues:

    • CRITICAL 1 critical
    • MAJOR 3 major
    • MINOR 1 minor

    Watch the comments in this conversation to review them. Note: the following issues could not be reported as comments because they are located on lines that are not displayed in this commit:

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment