Skip to content
Snippets Groups Projects
Commit f01a5679 authored by Britta Heymann's avatar Britta Heymann
Browse files

Fix some SonarLint issues

refs #40
parent 109488d4
No related branches found
No related tags found
1 merge request!8WIP: Broadcast messages in application layer
Pipeline #
...@@ -31,7 +31,7 @@ public class OneToOneMessage extends Message implements ISpecificRecipientsMessa ...@@ -31,7 +31,7 @@ public class OneToOneMessage extends Message implements ISpecificRecipientsMessa
*/ */
@Override @Override
public boolean isFinalRecipient(DTNHost host) { public boolean isFinalRecipient(DTNHost host) {
return this.to == host; return this.to.equals(host);
} }
/** /**
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package report; package report;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import javafx.util.Pair; import javafx.util.Pair;
...@@ -74,7 +73,7 @@ public class DistanceDelayReport extends Report implements MessageListener { ...@@ -74,7 +73,7 @@ public class DistanceDelayReport extends Report implements MessageListener {
ISpecificRecipientsMessage msg = (ISpecificRecipientsMessage)m; ISpecificRecipientsMessage msg = (ISpecificRecipientsMessage)m;
for(DTNHost node : msg.getFinalRecipients()) { 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(), new InfoTuple(getSimTime(),
m.getFrom().getLocation().clone(), m.getFrom().getLocation().clone(),
node.getLocation().clone()) ); node.getLocation().clone()) );
......
...@@ -116,7 +116,7 @@ public class EpidemicOracleRouter extends ActiveRouter { ...@@ -116,7 +116,7 @@ public class EpidemicOracleRouter extends ActiveRouter {
if (m.isFinalRecipient(this.getHost())) { if (m.isFinalRecipient(this.getHost())) {
for (EpidemicOracleRouter r : allRouters) { for (EpidemicOracleRouter r : allRouters) {
if (r != this && r != from.getRouter()) { if (r != this && r != from.getRouter()) {
this.ensureMessageHasSingleRecipient(m); EpidemicOracleRouter.ensureMessageHasSingleRecipient(m);
r.removeDeliveredMessage(id); r.removeDeliveredMessage(id);
} }
} }
...@@ -157,7 +157,7 @@ public class EpidemicOracleRouter extends ActiveRouter { ...@@ -157,7 +157,7 @@ public class EpidemicOracleRouter extends ActiveRouter {
/* was the message delivered to the final recipient? */ /* was the message delivered to the final recipient? */
if (m.isFinalRecipient(con.getOtherNode(getHost()))) { if (m.isFinalRecipient(con.getOtherNode(getHost()))) {
this.ensureMessageHasSingleRecipient(m); EpidemicOracleRouter.ensureMessageHasSingleRecipient(m);
this.deleteMessage(m.getId(), false); this.deleteMessage(m.getId(), false);
} }
} }
...@@ -166,7 +166,7 @@ public class EpidemicOracleRouter extends ActiveRouter { ...@@ -166,7 +166,7 @@ public class EpidemicOracleRouter extends ActiveRouter {
* Ensures that the given message only has a single recipient. * Ensures that the given message only has a single recipient.
* @param msg Message to check. * @param msg Message to check.
*/ */
private void ensureMessageHasSingleRecipient(Message msg) { private static void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"EpidemicOracleRouter only works with one to one messages"; "EpidemicOracleRouter only works with one to one messages";
} }
......
...@@ -217,7 +217,7 @@ public class MaxPropRouter extends ActiveRouter { ...@@ -217,7 +217,7 @@ public class MaxPropRouter extends ActiveRouter {
/* was the message delivered to the final recipient? */ /* was the message delivered to the final recipient? */
if (m.isFinalRecipient(recipient)) { if (m.isFinalRecipient(recipient)) {
this.ensureMessageHasSingleRecipient(m); MaxPropRouter.ensureMessageHasSingleRecipient(m);
this.ackedMessageIds.add(m.getId()); // yes, add to ACKed messages this.ackedMessageIds.add(m.getId()); // yes, add to ACKed messages
this.deleteMessage(m.getId(), false); // delete from buffer this.deleteMessage(m.getId(), false); // delete from buffer
} }
...@@ -278,7 +278,7 @@ public class MaxPropRouter extends ActiveRouter { ...@@ -278,7 +278,7 @@ public class MaxPropRouter extends ActiveRouter {
if (excludeMsgBeingSent && isSending(m.getId())) { if (excludeMsgBeingSent && isSending(m.getId())) {
continue; // skip the message(s) that router is sending continue; // skip the message(s) that router is sending
} }
validMessages.add(this.castMessageToOneToOne(m)); validMessages.add(MaxPropRouter.castMessageToOneToOne(m));
} }
Collections.sort(validMessages, Collections.sort(validMessages,
...@@ -323,7 +323,7 @@ public class MaxPropRouter extends ActiveRouter { ...@@ -323,7 +323,7 @@ public class MaxPropRouter extends ActiveRouter {
* (optimization) */ * (optimization) */
Set<Integer> toSet = new HashSet<Integer>(); Set<Integer> toSet = new HashSet<Integer>();
for (Message m : getMessageCollection()) { for (Message m : getMessageCollection()) {
OneToOneMessage singleRecipientMessage = this.castMessageToOneToOne(m); OneToOneMessage singleRecipientMessage = MaxPropRouter.castMessageToOneToOne(m);
toSet.add(singleRecipientMessage.getTo().getAddress()); toSet.add(singleRecipientMessage.getTo().getAddress());
} }
...@@ -374,7 +374,7 @@ public class MaxPropRouter extends ActiveRouter { ...@@ -374,7 +374,7 @@ public class MaxPropRouter extends ActiveRouter {
continue; continue;
} }
/* message was a good candidate for sending */ /* message was a good candidate for sending */
messages.add(new Tuple(this.castMessageToOneToOne(m),con)); messages.add(new Tuple(MaxPropRouter.castMessageToOneToOne(m),con));
} }
} }
...@@ -454,7 +454,7 @@ public class MaxPropRouter extends ActiveRouter { ...@@ -454,7 +454,7 @@ public class MaxPropRouter extends ActiveRouter {
* @return Message as OneToOneMessage. * @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage. * @throws AssertionError if message is not a OneToOneMessage.
*/ */
private OneToOneMessage castMessageToOneToOne(Message msg) { private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"MaxPropRouter only works with one to one messages"; "MaxPropRouter only works with one to one messages";
return (OneToOneMessage) msg; return (OneToOneMessage) msg;
...@@ -464,7 +464,7 @@ public class MaxPropRouter extends ActiveRouter { ...@@ -464,7 +464,7 @@ public class MaxPropRouter extends ActiveRouter {
* Ensures that the given message only has a single recipient. * Ensures that the given message only has a single recipient.
* @param msg Message to check. * @param msg Message to check.
*/ */
private void ensureMessageHasSingleRecipient(Message msg) { private static void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"MaxPropRouter only works with one to one messages"; "MaxPropRouter only works with one to one messages";
} }
......
...@@ -353,7 +353,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter { ...@@ -353,7 +353,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
Message m = con.getMessage(); Message m = con.getMessage();
/* was the message delivered to the final recipient? */ /* was the message delivered to the final recipient? */
if (m.isFinalRecipient(con.getOtherNode(getHost()))) { if (m.isFinalRecipient(con.getOtherNode(getHost()))) {
this.ensureMessageHasSingleRecipient(m); MaxPropRouterWithEstimation.ensureMessageHasSingleRecipient(m);
this.ackedMessageIds.add(m.getId()); // yes, add to ACKed messages this.ackedMessageIds.add(m.getId()); // yes, add to ACKed messages
this.deleteMessage(m.getId(), false); // delete from buffer this.deleteMessage(m.getId(), false); // delete from buffer
} }
...@@ -406,7 +406,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter { ...@@ -406,7 +406,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
if (excludeMsgBeingSent && isSending(m.getId())) { if (excludeMsgBeingSent && isSending(m.getId())) {
continue; // skip the message(s) that router is sending continue; // skip the message(s) that router is sending
} }
validMessages.add(this.castMessageToOneToOne(m)); validMessages.add(MaxPropRouterWithEstimation.castMessageToOneToOne(m));
} }
Collections.sort(validMessages, Collections.sort(validMessages,
...@@ -451,7 +451,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter { ...@@ -451,7 +451,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* (optimization) */ * (optimization) */
Set<Integer> toSet = new HashSet<Integer>(); Set<Integer> toSet = new HashSet<Integer>();
for (Message m : getMessageCollection()) { for (Message m : getMessageCollection()) {
OneToOneMessage singleRecipientMessage = this.castMessageToOneToOne(m); OneToOneMessage singleRecipientMessage = MaxPropRouterWithEstimation.castMessageToOneToOne(m);
toSet.add(singleRecipientMessage.getTo().getAddress()); toSet.add(singleRecipientMessage.getTo().getAddress());
} }
...@@ -495,7 +495,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter { ...@@ -495,7 +495,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
m.getHops().contains(other)) { m.getHops().contains(other)) {
continue; continue;
} }
messages.add(new Tuple<OneToOneMessage, Connection>(this.castMessageToOneToOne(m),con)); messages.add(new Tuple<>(MaxPropRouterWithEstimation.castMessageToOneToOne(m),con));
} }
} }
...@@ -572,7 +572,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter { ...@@ -572,7 +572,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* @return Message as OneToOneMessage. * @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage. * @throws AssertionError if message is not a OneToOneMessage.
*/ */
private OneToOneMessage castMessageToOneToOne(Message msg) { private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"MaxPropRouterWithEstimation only works with one to one messages"; "MaxPropRouterWithEstimation only works with one to one messages";
return (OneToOneMessage) msg; return (OneToOneMessage) msg;
...@@ -582,7 +582,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter { ...@@ -582,7 +582,7 @@ public class MaxPropRouterWithEstimation extends ActiveRouter {
* Ensures that the given message only has a single recipient. * Ensures that the given message only has a single recipient.
* @param msg Message to check. * @param msg Message to check.
*/ */
private void ensureMessageHasSingleRecipient(Message msg) { private static void ensureMessageHasSingleRecipient(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"MaxPropRouterWithEstimation only works with one to one messages"; "MaxPropRouterWithEstimation only works with one to one messages";
} }
......
...@@ -228,13 +228,13 @@ public class ProphetRouter extends ActiveRouter { ...@@ -228,13 +228,13 @@ public class ProphetRouter extends ActiveRouter {
} }
for (Message m : msgCollection) { for (Message m : msgCollection) {
OneToOneMessage msg = this.castMessageToOneToOne(m); OneToOneMessage msg = ProphetRouter.castMessageToOneToOne(m);
if (othRouter.hasMessage(msg.getId())) { if (othRouter.hasMessage(msg.getId())) {
continue; // skip messages that the other one has continue; // skip messages that the other one has
} }
if (othRouter.getPredFor(msg.getTo()) > getPredFor(msg.getTo())) { if (othRouter.getPredFor(msg.getTo()) > getPredFor(msg.getTo())) {
// the other node has higher probability of delivery // 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 { ...@@ -254,7 +254,7 @@ public class ProphetRouter extends ActiveRouter {
* @return Message as OneToOneMessage. * @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage. * @throws AssertionError if message is not a OneToOneMessage.
*/ */
private OneToOneMessage castMessageToOneToOne(Message msg) { private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"ProphetRouter only works with one to one messages"; "ProphetRouter only works with one to one messages";
return (OneToOneMessage) msg; return (OneToOneMessage) msg;
......
...@@ -438,13 +438,13 @@ public class ProphetRouterWithEstimation extends ActiveRouter { ...@@ -438,13 +438,13 @@ public class ProphetRouterWithEstimation extends ActiveRouter {
} }
for (Message m : msgCollection) { for (Message m : msgCollection) {
OneToOneMessage msg = this.castMessageToOneToOne(m); OneToOneMessage msg = ProphetRouterWithEstimation.castMessageToOneToOne(m);
if (othRouter.hasMessage(msg.getId())) { if (othRouter.hasMessage(msg.getId())) {
continue; // skip messages that the other one has continue; // skip messages that the other one has
} }
if (othRouter.getPredFor(msg.getTo()) > getPredFor(msg.getTo())) { if (othRouter.getPredFor(msg.getTo()) > getPredFor(msg.getTo())) {
// the other node has higher probability of delivery // the other node has higher probability of delivery
messages.add(new Tuple<OneToOneMessage, Connection>(msg,con)); messages.add(new Tuple<>(msg,con));
} }
} }
} }
...@@ -497,7 +497,7 @@ public class ProphetRouterWithEstimation extends ActiveRouter { ...@@ -497,7 +497,7 @@ public class ProphetRouterWithEstimation extends ActiveRouter {
* @return Message as OneToOneMessage. * @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage. * @throws AssertionError if message is not a OneToOneMessage.
*/ */
private OneToOneMessage castMessageToOneToOne(Message msg) { private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"ProphetRouterWithEstimation only works with one to one messages"; "ProphetRouterWithEstimation only works with one to one messages";
return (OneToOneMessage) msg; return (OneToOneMessage) msg;
......
...@@ -281,14 +281,13 @@ public class ProphetV2Router extends ActiveRouter { ...@@ -281,14 +281,13 @@ public class ProphetV2Router extends ActiveRouter {
} }
for (Message m : msgCollection) { for (Message m : msgCollection) {
OneToOneMessage msg = this.castMessageToOneToOne(m); OneToOneMessage msg = ProphetV2Router.castMessageToOneToOne(m);
if (othRouter.hasMessage(msg.getId())) { if (othRouter.hasMessage(msg.getId())) {
continue; // skip messages that the other one has continue; // skip messages that the other one has
} }
if((othRouter.getPredFor(msg.getTo()) >= getPredFor(msg.getTo()))) if((othRouter.getPredFor(msg.getTo()) >= getPredFor(msg.getTo())))
{ {
messages.add(new Tuple<>(msg,con));
messages.add(new Tuple<OneToOneMessage, Connection>(msg,con));
} }
} }
} }
...@@ -308,7 +307,7 @@ public class ProphetV2Router extends ActiveRouter { ...@@ -308,7 +307,7 @@ public class ProphetV2Router extends ActiveRouter {
* @return Message as OneToOneMessage. * @return Message as OneToOneMessage.
* @throws AssertionError if message is not a OneToOneMessage. * @throws AssertionError if message is not a OneToOneMessage.
*/ */
private OneToOneMessage castMessageToOneToOne(Message msg) { private static OneToOneMessage castMessageToOneToOne(Message msg) {
assert msg instanceof OneToOneMessage : assert msg instanceof OneToOneMessage :
"ProphetV2Router only works with one to one messages"; "ProphetV2Router only works with one to one messages";
return (OneToOneMessage) msg; return (OneToOneMessage) msg;
......
...@@ -232,7 +232,7 @@ public class MessageTransferAcceptPolicy { ...@@ -232,7 +232,7 @@ public class MessageTransferAcceptPolicy {
boolean checkRecipients = true; boolean checkRecipients = true;
if (m instanceof ISpecificRecipientsMessage) { if (m instanceof ISpecificRecipientsMessage) {
List<DTNHost> recipients = ((ISpecificRecipientsMessage)m).getFinalRecipients(); List<DTNHost> recipients = ((ISpecificRecipientsMessage)m).getFinalRecipients();
checkRecipients = this.checkSimplePolicy(recipients, this.toSendPolicy, ownAddress); 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 { ...@@ -248,10 +248,10 @@ public class MessageTransferAcceptPolicy {
* @return True if the address was in the policy list, or the policy list * @return True if the address was in the policy list, or the policy list
* was null * was null
*/ */
private boolean checkSimplePolicy(DTNHost host, Range [] policy, int thisHost) { private static boolean checkSimplePolicy(DTNHost host, Range [] policy, int thisHost) {
List<DTNHost> hosts = new ArrayList<>(1); List<DTNHost> hosts = new ArrayList<>(1);
hosts.add(host); hosts.add(host);
return this.checkSimplePolicy(hosts, policy, thisHost); return MessageTransferAcceptPolicy.checkSimplePolicy(hosts, policy, thisHost);
} }
/** /**
...@@ -264,17 +264,15 @@ public class MessageTransferAcceptPolicy { ...@@ -264,17 +264,15 @@ public class MessageTransferAcceptPolicy {
* @return True if one of the addresses was in the policy list, or the policy list * @return True if one of the addresses was in the policy list, or the policy list
* was null * was null
*/ */
private boolean checkSimplePolicy(List<DTNHost> hosts, Range [] policy, int thisHost) { private static boolean checkSimplePolicy(List<DTNHost> hosts, Range [] policy, int thisHost) {
if (policy == null) { if (policy == null) {
return true; return true;
} }
for (Range r : policy) { for (Range r : policy) {
for (DTNHost host : hosts) { for (DTNHost host : hosts) {
if (r.isInRange(TO_ME_VALUE) && host.getAddress() == thisHost) { boolean checkIsTrueBecauseOfOwnAddress = r.isInRange(TO_ME_VALUE) && host.getAddress() == thisHost;
return true; if (checkIsTrueBecauseOfOwnAddress || r.isInRange(host.getAddress())) {
}
else if (r.isInRange(host.getAddress())) {
return true; return true;
} }
} }
......
  • Contributor

    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:

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment