From f1b63e438e363f3152ac7c56a6b200ea32df4c27 Mon Sep 17 00:00:00 2001 From: Andre Brait <andrebrait@gmail.com> Date: Wed, 9 May 2018 01:22:31 -0300 Subject: [PATCH] Soling field isolation issues --- .../models/interferenceModels/SINR.java | 2 +- .../nodes/messages/IntMessage.java | 11 +- .../nodes/messages/StringMessage.java | 10 +- .../java/projects/sample1/CustomGlobal.java | 4 +- src/main/java/projects/sample1/LogL.java | 8 +- .../nodes/nodeImplementations/S1Node.java | 6 +- .../sample1/nodes/timers/DelayTimer.java | 2 +- .../nodes/nodeImplementations/S2Node.java | 2 +- .../sample3/nodes/messages/InviteMessage.java | 6 +- .../sample3/nodes/messages/SmsAckMessage.java | 7 +- .../nodes/nodeImplementations/MobileNode.java | 6 +- .../sample3/nodes/timers/InviteMsgTimer.java | 11 +- .../sample3/nodes/timers/SmsTimer.java | 21 ++-- .../sample4/nodes/messages/S4Message.java | 6 +- .../nodes/nodeImplementations/S4Node.java | 10 +- .../sample5/nodes/messages/FloodFindMsg.java | 41 +++---- .../sample5/nodes/messages/PayloadMsg.java | 18 +-- .../nodes/nodeImplementations/FNode.java | 90 +++++++-------- .../java/projects/sample6/CustomGlobal.java | 4 +- .../nodes/nodeImplementations/LeafNode.java | 18 ++- .../nodes/nodeImplementations/TreeNode.java | 10 +- src/main/java/sinalgo/Run.java | 2 +- .../java/sinalgo/configuration/AppConfig.java | 8 +- .../sinalgo/configuration/Configuration.java | 4 +- src/main/java/sinalgo/gui/GraphPanel.java | 12 +- .../controlPanel/MaximizedControlPanel.java | 4 +- .../gui/dialogs/GenerateNodesDialog.java | 2 +- .../sinalgo/gui/dialogs/GraphInfoDialog.java | 2 +- .../sinalgo/gui/dialogs/NodeInfoDialog.java | 8 +- .../sinalgo/io/eps/EPSOutputPrintStream.java | 107 +++++++++--------- src/main/java/sinalgo/io/eps/Exporter.java | 40 +++---- src/main/java/sinalgo/io/mapIO/Rectangle.java | 13 ++- .../models/ConnectivityModelHelper.java | 2 +- .../java/sinalgo/nodes/InboxPacketBuffer.java | 2 +- src/main/java/sinalgo/nodes/Node.java | 20 ++-- src/main/java/sinalgo/nodes/Position.java | 8 +- src/main/java/sinalgo/nodes/edges/Edge.java | 2 +- src/main/java/sinalgo/nodes/timers/Timer.java | 6 +- .../runtime/AsynchronousRuntimeThread.java | 6 +- src/main/java/sinalgo/runtime/GUIRuntime.java | 2 +- src/main/java/sinalgo/runtime/Main.java | 17 ++- .../java/sinalgo/runtime/SinalgoRuntime.java | 41 ++++--- .../SinalgoUncaughtExceptionHandler.java | 6 +- .../runtime/SynchronousRuntimeThread.java | 8 +- .../sinalgo/runtime/events/EventQueue.java | 2 +- .../sinalgo/runtime/events/PacketEvent.java | 15 ++- .../sinalgo/runtime/events/TimerEvent.java | 9 +- src/main/java/sinalgo/tools/Tools.java | 38 ++----- 48 files changed, 371 insertions(+), 308 deletions(-) diff --git a/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java b/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java index 62f3960..911a0d9 100644 --- a/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java +++ b/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java @@ -100,7 +100,7 @@ public class SINR extends InterferenceModel { double noise = this.ambientNoise; - for (Packet pack : SinalgoRuntime.packetsInTheAir) { // iterate over all active packets + for (Packet pack : SinalgoRuntime.getPacketsInTheAir()) { // iterate over all active packets if (pack == p) { continue; // that's the packet we want } diff --git a/src/main/java/projects/defaultProject/nodes/messages/IntMessage.java b/src/main/java/projects/defaultProject/nodes/messages/IntMessage.java index 099b853..0ac3775 100644 --- a/src/main/java/projects/defaultProject/nodes/messages/IntMessage.java +++ b/src/main/java/projects/defaultProject/nodes/messages/IntMessage.java @@ -36,17 +36,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.nodes.messages; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.messages.Message; /** * A standard message type consisting only of a integer as payload. */ +@Getter +@Setter public class IntMessage extends Message { /** * The payload of the Message: an integer. */ - public int value; + private int value; /** * The constructor for the IntMessage class. @@ -54,11 +58,12 @@ public class IntMessage extends Message { * @param i The integer the payload has to be set to. */ public IntMessage(int i) { - this.value = i; + this.setValue(i); } @Override public Message clone() { - return new IntMessage(this.value); + return new IntMessage(this.getValue()); } + } diff --git a/src/main/java/projects/defaultProject/nodes/messages/StringMessage.java b/src/main/java/projects/defaultProject/nodes/messages/StringMessage.java index 718182a..dc9bcc0 100644 --- a/src/main/java/projects/defaultProject/nodes/messages/StringMessage.java +++ b/src/main/java/projects/defaultProject/nodes/messages/StringMessage.java @@ -36,6 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.nodes.messages; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.messages.Message; /** @@ -46,7 +48,9 @@ public class StringMessage extends Message { /** * The text of this message. */ - public String text; + @Getter + @Setter + private String text; /** * Constructing a Message having the given string as message. @@ -54,12 +58,12 @@ public class StringMessage extends Message { * @param txt The test of the Message to construct. */ public StringMessage(String txt) { - this.text = txt; + this.setText(txt); } @Override public Message clone() { - return new StringMessage(this.text); + return new StringMessage(this.getText()); } } diff --git a/src/main/java/projects/sample1/CustomGlobal.java b/src/main/java/projects/sample1/CustomGlobal.java index c837bc7..9ea707a 100644 --- a/src/main/java/projects/sample1/CustomGlobal.java +++ b/src/main/java/projects/sample1/CustomGlobal.java @@ -186,7 +186,7 @@ public class CustomGlobal extends AbstractCustomGlobal { @GlobalMethod(menuText = "...", subMenu = "Node Control", order = 2) public void stopSending() { - S1Node.isSending = !S1Node.isSending; + S1Node.setSending(!S1Node.isSending()); } @Override @@ -195,7 +195,7 @@ public class CustomGlobal extends AbstractCustomGlobal { if (Tools.getNodeList().size() == 0) { return null; // don't display this menu option } - return S1Node.isSending ? "Stop Sending" : "Continue Sending"; + return S1Node.isSending() ? "Stop Sending" : "Continue Sending"; } return defaultText; } diff --git a/src/main/java/projects/sample1/LogL.java b/src/main/java/projects/sample1/LogL.java index b7d062c..55df473 100644 --- a/src/main/java/projects/sample1/LogL.java +++ b/src/main/java/projects/sample1/LogL.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.sample1; +import lombok.Getter; +import lombok.Setter; + /** * Enumerates the log-levels. Levels above THRESHOLD will be included in the * log-file. The levels below (with a higher enumeration value) not. @@ -46,5 +49,8 @@ public class LogL extends sinalgo.tools.logging.LogL { * An additional loglevel to inform about loggings for the sending process of * sending. */ - public static boolean SEND = true; + @Getter + @Setter + private static boolean SEND = true; + } diff --git a/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java b/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java index 36f996a..1657d7f 100644 --- a/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java +++ b/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java @@ -86,11 +86,13 @@ public class S1Node extends Node { Logging log = Logging.getLogger("s1_log"); // a flag to prevent all nodes from sending messages - public static boolean isSending = true; + @Getter + @Setter + private static boolean isSending = true; @Override public void handleMessages(Inbox inbox) { - if (!isSending) { // don't even look at incoming messages + if (!isSending()) { // don't even look at incoming messages return; } if (inbox.hasNext()) { diff --git a/src/main/java/projects/sample1/nodes/timers/DelayTimer.java b/src/main/java/projects/sample1/nodes/timers/DelayTimer.java index 79acac8..5489906 100644 --- a/src/main/java/projects/sample1/nodes/timers/DelayTimer.java +++ b/src/main/java/projects/sample1/nodes/timers/DelayTimer.java @@ -75,7 +75,7 @@ public class DelayTimer extends Timer { @Override public void fire() { - if (!S1Node.isSending) { + if (!S1Node.isSending()) { return; } if (this.sender.getNext() != null) { diff --git a/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java b/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java index 8bd279e..699eaaa 100644 --- a/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java +++ b/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java @@ -135,7 +135,7 @@ public class S2Node extends Node { @NodePopupMethod(menuText = "Undo Coloring") public void UndoColoring() { // NOTE: Do not change method name! // undo the coloring for all nodes - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { ((S2Node) n).setDrawAsNeighbor(false); } setColored(false); diff --git a/src/main/java/projects/sample3/nodes/messages/InviteMessage.java b/src/main/java/projects/sample3/nodes/messages/InviteMessage.java index 6b4ccaa..f3db4e1 100644 --- a/src/main/java/projects/sample3/nodes/messages/InviteMessage.java +++ b/src/main/java/projects/sample3/nodes/messages/InviteMessage.java @@ -1,13 +1,17 @@ package projects.sample3.nodes.messages; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.messages.Message; /** * Message sent by an antenna to invite adjacent mobile nodes to join */ +@Getter +@Setter public class InviteMessage extends Message { - public boolean requireSubscription = false; // if true, the receiver needs to subscribe even if it is already + private boolean requireSubscription = false; // if true, the receiver needs to subscribe even if it is already // subscribed @Override diff --git a/src/main/java/projects/sample3/nodes/messages/SmsAckMessage.java b/src/main/java/projects/sample3/nodes/messages/SmsAckMessage.java index b04588a..7aa05da 100644 --- a/src/main/java/projects/sample3/nodes/messages/SmsAckMessage.java +++ b/src/main/java/projects/sample3/nodes/messages/SmsAckMessage.java @@ -1,13 +1,18 @@ package projects.sample3.nodes.messages; +import lombok.Getter; +import lombok.Setter; import projects.sample3.nodes.timers.SmsTimer; import sinalgo.nodes.Node; public class SmsAckMessage extends SmsMessage { - public int smsSeqID; // the sequence ID of the message to ACK + @Getter + @Setter + private int smsSeqID; // the sequence ID of the message to ACK public SmsAckMessage(int aSeqID, Node aReceiver, Node aSender, String aText, SmsTimer aTimer) { super(aSeqID, aReceiver, aSender, aText, aTimer); } + } diff --git a/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java b/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java index 6e8bce4..6535c92 100644 --- a/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java +++ b/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java @@ -58,7 +58,7 @@ public class MobileNode extends Node { this.currentAntenna = (Antenna) inbox.getSender(); needSubscription = true; } else { - if (im.requireSubscription) { + if (im.isRequireSubscription()) { needSubscription = true; // subscirbe again } } @@ -168,10 +168,10 @@ public class MobileNode extends Node { for (Timer t : this.getTimers()) { if (t instanceof SmsTimer) { SmsTimer st = (SmsTimer) t; - if (st.enabled) { + if (st.isEnabled()) { pt.translateToGUIPosition(this.getPosition()); int fromX = pt.getGuiX(), fromY = pt.getGuiY(); - pt.translateToGUIPosition(st.destination.getPosition()); + pt.translateToGUIPosition(st.getDestination().getPosition()); Arrow.drawArrow(fromX, fromY, pt.getGuiX(), pt.getGuiY(), g, pt, Color.RED); } } diff --git a/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java b/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java index ad9fae8..258f48f 100644 --- a/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java +++ b/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java @@ -1,5 +1,7 @@ package projects.sample3.nodes.timers; +import lombok.Getter; +import lombok.Setter; import projects.sample3.nodes.messages.InviteMessage; import projects.sample3.nodes.nodeImplementations.Antenna; import sinalgo.configuration.Configuration; @@ -14,13 +16,15 @@ import sinalgo.tools.statistics.Distribution; */ public class InviteMsgTimer extends Timer { - private Distribution dist = null; + private Distribution dist; private int refreshRate; private int refreshCounter = 0; // If set to true, the antenna requires the nodes to register again // such that it can drop old mobileNodes - public boolean requireSubscription = false; + @Getter + @Setter + private boolean requireSubscription = false; public InviteMsgTimer() { try { @@ -37,7 +41,7 @@ public class InviteMsgTimer extends Timer { this.refreshCounter--; if (this.refreshCounter <= 0) { ((Antenna) this.getTargetNode()).resetNeighborhood(); - msg.requireSubscription = true; + msg.setRequireSubscription(true); this.refreshCounter = this.refreshRate; // reset the counter } @@ -48,4 +52,5 @@ public class InviteMsgTimer extends Timer { } this.startRelative(time, this.getTargetNode()); } + } diff --git a/src/main/java/projects/sample3/nodes/timers/SmsTimer.java b/src/main/java/projects/sample3/nodes/timers/SmsTimer.java index 77ce66e..792f22c 100644 --- a/src/main/java/projects/sample3/nodes/timers/SmsTimer.java +++ b/src/main/java/projects/sample3/nodes/timers/SmsTimer.java @@ -1,33 +1,36 @@ package projects.sample3.nodes.timers; +import lombok.Getter; +import lombok.Setter; import projects.sample3.nodes.messages.SmsMessage; import projects.sample3.nodes.nodeImplementations.Antenna; import projects.sample3.nodes.nodeImplementations.MobileNode; import sinalgo.nodes.Node; import sinalgo.nodes.timers.Timer; +@Getter +@Setter public class SmsTimer extends Timer { - public String text; - public Node destination; - - public boolean enabled = true; + private String text; + private Node destination; + private boolean enabled = true; public void disable() { - this.enabled = false; + this.setEnabled(false); } public SmsTimer(String aText, Node aDestination) { - this.text = aText; - this.destination = aDestination; + this.setText(aText); + this.setDestination(aDestination); } @Override public void fire() { - if (this.enabled) { + if (this.isEnabled()) { MobileNode mn = (MobileNode) this.getTargetNode(); // Assemble an SMS and send it to the current anteanna - SmsMessage msg = new SmsMessage(mn.getNextSeqID(), this.destination, this.getTargetNode(), this.text, this); + SmsMessage msg = new SmsMessage(mn.getNextSeqID(), this.getDestination(), this.getTargetNode(), this.getText(), this); Antenna a = mn.getCurrentAntenna(); if (a != null) { this.getTargetNode().send(msg, a); diff --git a/src/main/java/projects/sample4/nodes/messages/S4Message.java b/src/main/java/projects/sample4/nodes/messages/S4Message.java index 22f15db..63e5aed 100644 --- a/src/main/java/projects/sample4/nodes/messages/S4Message.java +++ b/src/main/java/projects/sample4/nodes/messages/S4Message.java @@ -36,13 +36,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.sample4.nodes.messages; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.messages.Message; import java.awt.*; public class S4Message extends Message { - public Color color; // the color the receiver should take + @Getter + @Setter + private Color color; // the color the receiver should take @Override public Message clone() { diff --git a/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java b/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java index 05444e7..03ff168 100644 --- a/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java +++ b/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java @@ -67,12 +67,12 @@ public class S4Node extends Node { if (msg instanceof S4Message) { S4Message m = (S4Message) msg; // green and yellow messages are forwarded to all neighbors - if (m.color == Color.GREEN && !this.getColor().equals(m.color)) { + if (m.getColor() == Color.GREEN && !this.getColor().equals(m.getColor())) { this.broadcast(m); - } else if (m.color == Color.YELLOW && !this.getColor().equals(m.color)) { + } else if (m.getColor() == Color.YELLOW && !this.getColor().equals(m.getColor())) { this.broadcast(m); } - this.setColor(m.color); // set this node's color + this.setColor(m.getColor()); // set this node's color } } } @@ -107,7 +107,7 @@ public class S4Node extends Node { */ private void sendColorMessage(Color c, Node to) { S4Message msg = new S4Message(); - msg.color = c; + msg.setColor(c); if (Tools.isSimulationInAsynchroneMode()) { // sending the messages directly is OK in async mode if (to != null) { @@ -162,7 +162,7 @@ public class S4Node extends Node { return; // the user aborted } S4Message msg = new S4Message(); - msg.color = Color.pink; + msg.setColor(Color.pink); if (Tools.isSimulationInAsynchroneMode()) { this.sendDirect(msg, n); } else { diff --git a/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java b/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java index 81c4d87..3eb948b 100644 --- a/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java +++ b/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java @@ -1,5 +1,7 @@ package projects.sample5.nodes.messages; +import lombok.Getter; +import lombok.Setter; import projects.sample5.nodes.timers.RetryFloodingTimer; import sinalgo.nodes.Node; import sinalgo.nodes.messages.Message; @@ -8,51 +10,53 @@ import sinalgo.nodes.messages.Message; * The message used to determine a route between two nodes using incremental * flooding. This message requires the read-only policy. */ +@Getter +@Setter public class FloodFindMsg extends Message { /** * True if this is a find-message, false if it is the answer-message that * returns from the destination when the flooding was successful. */ - public boolean isFindMessage; + private boolean isFindMessage; /** * The TTL for this message when it's being sent as a find-msg */ - public int ttl; + private int ttl; /** * The node that wishes to determine the route to the desinationNode; */ - public Node sender; + private Node sender; /** * Number of hops to sender */ - public int hopsToSender; + private int hopsToSender; /** * Sequence ID of this message */ - public int sequenceID; + private int sequenceID; - public RetryFloodingTimer retryTimer = null; + private RetryFloodingTimer retryTimer = null; /** * The node to which a route should be established. */ - public Node destination; + private Node destination; /** * Default constructor. */ public FloodFindMsg(int seqID, Node sender, Node dest) { - this.ttl = 4; // initial TTL - this.isFindMessage = true; - this.hopsToSender = 0; - this.sequenceID = seqID; - this.sender = sender; - this.destination = dest; + this.setTtl(4); // initial TTL + this.setFindMessage(true); + this.setHopsToSender(0); + this.setSequenceID(seqID); + this.setSender(sender); + this.setDestination(dest); } @Override @@ -65,12 +69,11 @@ public class FloodFindMsg extends Message { * @return A real clone of this message, i.e. a new message object */ public FloodFindMsg getRealClone() { - FloodFindMsg msg = new FloodFindMsg(this.sequenceID, this.sender, this.destination); - msg.ttl = this.ttl; - msg.isFindMessage = this.isFindMessage; - msg.hopsToSender = this.hopsToSender; - msg.retryTimer = this.retryTimer; + FloodFindMsg msg = new FloodFindMsg(this.getSequenceID(), this.getSender(), this.getDestination()); + msg.setTtl(this.getTtl()); + msg.setFindMessage(this.isFindMessage()); + msg.setHopsToSender(this.getHopsToSender()); + msg.setRetryTimer(this.getRetryTimer()); return msg; } - } diff --git a/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java b/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java index 1639773..d91016c 100644 --- a/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java +++ b/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java @@ -1,5 +1,7 @@ package projects.sample5.nodes.messages; +import lombok.Getter; +import lombok.Setter; import projects.sample5.nodes.timers.RetryPayloadMessageTimer; import sinalgo.nodes.Node; import sinalgo.nodes.messages.Message; @@ -7,14 +9,16 @@ import sinalgo.nodes.messages.Message; /** * A message used to transport data from a sender to a receiver */ +@Getter +@Setter public class PayloadMsg extends Message { - public Node destination; // node who should receive this msg - public Node sender; // node who sent this msg - public int sequenceNumber; // a number to identify this msg, set by the sender - public RetryPayloadMessageTimer ackTimer; // The timer set on the sender that will fire if there is no ACK returning + private Node destination; // node who should receive this msg + private Node sender; // node who sent this msg + private int sequenceNumber; // a number to identify this msg, set by the sender + private RetryPayloadMessageTimer ackTimer; // The timer set on the sender that will fire if there is no ACK returning // from the destination - public boolean requireACK = false; // Indicates whether this msg needs to be ACKed + private boolean requireACK = false; // Indicates whether this msg needs to be ACKed /** * Constructor @@ -23,8 +27,8 @@ public class PayloadMsg extends Message { * @param sender The sender who sends this msg */ public PayloadMsg(Node destination, Node sender) { - this.destination = destination; - this.sender = sender; + this.setDestination(destination); + this.setSender(sender); } @Override diff --git a/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java b/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java index 4d05b42..2666e0d 100644 --- a/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java +++ b/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java @@ -78,66 +78,66 @@ public class FNode extends Node { if (msg instanceof FloodFindMsg) { // This node received a flooding message. // --------------------------------------------------------------- FloodFindMsg m = (FloodFindMsg) msg; - if (m.isFindMessage) { + if (m.isFindMessage()) { // forward the message, it's a find-message that has to be // forwarded if the TTL allows. At the same time, update this node's routing // table s.t. it knows how to route to the sender of the flooding-msg. boolean forward = true; - if (m.sender.equals(this)) { // the message bounced back - discard the msg + if (m.getSender().equals(this)) { // the message bounced back - discard the msg forward = false; } else { // update routing table to the sender of this node - RoutingEntry re = this.routingTable.get(m.sender); + RoutingEntry re = this.routingTable.get(m.getSender()); if (re == null) { // add a new routing entry - this.routingTable.put(m.sender, - new RoutingEntry(m.sequenceID, m.hopsToSender, inbox.getSender())); - this.useNewRoutingInfo(m.destination, inbox.getSender()); - } else if (re.sequenceNumber < m.sequenceID) { // update the existing entry - re.numHops = m.hopsToSender; - re.sequenceNumber = m.sequenceID; + this.routingTable.put(m.getSender(), + new RoutingEntry(m.getSequenceID(), m.getHopsToSender(), inbox.getSender())); + this.useNewRoutingInfo(m.getDestination(), inbox.getSender()); + } else if (re.sequenceNumber < m.getSequenceID()) { // update the existing entry + re.numHops = m.getHopsToSender(); + re.sequenceNumber = m.getSequenceID(); re.nextHop = inbox.getSender(); } else { forward = false; // we've already seen this message once - don't forward it a 2nd time } } - if (m.destination.equals(this)) { // the lookup has succeeded, this is the node that was searched + if (m.getDestination().equals(this)) { // the lookup has succeeded, this is the node that was searched this.setColor(Color.BLUE); FloodFindMsg copy = m.getRealClone(); - copy.hopsToSender = 1; // now, this field contains the hops to the destination - copy.isFindMessage = false; - copy.sequenceID = ++this.seqID; + copy.setHopsToSender(1); // now, this field contains the hops to the destination + copy.setFindMessage(false); + copy.setSequenceID(++this.seqID); this.send(copy, inbox.getSender()); // send back the echo message forward = false; } - if (forward && m.ttl > 1) { // forward the flooding request + if (forward && m.getTtl() > 1) { // forward the flooding request FloodFindMsg copy = m.getRealClone(); - copy.ttl--; - copy.hopsToSender++; + copy.setTtl(copy.getTtl() - 1); + copy.setHopsToSender(copy.getHopsToSender() + 1); this.broadcast(copy); } } else { // return the message back to the sender // update the routing table boolean forward = true; this.setColor(Color.GREEN); - RoutingEntry re = this.routingTable.get(m.destination); + RoutingEntry re = this.routingTable.get(m.getDestination()); if (re == null) { // add a new routing entry - this.routingTable.put(m.destination, - new RoutingEntry(m.sequenceID, m.hopsToSender, inbox.getSender())); - this.useNewRoutingInfo(m.destination, inbox.getSender()); - } else if (re.sequenceNumber < m.sequenceID) { // update the existing entry - re.numHops = m.hopsToSender; - re.sequenceNumber = m.sequenceID; + this.routingTable.put(m.getDestination(), + new RoutingEntry(m.getSequenceID(), m.getHopsToSender(), inbox.getSender())); + this.useNewRoutingInfo(m.getDestination(), inbox.getSender()); + } else if (re.sequenceNumber < m.getSequenceID()) { // update the existing entry + re.numHops = m.getHopsToSender(); + re.sequenceNumber = m.getSequenceID(); re.nextHop = inbox.getSender(); } else { forward = false; } - if (m.sender.equals(this)) { + if (m.getSender().equals(this)) { // this node sent the request - remove timers - m.retryTimer.deactivate(); + m.getRetryTimer().deactivate(); } else if (forward) { - re = this.routingTable.get(m.sender); + re = this.routingTable.get(m.getSender()); if (re != null) { - m.hopsToSender++; // we can modify the message, its a unicast + m.setHopsToSender(m.getHopsToSender() + 1); // we can modify the message, its a unicast this.send(m, re.nextHop); } } @@ -146,17 +146,17 @@ public class FNode extends Node { // --------------------------------------------------------------- if (msg instanceof PayloadMsg) { PayloadMsg m = (PayloadMsg) msg; - if (m.destination.equals(this)) { // the message was for this node + if (m.getDestination().equals(this)) { // the message was for this node if (msg instanceof AckPayload) { // it is an ACK message - m.ackTimer.deactivate(); + m.getAckTimer().deactivate(); this.setColor(Color.ORANGE); } else { // it is a Payload Msg // handle the payload this.setColor(Color.YELLOW); // send back an ACK - AckPayload ack = new AckPayload(m.sender, this); - ack.sequenceNumber = m.sequenceNumber; - ack.ackTimer = m.ackTimer; + AckPayload ack = new AckPayload(m.getSender(), this); + ack.setSequenceNumber(m.getSequenceNumber()); + ack.setAckTimer(m.getAckTimer()); this.sendPayloadMessage(ack); } } else { // the message was not for this node -> forward @@ -182,8 +182,8 @@ public class FNode extends Node { return; // aborted } PayloadMsg msg = new PayloadMsg(n, FNode.this); - msg.requireACK = true; - msg.sequenceNumber = ++FNode.this.seqID; + msg.setRequireACK(true); + msg.setSequenceNumber(++FNode.this.seqID); PayloadMessageTimer t = new PayloadMessageTimer(msg); t.startRelative(1, FNode.this); }, "Select a node to send a message to..."); @@ -197,20 +197,20 @@ public class FNode extends Node { * @param msg The message to be sent. */ public void sendPayloadMessage(PayloadMsg msg) { - RoutingEntry re = this.routingTable.get(msg.destination); + RoutingEntry re = this.routingTable.get(msg.getDestination()); if (re != null) { - if (msg.sender.equals(this) && msg.requireACK) { // this node wants to have the message sent - it waits for + if (msg.getSender().equals(this) && msg.isRequireACK()) { // this node wants to have the message sent - it waits for // an ack RetryPayloadMessageTimer rpmt = new RetryPayloadMessageTimer(msg); rpmt.startRelative(re.numHops * 3, this); // We wait a bit longer than necessary - if (msg.ackTimer != null) { - msg.ackTimer.deactivate(); + if (msg.getAckTimer() != null) { + msg.getAckTimer().deactivate(); } - msg.ackTimer = rpmt; + msg.setAckTimer(rpmt); } this.send(msg, re.nextHop); } else { - this.lookForNode(msg.destination, 4); + this.lookForNode(msg.getDestination(), 4); this.messagesOnHold.add(msg); } } @@ -227,12 +227,12 @@ public class FNode extends Node { } FloodFindMsg m = new FloodFindMsg(++this.seqID, this, destination); - m.ttl = ttl; - RetryFloodingTimer rft = new RetryFloodingTimer(destination, m.ttl); + m.setTtl(ttl); + RetryFloodingTimer rft = new RetryFloodingTimer(destination, m.getTtl()); // The TTL must depend on the message transmission time. We assume here a // constant msg. transm. time of 1 unit. - rft.startRelative(m.ttl * 2 + 1, this); - m.retryTimer = rft; + rft.startRelative(m.getTtl() * 2 + 1, this); + m.setRetryTimer(rft); this.broadcast(m); } @@ -240,7 +240,7 @@ public class FNode extends Node { Iterator<PayloadMsg> it = this.messagesOnHold.iterator(); while (it.hasNext()) { PayloadMsg m = it.next(); - if (m.destination.equals(destination)) { + if (m.getDestination().equals(destination)) { this.sendPayloadMessage(m); it.remove(); } diff --git a/src/main/java/projects/sample6/CustomGlobal.java b/src/main/java/projects/sample6/CustomGlobal.java index 29f2a75..1d273b7 100644 --- a/src/main/java/projects/sample6/CustomGlobal.java +++ b/src/main/java/projects/sample6/CustomGlobal.java @@ -125,7 +125,7 @@ public class CustomGlobal extends AbstractCustomGlobal { this.treeNodes.clear(); this.leaves.clear(); // Reset ID counter of leaf-nodes - LeafNode.smallIdCounter = 0; + LeafNode.setSmallIdCounter(0); // some vectors to store the nodes that we still need to process Vector<TreeNode> toProcess = new Vector<>(); @@ -170,7 +170,7 @@ public class CustomGlobal extends AbstractCustomGlobal { numAdded = 0; } currentNode.addConnectionTo(tn); - currentNode.parent = tn; + currentNode.setParent(tn); numAdded++; if (numAdded >= fanOut) { tn.setPosition((leftMostXOffset + currentNode.getPosition().getXCoord()) / 2, posY, 0); diff --git a/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java b/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java index 214cacb..106486c 100644 --- a/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java +++ b/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java @@ -1,5 +1,7 @@ package projects.sample6.nodes.nodeImplementations; +import lombok.Getter; +import lombok.Setter; import projects.sample6.nodes.messages.MarkMessage; import sinalgo.exception.WrongConfigurationException; import sinalgo.gui.transformation.PositionTransformation; @@ -11,14 +13,20 @@ import java.awt.*; /** * A node on the bottom of the tree */ +@Getter +@Setter public class LeafNode extends TreeNode { // A counter that may be reset by the user - public static int smallIdCounter = 0; - public int smallID; + @Getter + @Setter + private static int smallIdCounter = 0; + + private int smallID; public LeafNode() { - this.smallID = ++smallIdCounter; + setSmallIdCounter(getSmallIdCounter() + 1); + this.setSmallID(getSmallIdCounter()); } @Override @@ -53,12 +61,12 @@ public class LeafNode extends TreeNode { @Override public void draw(Graphics g, PositionTransformation pt, boolean highlight) { - super.drawNodeAsDiskWithText(g, pt, highlight, Integer.toString(this.smallID), 15, Color.YELLOW); + super.drawNodeAsDiskWithText(g, pt, highlight, Integer.toString(this.getSmallID()), 15, Color.YELLOW); } @Override public String toString() { - return this.smallID + " (" + this.getID() + ")"; + return this.getSmallID() + " (" + this.getID() + ")"; } } diff --git a/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java b/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java index ed499c7..9fbab4c 100644 --- a/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java +++ b/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java @@ -1,5 +1,7 @@ package projects.sample6.nodes.nodeImplementations; +import lombok.Getter; +import lombok.Setter; import projects.defaultProject.nodes.timers.MessageTimer; import projects.sample6.nodes.messages.MarkMessage; import sinalgo.exception.WrongConfigurationException; @@ -16,7 +18,9 @@ import java.awt.*; */ public class TreeNode extends Node { - public TreeNode parent = null; // the parentGUI in the tree, null if this node is the root + @Getter + @Setter + private TreeNode parent = null; // the parentGUI in the tree, null if this node is the root @Override public void checkRequirements() throws WrongConfigurationException { @@ -27,13 +31,13 @@ public class TreeNode extends Node { while (inbox.hasNext()) { Message m = inbox.next(); if (m instanceof MarkMessage) { - if (this.parent == null || !inbox.getSender().equals(this.parent)) { + if (this.getParent() == null || !inbox.getSender().equals(this.getParent())) { continue;// don't consider mark messages sent by children } this.setColor(Color.RED); // forward the message to all children for (Edge e : this.getOutgoingConnections()) { - if (!e.getEndNode().equals(this.parent)) { // don't send it to the parentGUI + if (!e.getEndNode().equals(this.getParent())) { // don't send it to the parentGUI this.send(m, e.getEndNode()); } } diff --git a/src/main/java/sinalgo/Run.java b/src/main/java/sinalgo/Run.java index 9ddb5c4..7c7bfd9 100644 --- a/src/main/java/sinalgo/Run.java +++ b/src/main/java/sinalgo/Run.java @@ -126,7 +126,7 @@ public class Run { // Setting it to server mode s = s.replaceFirst("server=n", "server=y"); // Do NOT block until the debugger has attached - s = s.replaceFirst("suspend=y", "suspend=y"); + s = s.replaceFirst("suspend=y", "suspend=n"); } return s; }) diff --git a/src/main/java/sinalgo/configuration/AppConfig.java b/src/main/java/sinalgo/configuration/AppConfig.java index a5ee084..d5bd75f 100644 --- a/src/main/java/sinalgo/configuration/AppConfig.java +++ b/src/main/java/sinalgo/configuration/AppConfig.java @@ -112,16 +112,16 @@ public class AppConfig { @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private static Supplier<AppConfig> appConfigProvider = () -> { - AppConfig.setSingletonInstance(new AppConfig()); - AppConfig.setAppConfigProvider(AppConfig::getSingletonInstance); - return AppConfig.getAppConfig(); + setSingletonInstance(new AppConfig()); + setAppConfigProvider(AppConfig::getSingletonInstance); + return getAppConfig(); }; /** * @return The singleton instance of AppConfig. */ public static AppConfig getAppConfig() { - return AppConfig.getAppConfigProvider().get(); + return getAppConfigProvider().get(); } /** diff --git a/src/main/java/sinalgo/configuration/Configuration.java b/src/main/java/sinalgo/configuration/Configuration.java index 3663b45..1ba2e41 100644 --- a/src/main/java/sinalgo/configuration/Configuration.java +++ b/src/main/java/sinalgo/configuration/Configuration.java @@ -1270,8 +1270,8 @@ public class Configuration { + "------------------------------------------------------"); // Command Line Args ps.print("Command Line arguments: "); - if (Main.cmdLineArgs != null) { - for (String entry : Main.cmdLineArgs) { + if (Main.getCmdLineArgs() != null) { + for (String entry : Main.getCmdLineArgs()) { ps.print(entry + " "); } } diff --git a/src/main/java/sinalgo/gui/GraphPanel.java b/src/main/java/sinalgo/gui/GraphPanel.java index 928a9cf..f54bb00 100644 --- a/src/main/java/sinalgo/gui/GraphPanel.java +++ b/src/main/java/sinalgo/gui/GraphPanel.java @@ -319,7 +319,7 @@ public class GraphPanel extends JPanel { this.pt.drawBackground(g); if (Configuration.isUseMap()) { - SinalgoRuntime.map.paintMap(g, this.getPt()); + SinalgoRuntime.getMap().paintMap(g, this.getPt()); } g.setColor(Color.BLACK); @@ -329,7 +329,7 @@ public class GraphPanel extends JPanel { // First draw all edges, only then the nodes Enumeration<Node> nodeEnumer; if (Configuration.isDrawEdges()) { - nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(true); + nodeEnumer = SinalgoRuntime.getNodes().getSortedNodeEnumeration(true); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); // first draw all outgoing edges of this node @@ -341,7 +341,7 @@ public class GraphPanel extends JPanel { // Draw the nodes in a separate loop if (Configuration.isDrawNodes()) { // Draw the nodes in a separate loop - nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(true); + nodeEnumer = SinalgoRuntime.getNodes().getSortedNodeEnumeration(true); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); node.draw(g, this.getPt(), false); @@ -530,7 +530,7 @@ public class GraphPanel extends JPanel { Edge edgeUnderPos = null; - Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(false); + Enumeration<Node> nodeEnumer = SinalgoRuntime.getNodes().getSortedNodeEnumeration(false); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); if (node.isInside(event.getX(), event.getY(), this.getPt())) { @@ -641,7 +641,7 @@ public class GraphPanel extends JPanel { * no node covers this position. */ public Node getFirstNodeAtPosition(int x, int y) { - Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(false); + Enumeration<Node> nodeEnumer = SinalgoRuntime.getNodes().getSortedNodeEnumeration(false); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); if (node.isInside(x, y, this.getPt())) { @@ -835,7 +835,7 @@ public class GraphPanel extends JPanel { Edge clickedEdge = null; // go throught all the nodes and their edges to find out, if one is under the // cursor - Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(false); + Enumeration<Node> nodeEnumer = SinalgoRuntime.getNodes().getSortedNodeEnumeration(false); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); if (node.isInside(event.getX(), event.getY(), GraphPanel.this.getPt())) { diff --git a/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java b/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java index 7e0c39b..9d15c71 100644 --- a/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java @@ -376,7 +376,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis this.composeEventList(); this.setEventList(new EventQueueList(this.getQueueElements())); - SinalgoRuntime.eventQueue.addEventQueueListener(MaximizedControlPanel.this); + SinalgoRuntime.getEventQueue().addEventQueueListener(MaximizedControlPanel.this); this.getEventList().setCellRenderer(new NonColoringNonBorderingCellRenderer()); this.getEventList().setFixedCellHeight(fixedCellHeight); this.getEventList().setFixedCellWidth(fixedCellWidth); @@ -629,7 +629,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis } private void composeEventList() { - Iterator<Event> eventIter = SinalgoRuntime.eventQueue.iterator(); + Iterator<Event> eventIter = SinalgoRuntime.getEventQueue().iterator(); for (EventQueueElement queueElement : this.getQueueElements()) { if (eventIter.hasNext()) { Event e = eventIter.next(); diff --git a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java index 875d75d..132caae 100644 --- a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java @@ -414,7 +414,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog if (this.isCanceled()) { for (Node n : addedNodes) { - SinalgoRuntime.nodes.removeNode(n); + SinalgoRuntime.getNodes().removeNode(n); i--; this.getPf().setPercentage(100.0d * ((double) i / (double) this.getNumberOfNodes())); } diff --git a/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java b/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java index 3e7d1b0..06914ab 100644 --- a/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java @@ -69,7 +69,7 @@ public class GraphInfoDialog extends JDialog implements ActionListener { GuiHelper.setWindowIcon(this); // determine the number of nodes and edges - Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); + Enumeration<Node> nodeEnumer = SinalgoRuntime.getNodes().getNodeEnumeration(); int numNodes = 0; int numEdges = 0; diff --git a/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java b/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java index 36bb2db..0d9f883 100644 --- a/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java @@ -111,7 +111,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC // has no // previous respective next element. boolean hasPrev = false; - Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); + Enumeration<Node> nodesEnumer = SinalgoRuntime.getNodes().getNodeEnumeration(); while (nodesEnumer.hasMoreElements()) { Node nd = nodesEnumer.nextElement(); if (nd.getID() == n.getID()) { @@ -296,7 +296,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC this.getParentGUI().redrawGUINow(); // needs blocking redrawing break; case "Next Node": { - Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); + Enumeration<Node> nodesEnumer = SinalgoRuntime.getNodes().getNodeEnumeration(); while (nodesEnumer.hasMoreElements()) { Node nd = nodesEnumer.nextElement(); if (nd.getID() == this.getNode().getID() + 1) { @@ -308,7 +308,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC break; } case "Previous Node": { - Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); + Enumeration<Node> nodesEnumer = SinalgoRuntime.getNodes().getNodeEnumeration(); while (nodesEnumer.hasMoreElements()) { Node nd = nodesEnumer.nextElement(); if (nd.getID() == this.getNode().getID() - 1) { @@ -328,7 +328,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC int newId = (Integer) evt.getNewValue(); boolean hasPrev = false; - Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); + Enumeration<Node> nodesEnumer = SinalgoRuntime.getNodes().getNodeEnumeration(); while (nodesEnumer.hasMoreElements()) { Node nd = nodesEnumer.nextElement(); if (nd.getID() == newId) { diff --git a/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java b/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java index 89f5336..9fa6c26 100644 --- a/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java +++ b/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.io.eps; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.exception.SinalgoFatalException; import java.io.File; @@ -61,14 +64,36 @@ import java.util.HashMap; * direct output to the file use the mirror-method to mirror the y coordinates * correctly. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class EPSOutputPrintStream extends PrintStream { - private int boundingBoxX = 0, boundingBoxY = 0, boundingBoxWidth = 0, boundingBoxHeight = 0; + private int boundingBoxX = 0; + private int boundingBoxY = 0; + private int boundingBoxWidth = 0; + private int boundingBoxHeight = 0; private HashMap<String, String> macros = new HashMap<>(); - private double colorR = 0, colorG = 0, colorB = 0; + private double colorR = 0; + private double colorG = 0; + private double colorB = 0; private double lineWidth = 1.0; + /** + * The length of the arrows for all the successive arrows until the next + * call of setArrowLength. + * + * @param arrowLength The length of the Arrows. + */ + @Setter private double arrowLength = 10; + + /** + * The width of the arrows for all the successive arrows until the next + * call of setArrowWidth. + * + * @param width The width of the Arrows. + */ + @Setter private double arrowWidth = 2; private int fontSize = 12; @@ -97,10 +122,10 @@ public class EPSOutputPrintStream extends PrintStream { * setLineWidth. */ public void setLineWidth(double width) { - if (this.lineWidth != width) { + if (this.getLineWidth() != width) { // only print it if the width changed. this.lineWidth = width; - this.println("0 " + this.lineWidth + " dtransform truncate idtransform setlinewidth pop"); + this.println("0 " + this.getLineWidth() + " dtransform truncate idtransform setlinewidth pop"); } } @@ -115,12 +140,12 @@ public class EPSOutputPrintStream extends PrintStream { */ public void setColor(int r, int g, int b) { double dR = this.mapIntColToDoubleCol(r), dG = this.mapIntColToDoubleCol(g), dB = this.mapIntColToDoubleCol(b); - if ((this.colorR != dR) || (this.colorG != dG) || (this.colorB != dB)) { + if ((this.getColorR() != dR) || (this.getColorG() != dG) || (this.getColorB() != dB)) { // only print the statement, if the color changed - this.colorR = dR; - this.colorG = dG; - this.colorB = dB; - this.println(this.colorR + " " + this.colorG + " " + this.colorB + " setrgbcolor"); + this.setColorR(dR); + this.setColorG(dG); + this.setColorB(dB); + this.println(this.getColorR() + " " + this.getColorG() + " " + this.getColorB() + " setrgbcolor"); } } @@ -141,30 +166,10 @@ public class EPSOutputPrintStream extends PrintStream { * @param height The height of the bounding box. */ public void setBoundingBox(int x, int y, int width, int height) { - this.boundingBoxX = x; - this.boundingBoxY = y; - this.boundingBoxWidth = width; - this.boundingBoxHeight = height; - } - - /** - * Sets the length of the arrows for all the successive arrows until the next - * call of setArrowLength. - * - * @param length The length of the Arrows. - */ - public void setArrowLength(double length) { - this.arrowLength = length; - } - - /** - * Sets the width of the arrows for all the successive arrows until the next - * call of setArrowWidth. - * - * @param width The width of the Arrows. - */ - public void setArrowWidth(double width) { - this.arrowWidth = width; + this.setBoundingBoxX(x); + this.setBoundingBoxY(y); + this.setBoundingBoxWidth(width); + this.setBoundingBoxHeight(height); } // helpers @@ -282,9 +287,9 @@ public class EPSOutputPrintStream extends PrintStream { if (x1 != x2 || y1 != y2) { double lineLength = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); double factor = 1.0 / lineLength; - double aLen = this.arrowLength; + double aLen = this.getArrowLength(); // shorten the arrow if the two nodes are very close - if (2 * this.arrowLength >= lineLength) { + if (2 * this.getArrowLength() >= lineLength) { aLen = lineLength / 3; } @@ -302,10 +307,10 @@ public class EPSOutputPrintStream extends PrintStream { // one end-point of the triangle is (x2,y2), the second end-point (ex1, ey1) and // the third (ex2, ey2) - double ex1 = ix + this.arrowWidth * uy; - double ey1 = iy - this.arrowWidth * ux; - double ex2 = ix - this.arrowWidth * uy; - double ey2 = iy + this.arrowWidth * ux; + double ex1 = ix + this.getArrowWidth() * uy; + double ey1 = iy - this.getArrowWidth() * ux; + double ex2 = ix - this.getArrowWidth() * uy; + double ey2 = iy + this.getArrowWidth() * ux; this.println(x2 + " " + this.mirrorCoords(y2) + " " + ex1 + " " + this.mirrorCoords(ey1) + " " + ex2 + " " + this.mirrorCoords(ey2) + " filledArrowHead"); @@ -330,7 +335,7 @@ public class EPSOutputPrintStream extends PrintStream { * @param size The size of the font to print successive texts with. */ public void setFontSize(int size) { - if (size != this.fontSize) { + if (size != this.getFontSize()) { this.println(size + " scalefont setfont"); this.fontSize = size; } @@ -342,7 +347,7 @@ public class EPSOutputPrintStream extends PrintStream { * @param font The font to print successive texts with. */ public void setFont(String font) { - if (!font.equals(this.font)) { + if (!font.equals(this.getFont())) { this.println("/" + font + " findfont\n"); this.font = font; } @@ -361,15 +366,15 @@ public class EPSOutputPrintStream extends PrintStream { * @param command The commands of the macro. */ public void addMacro(String name, String command) { - if (!this.macros.containsKey(name)) { // we have a new macro + if (!this.getMacros().containsKey(name)) { // we have a new macro this.println("/" + name + " {" + command + "} def"); - this.macros.put(name, command); + this.getMacros().put(name, command); } else { - if (!this.macros.get(name).equals(command)) { + if (!this.getMacros().get(name).equals(command)) { // print it as it is different to the one specified before with the same name this.println("/" + name + " {" + command + "} def"); // replace the one in the map by this one. - this.macros.put(name, command); + this.getMacros().put(name, command); } } } @@ -387,12 +392,12 @@ public class EPSOutputPrintStream extends PrintStream { * @return The mirrored y component of the eps coordinate. */ public double mirrorCoords(double original) { - if (this.boundingBoxHeight == 0) { + if (this.getBoundingBoxHeight() == 0) { throw new SinalgoFatalException( "The height of the bounding box is 0 and thus the coordinates can not be mirrored correctly. Please " + "set the bounding box of the graph prior to drawing items."); } - return this.boundingBoxHeight - original; + return this.getBoundingBoxHeight() - original; } /** @@ -401,15 +406,15 @@ public class EPSOutputPrintStream extends PrintStream { */ public void writeHeader() { this.println("%!PS-Adobe-3.0 EPSF-3.0"); - this.println("%%BoundingBox: " + this.boundingBoxX + " " + this.boundingBoxY + " " + this.boundingBoxWidth + " " - + this.boundingBoxHeight); + this.println("%%BoundingBox: " + this.getBoundingBoxX() + " " + this.getBoundingBoxY() + " " + this.getBoundingBoxWidth() + " " + + this.getBoundingBoxHeight()); this.println("%%Creator: Sinalgo"); this.println("%%Pages: 1"); this.println("%%EndComments"); this.println("%%Page: 1 1"); this.println(); - this.println("/" + this.font + " findfont"); - this.println(this.fontSize + " scalefont setfont"); + this.println("/" + this.getFont() + " findfont"); + this.println(this.getFontSize() + " scalefont setfont"); this.println(); } diff --git a/src/main/java/sinalgo/io/eps/Exporter.java b/src/main/java/sinalgo/io/eps/Exporter.java index 4f1bc00..029f2e3 100644 --- a/src/main/java/sinalgo/io/eps/Exporter.java +++ b/src/main/java/sinalgo/io/eps/Exporter.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.io.eps; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.exception.ExportException; @@ -59,7 +62,9 @@ import java.util.Random; */ public class Exporter { - private JFrame parent = null; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private JFrame parentFrame = null; /** * Creates a new Exporter instance with a given JFrame as parentGUI. The parentGUI @@ -68,7 +73,7 @@ public class Exporter { * @param p The parentGUI frame to attach the save-dialog to. */ public Exporter(JFrame p) { - this.parent = p; + this.setParentFrame(p); } /** @@ -107,7 +112,7 @@ public class Exporter { fc.setAcceptAllFileFilterUsed(false); // only allow the above file types - if (fc.showSaveDialog(this.parent) == JFileChooser.APPROVE_OPTION) { + if (fc.showSaveDialog(this.getParentFrame()) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (file.exists()) { @@ -155,7 +160,7 @@ public class Exporter { // print the map prior to the background (such that the border is on top of the // map if (Configuration.isUseMap()) { - SinalgoRuntime.map.drawToPostScript(pw, pt); + SinalgoRuntime.getMap().drawToPostScript(pw, pt); } // draw the background @@ -165,7 +170,7 @@ public class Exporter { // draw the edges if (Configuration.isDrawEdges()) { - Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(true); + Enumeration<Node> nodeEnumer = SinalgoRuntime.getNodes().getSortedNodeEnumeration(true); while (nodeEnumer.hasMoreElements()) { Node n = nodeEnumer.nextElement(); for (Edge e : n.getOutgoingConnections()) { @@ -176,7 +181,7 @@ public class Exporter { if (Configuration.isDrawNodes()) { // draw the nodes - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { n.drawToPostScript(pw, pt); } } @@ -260,37 +265,24 @@ public class Exporter { /** * A single File Filter allowing only one file-type and directories. */ + @Getter + @Setter public static abstract class SingleFileFilter extends FileFilter { /** * The only file-extension this filter allows. - */ - private String extension = ""; - - /** - * Sets the only file-extension this filter allows. - * - * @param ext the only file-extension this filter allows. - */ - public void setExtension(String ext) { - this.extension = ext; - } - - /** - * Returns the only file-extension this filter allows. * + * @param extension the only file-extension this filter allows. * @return only file-extension this filter allows. */ - public String getExtension() { - return this.extension; - } + private String extension = ""; @Override public boolean accept(File pathname) { if (pathname.isDirectory()) { return true; } - return pathname.getName().toLowerCase().endsWith(this.extension); + return pathname.getName().toLowerCase().endsWith(this.getExtension()); } } diff --git a/src/main/java/sinalgo/io/mapIO/Rectangle.java b/src/main/java/sinalgo/io/mapIO/Rectangle.java index da102c1..defb858 100644 --- a/src/main/java/sinalgo/io/mapIO/Rectangle.java +++ b/src/main/java/sinalgo/io/mapIO/Rectangle.java @@ -36,28 +36,33 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.io.mapIO; +import lombok.Getter; +import lombok.Setter; + /** * The class for the maprectangles to draw the map with. The whole field is * partitioned into rectangles according to the size of the map. Each rectangle * corresponds to a value in the map-file. */ +@Getter +@Setter public class Rectangle { /** * The x position of top left corner of the rectangle. */ - public int x; + private int x; /** * The y position of top left corner of the rectangle. */ - public int y; + private int y; /** * The height of the rectangle. */ - public int height; + private int height; /** * The width of the rectangle. */ - public int width; + private int width; } diff --git a/src/main/java/sinalgo/models/ConnectivityModelHelper.java b/src/main/java/sinalgo/models/ConnectivityModelHelper.java index b5954b8..cae702d 100644 --- a/src/main/java/sinalgo/models/ConnectivityModelHelper.java +++ b/src/main/java/sinalgo/models/ConnectivityModelHelper.java @@ -68,7 +68,7 @@ public abstract class ConnectivityModelHelper extends ConnectivityModel { // is possible because of the rMax filed of the GeometricNodeCollection, which // indicates the maximum // distance between any two connected points. - Enumeration<Node> pNE = SinalgoRuntime.nodes.getPossibleNeighborsEnumeration(n); + Enumeration<Node> pNE = SinalgoRuntime.getNodes().getPossibleNeighborsEnumeration(n); while (pNE.hasMoreElements()) { Node possibleNeighbor = pNE.nextElement(); if (n.getID() != possibleNeighbor.getID()) { diff --git a/src/main/java/sinalgo/nodes/InboxPacketBuffer.java b/src/main/java/sinalgo/nodes/InboxPacketBuffer.java index 1fe8f40..5a1a916 100644 --- a/src/main/java/sinalgo/nodes/InboxPacketBuffer.java +++ b/src/main/java/sinalgo/nodes/InboxPacketBuffer.java @@ -103,7 +103,7 @@ public class InboxPacketBuffer extends DoublyLinkedList<Packet> implements Packe // only if added if (Configuration.isInterference()) { // remove it from the global queue - SinalgoRuntime.packetsInTheAir.remove(p); + SinalgoRuntime.getPacketsInTheAir().remove(p); } this.bufferIterator.remove(); diff --git a/src/main/java/sinalgo/nodes/Node.java b/src/main/java/sinalgo/nodes/Node.java index 6cec103..269f278 100644 --- a/src/main/java/sinalgo/nodes/Node.java +++ b/src/main/java/sinalgo/nodes/Node.java @@ -338,7 +338,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { public final void setPosition(double x, double y, double z) { this.getPosition().assign(x, y, z); this.cropPos(this.position); - SinalgoRuntime.nodes.updateNodeCollection(this); // note that this method tests whether the node is already added to + SinalgoRuntime.getNodes().updateNodeCollection(this); // note that this method tests whether the node is already added to // the node collection this.onChangePosition(); } @@ -413,7 +413,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { Packet sentP = this.sendMessage(m, connection, this, target, intensity); if (Configuration.isInterference()) { // only add the message in the packetsInTheAirBuffer, if interference is // turned on - SinalgoRuntime.packetsInTheAir.add(sentP); + SinalgoRuntime.getPacketsInTheAir().add(sentP); } } @@ -469,7 +469,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { if (Global.isAsynchronousMode()) { // add a packet event to the event list - SinalgoRuntime.eventQueue.insert(PacketEvent.getNewPacketEvent(packet, Global.getCurrentTime() + transmissionTime)); + SinalgoRuntime.getEventQueue().insert(PacketEvent.getNewPacketEvent(packet, Global.getCurrentTime() + transmissionTime)); } else { // Synchronous // check whether the simulation is currently running or not. if (!Global.isRunning()) { @@ -1171,17 +1171,17 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { if (p.getXCoord() < 0) { p.setXCoord(0); } else if (p.getXCoord() >= Configuration.getDimX()) { - p.setXCoord(Configuration.getDimX() - Position.epsilonPosition); + p.setXCoord(Configuration.getDimX() - Position.getEpsilonPosition()); } if (p.getYCoord() < 0) { p.setYCoord(0); } else if (p.getYCoord() >= Configuration.getDimY()) { - p.setYCoord(Configuration.getDimY() - Position.epsilonPosition); + p.setYCoord(Configuration.getDimY() - Position.getEpsilonPosition()); } if (p.getZCoord() < 0) { p.setZCoord(0); } else if (p.getZCoord() >= Configuration.getDimZ()) { - p.setZCoord(Configuration.getDimZ() - Position.epsilonPosition); + p.setZCoord(Configuration.getDimZ() - Position.getEpsilonPosition()); } } @@ -1294,7 +1294,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { Edge e = this.edgeIteratorInstance.next(); Packet sentP = this.sendMessage(m, e, e.getStartNode(), e.getEndNode(), intensity); sentP.setType(PacketType.MULTICAST); - SinalgoRuntime.packetsInTheAir.addPassivePacket(sentP); + SinalgoRuntime.getPacketsInTheAir().addPassivePacket(sentP); if (longestPacket == null || longestPacket.compareTo(sentP) < 0) { // NOTE that the second // statement is not @@ -1304,14 +1304,14 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { } } if (longestPacket != null) { - SinalgoRuntime.packetsInTheAir.upgradeToActivePacket(longestPacket); + SinalgoRuntime.getPacketsInTheAir().upgradeToActivePacket(longestPacket); } else { // there was no neighbor // For the interference, we need to send a packet anyways. Send it to this // node itself. Packet sentP = this.sendMessage(m, null, this, this, intensity); sentP.setType(PacketType.MULTICAST); sentP.denyDelivery(); // ensure that the packet never arrives at this node - SinalgoRuntime.packetsInTheAir.add(sentP); + SinalgoRuntime.getPacketsInTheAir().add(sentP); } } else { // no interference this.edgeIteratorInstance.reset(); @@ -1387,7 +1387,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { Global.setNumberOfMessagesOverAll(Global.getNumberOfMessagesOverAll() + 1); // statistics (don't increment the counter that counts the number of sent // messages per round. This counter has no meaning in the async mode.) - SinalgoRuntime.eventQueue.insert(PacketEvent.getNewPacketEvent(packet, Global.getCurrentTime() + transmissionTime)); + SinalgoRuntime.getEventQueue().insert(PacketEvent.getNewPacketEvent(packet, Global.getCurrentTime() + transmissionTime)); return packet; } diff --git a/src/main/java/sinalgo/nodes/Position.java b/src/main/java/sinalgo/nodes/Position.java index 2ba76e2..0c31454 100644 --- a/src/main/java/sinalgo/nodes/Position.java +++ b/src/main/java/sinalgo/nodes/Position.java @@ -36,9 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.nodes; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; /** * A simple vector implementation that describes the position of the nodes on @@ -56,7 +54,9 @@ public class Position { * Do always use this variable for such purposes, such that backtracking where * such rounding error corrections were made is possible. */ - public static double epsilonPosition = 10e-8; + @Getter + @Setter + private static double epsilonPosition = 10e-8; /** * The x coordinate of the position. diff --git a/src/main/java/sinalgo/nodes/edges/Edge.java b/src/main/java/sinalgo/nodes/edges/Edge.java index a61d75b..92e99c8 100644 --- a/src/main/java/sinalgo/nodes/edges/Edge.java +++ b/src/main/java/sinalgo/nodes/edges/Edge.java @@ -480,7 +480,7 @@ public class Edge implements DoublyLinkedListEntry { // This is quite slow as it iterates over all pending events. However, // synchronous simulations are not mobile, therefore this method is not called // often. - SinalgoRuntime.eventQueue.invalidatePacketEventsForThisEdge(this); + SinalgoRuntime.getEventQueue().invalidatePacketEventsForThisEdge(this); } else { this.getEndNode().getInboxPacketBuffer().invalidatePacketsSentOverThisEdge(this); } diff --git a/src/main/java/sinalgo/nodes/timers/Timer.java b/src/main/java/sinalgo/nodes/timers/Timer.java index 3ac72af..0ee4aba 100644 --- a/src/main/java/sinalgo/nodes/timers/Timer.java +++ b/src/main/java/sinalgo/nodes/timers/Timer.java @@ -95,7 +95,7 @@ public abstract class Timer implements Comparable<Timer> { this.setTargetNode(null); this.setFireTime(Global.getCurrentTime() + relativeTime); if (Global.isAsynchronousMode()) { - SinalgoRuntime.eventQueue.insert(TimerEvent.getNewTimerEvent(this, this.fireTime)); + SinalgoRuntime.getEventQueue().insert(TimerEvent.getNewTimerEvent(this, this.fireTime)); } else { Global.getCustomGlobal().getGlobalTimers().add(this); } @@ -120,7 +120,7 @@ public abstract class Timer implements Comparable<Timer> { this.setTargetNode(n); this.setFireTime(Global.getCurrentTime() + relativeTime); if (Global.isAsynchronousMode()) { - SinalgoRuntime.eventQueue.insert(TimerEvent.getNewTimerEvent(this, this.fireTime)); + SinalgoRuntime.getEventQueue().insert(TimerEvent.getNewTimerEvent(this, this.fireTime)); } else { this.getTargetNode().getTimers().add(this); } @@ -142,7 +142,7 @@ public abstract class Timer implements Comparable<Timer> { this.setTargetNode(n); this.setFireTime(absoluteTime); if (Global.isAsynchronousMode()) { - SinalgoRuntime.eventQueue.insert(TimerEvent.getNewTimerEvent(this, this.fireTime)); + SinalgoRuntime.getEventQueue().insert(TimerEvent.getNewTimerEvent(this, this.fireTime)); } else { this.getTargetNode().getTimers().add(this); } diff --git a/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java b/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java index 059b933..56e6a2a 100644 --- a/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java +++ b/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java @@ -103,7 +103,7 @@ public class AsynchronousRuntimeThread extends Thread { */ static void initializeConnectivity() { connectivityInitialized = true; - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { n.getConnectivityModel().updateConnections(n); } } @@ -127,12 +127,12 @@ public class AsynchronousRuntimeThread extends Thread { if (event != null) { event.free(); // free the previous event } - event = SinalgoRuntime.eventQueue.getNextEvent(); // returns null if there is no further event + event = SinalgoRuntime.getEventQueue().getNextEvent(); // returns null if there is no further event if (event == null && Configuration.isHandleEmptyEventQueue()) { Global.getCustomGlobal().handleEmptyEventQueue(); // and try again - event = SinalgoRuntime.eventQueue.getNextEvent(); // returns null if there is no further event + event = SinalgoRuntime.getEventQueue().getNextEvent(); // returns null if there is no further event } if (event == null) { Global.getLog().logln(LogL.EVENT_QUEUE_DETAILS, diff --git a/src/main/java/sinalgo/runtime/GUIRuntime.java b/src/main/java/sinalgo/runtime/GUIRuntime.java index 82e676e..50c42ef 100644 --- a/src/main/java/sinalgo/runtime/GUIRuntime.java +++ b/src/main/java/sinalgo/runtime/GUIRuntime.java @@ -80,7 +80,7 @@ public class GUIRuntime extends SinalgoRuntime implements ProgressBarUser { // In async mode, the user may specify to evaluate the connections immediately // at startup if (Global.isAsynchronousMode() && Configuration.isInitializeConnectionsOnStartup()) { - if (SinalgoRuntime.nodes.size() > 0) { + if (SinalgoRuntime.getNodes().size() > 0) { // when there are no nodes created yet, perform the initialization // only during the first step. AsynchronousRuntimeThread.initializeConnectivity(); diff --git a/src/main/java/sinalgo/runtime/Main.java b/src/main/java/sinalgo/runtime/Main.java index 4f4af45..a04b973 100644 --- a/src/main/java/sinalgo/runtime/Main.java +++ b/src/main/java/sinalgo/runtime/Main.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.runtime; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.exception.*; @@ -61,8 +64,12 @@ import java.lang.reflect.InvocationTargetException; */ public class Main { - static SinalgoRuntime runtime; - public static String[] cmdLineArgs; // the command line arguments + @Setter(AccessLevel.PACKAGE) + private static SinalgoRuntime runtime; + + @Getter + @Setter + private static String[] cmdLineArgs; // the command line arguments /** * This method is the one to start with. It starts the whole simulation. @@ -70,7 +77,7 @@ public class Main { * @param args The parameters to start the simulation with. */ public static void main(String[] args) { - cmdLineArgs = args; // store for later use + setCmdLineArgs(args); // store for later use Main main = new Main(); main.go(args); } @@ -128,11 +135,11 @@ public class Main { Global.setGuiMode(true); Global.getLog().logln(LogL.ALWAYS, "> Starting " + Configuration.getAppName() + " in GUI-Mode" + (Global.isUseProject() ? " for project " + Global.getProjectName() + "." : ".")); - runtime = new GUIRuntime(); + setRuntime(new GUIRuntime()); } else { // BATCH MODE Global.getLog().log(LogL.ALWAYS, "> Starting " + Configuration.getAppName() + " in BATCH-Mode" + (Global.isUseProject() ? " for project " + Global.getProjectName() + "." : ".")); - runtime = new BatchRuntime(); + setRuntime(new BatchRuntime()); } // initialize the DefaultMessageTransmissionModel (only after the runtime diff --git a/src/main/java/sinalgo/runtime/SinalgoRuntime.java b/src/main/java/sinalgo/runtime/SinalgoRuntime.java index 0e9836e..815bc0e 100644 --- a/src/main/java/sinalgo/runtime/SinalgoRuntime.java +++ b/src/main/java/sinalgo/runtime/SinalgoRuntime.java @@ -79,25 +79,32 @@ public abstract class SinalgoRuntime { * The collection of nodes stored in a slever way to fast retrieve the possible * neighbors. */ - public static AbstractNodeCollection nodes = createNewNodeCollection(); + @Getter + @Setter + private static AbstractNodeCollection nodes = createNewNodeCollection(); /** * The datastructure for all the messages, that are in the air in this moment. * This is important for the interference. */ - public static PacketsInTheAirBuffer packetsInTheAir = new PacketsInTheAirBuffer(); + @Getter + @Setter + private static PacketsInTheAirBuffer packetsInTheAir = new PacketsInTheAirBuffer(); /** * The global event queue that stores the events scheduled. This queue is always * empty in the synchronous mode. */ - public static EventQueue eventQueue = new EventQueue(); + @Getter + @Setter + private static EventQueue eventQueue = new EventQueue(); /** * The instance of the background map. */ - public static Map map = null; - + @Getter + @Setter + private static Map map = null; // some information on the rounds @@ -141,7 +148,7 @@ public abstract class SinalgoRuntime { public SinalgoRuntime() { if (Configuration.isUseMap()) { try { - map = new Map(IOUtils.getAsPath(Configuration.getUserProjectsPackage(), Global.getProjectName(), Configuration.getMap())); + setMap(new Map(IOUtils.getAsPath(Configuration.getUserProjectsPackage(), Global.getProjectName(), Configuration.getMap()))); } catch (FileNotFoundException e) { throw new SinalgoWrappedException(e); } @@ -375,7 +382,7 @@ public abstract class SinalgoRuntime { * @param n The node to add. */ public static void addNode(Node n) { - nodes.addNode(n); + getNodes().addNode(n); Global.getCustomGlobal().nodeAddedEvent(n); if (Global.isGuiMode()) { try { @@ -404,7 +411,7 @@ public abstract class SinalgoRuntime { // remove the outgoing connections from neighbor to this nodes // TODO: This is really expensive! Can't we have a better data structure? // The problem so far is the 'getRandomNode' method - Enumeration<Node> nodeEnumer = nodes.getNodeEnumeration(); + Enumeration<Node> nodeEnumer = getNodes().getNodeEnumeration(); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); Edge e = node.getOutgoingConnections().remove(node, n); // does only remove it it really exists @@ -414,8 +421,8 @@ public abstract class SinalgoRuntime { } n.getOutgoingConnections().removeAndFreeAllEdges(); - nodes.removeNode(n); - eventQueue.removeAllEventsForThisNode(n); + getNodes().removeNode(n); + getEventQueue().removeAllEventsForThisNode(n); if (Global.isGuiMode()) { // un highlight this node Tools.getGUI().getGraphPanel().setNodeHighlighted(n, false); @@ -443,7 +450,7 @@ public abstract class SinalgoRuntime { * In asynchronous mode, removes all events from the event queue */ public static void removeAllAsynchronousEvents() { - eventQueue.dropAllEvents(); + getEventQueue().dropAllEvents(); } /** @@ -452,7 +459,7 @@ public abstract class SinalgoRuntime { * @param e The event to remove */ public static void removeEvent(Event e) { - eventQueue.dropEvent(e); + getEventQueue().dropEvent(e); } /** @@ -502,7 +509,7 @@ public abstract class SinalgoRuntime { * the graph. */ public static void reevaluateConnections() { - for (Node n : nodes) { + for (Node n : getNodes()) { n.getConnectivityModel().updateConnections(n); } } @@ -514,13 +521,13 @@ public abstract class SinalgoRuntime { * This method may be used to empty the node collection. */ public static void clearAllNodes() { - eventQueue.pruneAllNodeEvents(); + getEventQueue().pruneAllNodeEvents(); - packetsInTheAir = new PacketsInTheAirBuffer(); - for (Node n : nodes) { + setPacketsInTheAir(new PacketsInTheAirBuffer()); + for (Node n : getNodes()) { n.getOutgoingConnections().removeAndFreeAllEdges(); } - nodes = createNewNodeCollection(); + setNodes(createNewNodeCollection()); Node.resetIDCounter(); // new nodes restart their ID with 1 if (Global.isGuiMode()) { GUI gui = Tools.getGUI(); diff --git a/src/main/java/sinalgo/runtime/SinalgoUncaughtExceptionHandler.java b/src/main/java/sinalgo/runtime/SinalgoUncaughtExceptionHandler.java index 60c1cdd..c4ae6d0 100644 --- a/src/main/java/sinalgo/runtime/SinalgoUncaughtExceptionHandler.java +++ b/src/main/java/sinalgo/runtime/SinalgoUncaughtExceptionHandler.java @@ -61,7 +61,7 @@ public class SinalgoUncaughtExceptionHandler implements UncaughtExceptionHandler } else if (e instanceof SinalgoWrappedException) { fatalError(e.getCause()); } else if (e instanceof OutOfMemoryError) { - SinalgoRuntime.nodes = null; + SinalgoRuntime.setNodes(null); Tools.disposeRecycledObjects(Logging.getLogger().getOutputStream()); System.gc(); Runtime r = Runtime.getRuntime(); @@ -122,8 +122,8 @@ public class SinalgoUncaughtExceptionHandler implements UncaughtExceptionHandler */ private static void fatalError(String message, Throwable cause) { if (Global.isGuiMode()) { - if (Main.runtime != null) { - JOptionPane.showMessageDialog(((GUIRuntime) Main.runtime).getGUI(), + if (Main.getRuntime() != null) { + JOptionPane.showMessageDialog(((GUIRuntime) Main.getRuntime()).getGUI(), Tools.wrapAndCutToLines(message, 30), "Fatal Error", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(null, Tools.wrapAndCutToLines(message, 30), "Fatal Error", diff --git a/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java b/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java index b3d81e8..818681a 100644 --- a/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java +++ b/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java @@ -112,25 +112,25 @@ public class SynchronousRuntimeThread extends Thread { // Mobility is performed in a separate iteration over all nodes to avoid // inconsistencies. if (Configuration.isMobility()) { - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { n.setPosition(n.getMobilityModel().getNextPos(n)); } } // Before the nodes perform their step, the entire network graph is updated // such that all nodes see the same network when they perform their step. - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { n.updateConnections(); } // Test all messages still being sent for interference if (Configuration.isInterference()) { - SinalgoRuntime.packetsInTheAir.testForInterference(); + SinalgoRuntime.getPacketsInTheAir().testForInterference(); } // Perform the step for each node try { - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { n.step(); } } catch (WrongConfigurationException wCE) { diff --git a/src/main/java/sinalgo/runtime/events/EventQueue.java b/src/main/java/sinalgo/runtime/events/EventQueue.java index b76738e..022dc64 100644 --- a/src/main/java/sinalgo/runtime/events/EventQueue.java +++ b/src/main/java/sinalgo/runtime/events/EventQueue.java @@ -179,7 +179,7 @@ public class EventQueue extends TreeSet<Event> { } } super.clear(); // kill this set - SinalgoRuntime.eventQueue = eq; // replace the event queue + SinalgoRuntime.setEventQueue(eq); // replace the event queue this.notifyListeners(); } diff --git a/src/main/java/sinalgo/runtime/events/PacketEvent.java b/src/main/java/sinalgo/runtime/events/PacketEvent.java index 72220a9..29593c9 100644 --- a/src/main/java/sinalgo/runtime/events/PacketEvent.java +++ b/src/main/java/sinalgo/runtime/events/PacketEvent.java @@ -59,7 +59,10 @@ import java.util.Stack; public class PacketEvent extends Event { private static Stack<PacketEvent> unusedPacketEvents = new Stack<>(); - public static int numPacketEventsOnTheFly = 0; + + @Getter + @Setter + private static int numPacketEventsOnTheFly = 0; public static int getNumFreedPacketEvents() { return unusedPacketEvents.size(); @@ -109,7 +112,7 @@ public class PacketEvent extends Event { } else { pe = new PacketEvent(packet, time); } - numPacketEventsOnTheFly++; + setNumPacketEventsOnTheFly(getNumPacketEventsOnTheFly() + 1); return pe; } @@ -124,7 +127,7 @@ public class PacketEvent extends Event { this.packet = null; } unusedPacketEvents.push(this); - numPacketEventsOnTheFly--; + setNumPacketEventsOnTheFly(getNumPacketEventsOnTheFly() - 1); } // Two static objects to prevent from allocating them all over again @@ -135,8 +138,8 @@ public class PacketEvent extends Event { public void handle() { // the arrival of a packet in the asynchronous case if (Configuration.isInterference()) { - SinalgoRuntime.packetsInTheAir.performInterferenceTestBeforeRemove(); - SinalgoRuntime.packetsInTheAir.remove(this.packet); + SinalgoRuntime.getPacketsInTheAir().performInterferenceTestBeforeRemove(); + SinalgoRuntime.getPacketsInTheAir().remove(this.packet); } if (this.getPacket().getEdge() != null) { this.getPacket().getEdge().removeMessageForThisEdge(this.getPacket().getMessage()); @@ -154,7 +157,7 @@ public class PacketEvent extends Event { public void drop() { // similar to the arrival of a packet in the asynchronous case if (Configuration.isInterference()) { - SinalgoRuntime.packetsInTheAir.remove(this.getPacket()); + SinalgoRuntime.getPacketsInTheAir().remove(this.getPacket()); } if (this.getPacket().getEdge() != null) { this.getPacket().getEdge().removeMessageForThisEdge(this.getPacket().getMessage()); diff --git a/src/main/java/sinalgo/runtime/events/TimerEvent.java b/src/main/java/sinalgo/runtime/events/TimerEvent.java index 084413d..a2ea1d8 100644 --- a/src/main/java/sinalgo/runtime/events/TimerEvent.java +++ b/src/main/java/sinalgo/runtime/events/TimerEvent.java @@ -52,7 +52,10 @@ import java.util.Stack; public class TimerEvent extends Event { private static Stack<TimerEvent> unusedTimerEvents = new Stack<>(); - public static int numTimerEventsOnTheFly = 0; + + @Getter + @Setter + private static int numTimerEventsOnTheFly = 0; public static int getNumFreedTimerEvents() { return unusedTimerEvents.size(); @@ -104,7 +107,7 @@ public class TimerEvent extends Event { } else { te = new TimerEvent(timer, time); } - numTimerEventsOnTheFly++; + setNumTimerEventsOnTheFly(getNumTimerEventsOnTheFly() + 1); return te; } @@ -115,7 +118,7 @@ public class TimerEvent extends Event { public void free() { this.setTimer(null); unusedTimerEvents.push(this); - numTimerEventsOnTheFly--; + setNumTimerEventsOnTheFly(getNumTimerEventsOnTheFly() - 1); } @Override diff --git a/src/main/java/sinalgo/tools/Tools.java b/src/main/java/sinalgo/tools/Tools.java index 3ea125b..a8e1b31 100644 --- a/src/main/java/sinalgo/tools/Tools.java +++ b/src/main/java/sinalgo/tools/Tools.java @@ -37,35 +37,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package sinalgo.tools; import sinalgo.configuration.Configuration; -import sinalgo.exception.NotInBatchModeException; -import sinalgo.exception.NotInGUIModeException; -import sinalgo.exception.SinalgoFatalException; -import sinalgo.exception.SinalgoWrappedException; -import sinalgo.exception.WrongConfigurationException; +import sinalgo.exception.*; import sinalgo.gui.GUI; import sinalgo.gui.GraphPanel; import sinalgo.gui.helper.NodeSelectionHandler; import sinalgo.gui.transformation.PositionTransformation; import sinalgo.io.mapIO.Map; -import sinalgo.models.ConnectivityModel; -import sinalgo.models.DistributionModel; -import sinalgo.models.InterferenceModel; -import sinalgo.models.MessageTransmissionModel; -import sinalgo.models.MobilityModel; -import sinalgo.models.Model; -import sinalgo.models.ModelType; -import sinalgo.models.ReliabilityModel; +import sinalgo.models.*; import sinalgo.nodes.Node; import sinalgo.nodes.Position; import sinalgo.nodes.edges.Edge; import sinalgo.nodes.edges.EdgePool; import sinalgo.nodes.messages.Packet; -import sinalgo.runtime.AbstractCustomGlobal; -import sinalgo.runtime.BatchRuntime; -import sinalgo.runtime.GUIRuntime; -import sinalgo.runtime.Global; -import sinalgo.runtime.Main; -import sinalgo.runtime.SinalgoRuntime; +import sinalgo.runtime.*; import sinalgo.runtime.events.EventQueue; import sinalgo.runtime.events.PacketEvent; import sinalgo.runtime.events.TimerEvent; @@ -296,7 +280,7 @@ public class Tools { * information about the sender, the intensity... */ public static PacketsInTheAirBuffer getPacketsInTheAir() { - return SinalgoRuntime.packetsInTheAir; + return SinalgoRuntime.getPacketsInTheAir(); } /** @@ -360,7 +344,7 @@ public class Tools { * simulation mode. */ public static EventQueue getEventQueue() { - return SinalgoRuntime.eventQueue; + return SinalgoRuntime.getEventQueue(); } /** @@ -368,14 +352,14 @@ public class Tools { * is set. */ public static Map getBackgroundMap() { - return SinalgoRuntime.map; + return SinalgoRuntime.getMap(); } /** * @return A list of all nodes currently added to the framework. */ public static AbstractNodeCollection getNodeList() { - return SinalgoRuntime.nodes; + return SinalgoRuntime.getNodes(); } /** @@ -387,7 +371,7 @@ public class Tools { * @return The node with the given ID, null if there is no such node. */ public static Node getNodeByID(int id) { - for (Node n : SinalgoRuntime.nodes) { + for (Node n : SinalgoRuntime.getNodes()) { if (n.getID() == id) { return n; } @@ -400,7 +384,7 @@ public class Tools { * framework. */ public static Node getRandomNode() { - return SinalgoRuntime.nodes.getRandomNode(); + return SinalgoRuntime.getNodes().getRandomNode(); } /** @@ -886,9 +870,9 @@ public class Tools { ps.print("\nSinalgo Memory Stats:\nRecycling: (used / recycled)\n"); ps.print(" Packets \t(" + Packet.getNumPacketsOnTheFly() + " / " + Packet.getNumFreedPackets() + ")\n"); if (Global.isAsynchronousMode()) { - ps.print(" PacketEvents \t(" + PacketEvent.numPacketEventsOnTheFly + " / " + ps.print(" PacketEvents \t(" + PacketEvent.getNumPacketEventsOnTheFly() + " / " + PacketEvent.getNumFreedPacketEvents() + ")\n"); - ps.print(" TimerEvents \t(" + TimerEvent.numTimerEventsOnTheFly + " / " + ps.print(" TimerEvents \t(" + TimerEvent.getNumTimerEventsOnTheFly() + " / " + TimerEvent.getNumFreedTimerEvents() + ")\n"); } ps.print(" Edges \t(" + Edge.getNumEdgesOnTheFly() + " / " + EdgePool.getNumFreedEdges() + ")\n"); -- GitLab