diff --git a/src/main/java/projects/defaultProject/models/connectivityModels/QUDG.java b/src/main/java/projects/defaultProject/models/connectivityModels/QUDG.java index 59ef437b2766e8101d242594a726af7c47322a49..a90d89dd39b7eb1f9ffcb1ffdcf5463f7e3951d4 100644 --- a/src/main/java/projects/defaultProject/models/connectivityModels/QUDG.java +++ b/src/main/java/projects/defaultProject/models/connectivityModels/QUDG.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.connectivityModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.exception.NotYetImplementedException; @@ -45,6 +48,8 @@ import sinalgo.nodes.Position; import sinalgo.runtime.Main; import sinalgo.tools.statistics.Distribution; +import java.util.Random; + /** * Implementation of a quasi unit disc graph connectivy model. This connectivity * model is close to the UDG, but does not have a sharp bound on the maximum @@ -83,22 +88,38 @@ public class QUDG extends ConnectivityModelHelper { // the lower threshold of the distance between two nodes below they are always // connected + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static double r_min_squared; // the upper threshold of the distance between two nodes above which to nodes // are never connected. + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static double r_max_squared; - private static double m, q; // for linear probability + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static double m; + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static double q; // for linear probability // The probability to add an edge if the distance between two nodes is in the // range ]r_min, r_max]. + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static double probability; // Instance of the framework intern random number generator. - private static java.util.Random rand = Distribution.getRandom(); + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static Random rand = Distribution.getRandom(); - private int probabilityType = 0; // 0 = constant probability, 1 = linear, 2 = quadratic + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private int probabilityType; // 0 = constant probability, 1 = linear, 2 = quadratic /** * In the QUDG graph, two nodes are always connected if their mutual distance is @@ -115,22 +136,22 @@ public class QUDG extends ConnectivityModelHelper { Position p2 = to.getPosition(); double d = p1.squareDistanceTo(p2); - if (d <= r_min_squared) { + if (d <= getR_min_squared()) { return true; // the two nodes are always connected } - if (d > r_max_squared) { + if (d > getR_max_squared()) { return false; // the two nodes are never connected } // the distance between the two nodes is between r_min and r_max. Now, we // randomly // determine whether the edge exists or not. - if (this.probabilityType == 1) { // linear probability - probability = Math.sqrt(d) * m + q; - } else if (this.probabilityType == 2) { // quadratic probability + if (this.getProbabilityType() == 1) { // linear probability + setProbability(Math.sqrt(d) * getM() + getQ()); + } else if (this.getProbabilityType() == 2) { // quadratic probability // ... not yet implemented } - return rand.nextDouble() <= probability; + return getRand().nextDouble() <= getProbability(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -139,7 +160,9 @@ public class QUDG extends ConnectivityModelHelper { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - private static boolean initialized = false; // indicates whether the static fields of this class have already been + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static boolean initialized; // indicates whether the static fields of this class have already been // initialized /** @@ -153,14 +176,14 @@ public class QUDG extends ConnectivityModelHelper { */ public QUDG() throws CorruptConfigurationEntryException { // only call the first time a QUDG object is created - if (!initialized) { + if (!isInitialized()) { // speed up by comparing the squared distances (needs not take the square root // to get the distance) double r_min = Configuration.getDoubleParameter("QUDG/rMin"); - r_min_squared = r_min * r_min; + setR_min_squared(r_min * r_min); double r_max = Configuration.getDoubleParameter("QUDG/rMax"); - r_max_squared = r_max * r_max; + setR_max_squared(r_max * r_max); // Sanity check double geomNodeRMax = Configuration.getDoubleParameter("GeometricNodeCollection/rMax"); @@ -177,16 +200,16 @@ public class QUDG extends ConnectivityModelHelper { String type = Configuration.getStringParameter("QUDG/ProbabilityType"); switch (type.toLowerCase()) { case "constant": - this.probabilityType = 0; - probability = Configuration.getDoubleParameter("QUDG/connectionProbability"); + this.setProbabilityType(0); + setProbability(Configuration.getDoubleParameter("QUDG/connectionProbability")); break; case "linear": - this.probabilityType = 1; - m = 1 / (r_min - r_max); - q = r_max / (r_max - r_min); + this.setProbabilityType(1); + setM(1 / (r_min - r_max)); + setQ(r_max / (r_max - r_min)); break; case "quadratic": - this.probabilityType = 2; + this.setProbabilityType(2); throw new NotYetImplementedException("QUDG does not yet support quadratic probability distributions."); default: // TODO: rewrite the following exception, rewrite docu as well @@ -199,8 +222,9 @@ public class QUDG extends ConnectivityModelHelper { + "'quadratic' applies a quadratic regression that decreases from 1 to 0 from rMin to rMax.\n\n"); } - probability = Configuration.getDoubleParameter("QUDG/connectionProbability"); - initialized = true; + setProbability(Configuration.getDoubleParameter("QUDG/connectionProbability")); + setInitialized(true); } } + } diff --git a/src/main/java/projects/defaultProject/models/connectivityModels/StaticUDG.java b/src/main/java/projects/defaultProject/models/connectivityModels/StaticUDG.java index dcd7715dd4b7b31cdd34916e63efe9518ac7fa56..37e3abde6af49079f29aefabda45b446476c8b3e 100644 --- a/src/main/java/projects/defaultProject/models/connectivityModels/StaticUDG.java +++ b/src/main/java/projects/defaultProject/models/connectivityModels/StaticUDG.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.connectivityModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.exception.WrongConfigurationException; import sinalgo.nodes.Node; @@ -49,12 +52,14 @@ import sinalgo.nodes.Node; */ public class StaticUDG extends UDG { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private boolean firstTime = true; // detect when the connections are evaluated for the first time @Override public boolean updateConnections(Node n) throws WrongConfigurationException { - if (this.firstTime) { - this.firstTime = false; + if (this.isFirstTime()) { + this.setFirstTime(false); return super.updateConnections(n); // let UDG do its work } else { return false; // keep all existing connections @@ -69,4 +74,5 @@ public class StaticUDG extends UDG { public StaticUDG() throws CorruptConfigurationEntryException { // all done in UDG. } + } diff --git a/src/main/java/projects/defaultProject/models/connectivityModels/UDG.java b/src/main/java/projects/defaultProject/models/connectivityModels/UDG.java index faed4825ac2106b7c74e20cc112c53ec8d9c5316..5017c5ce1c00a9912d4a1ab5abdfc981aa23ff3d 100644 --- a/src/main/java/projects/defaultProject/models/connectivityModels/UDG.java +++ b/src/main/java/projects/defaultProject/models/connectivityModels/UDG.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.connectivityModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.models.ConnectivityModelHelper; @@ -63,6 +66,8 @@ import sinalgo.runtime.Main; */ public class UDG extends ConnectivityModelHelper { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private double squareRadius; @Override @@ -71,7 +76,7 @@ public class UDG extends ConnectivityModelHelper { Position p2 = to.getPosition(); double distance = p1.squareDistanceTo(p2); - return (distance < this.squareRadius); + return (distance < this.getSquareRadius()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -80,15 +85,20 @@ public class UDG extends ConnectivityModelHelper { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - private static boolean initialized = false; // indicates whether the static fields of this class have already been + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static boolean initialized; // indicates whether the static fields of this class have already been // initialized + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static double rMaxSquare; // we reuse the rMax value from the GeometricNodeCollection. /** * @return The maximum transmission range of this UDG model. */ public double getMaxTransmissionRange() { - return Math.sqrt(this.squareRadius); + return Math.sqrt(this.getSquareRadius()); } /** @@ -97,11 +107,11 @@ public class UDG extends ConnectivityModelHelper { * @param rMax The new max. transmission range. */ public void setMaxTransmissionRange(double rMax) { - this.squareRadius = rMax * rMax; + this.setSquareRadius(rMax * rMax); } public UDG(double rMax) { - this.squareRadius = rMax * rMax; + this.setSquareRadius(rMax * rMax); } /** @@ -113,24 +123,32 @@ public class UDG extends ConnectivityModelHelper { * @throws CorruptConfigurationEntryException If one of the initialization steps fails. */ public UDG() throws CorruptConfigurationEntryException { - if (!initialized) { + if (!isInitialized()) { double geomNodeRMax = Configuration.getDoubleParameter("GeometricNodeCollection/rMax"); try { - rMaxSquare = Configuration.getDoubleParameter("UDG/rMax"); + setRMaxSquare(Configuration.getDoubleParameter("UDG/rMax")); } catch (CorruptConfigurationEntryException e) { Global.getLog().logln( "\nWARNING: There is no entry 'UDG/rMax' in the XML configuration file. This entry specifies the max. transmission range for the UDG connectivity model.\nThe simulation now uses GeometricNodeCollection/rMax instead.\n"); - rMaxSquare = geomNodeRMax; + setRMaxSquare(geomNodeRMax); } - if (rMaxSquare > geomNodeRMax) { // dangerous! This is probably not what the user wants! + if (getRMaxSquare() > geomNodeRMax) { // dangerous! This is probably not what the user wants! Main.minorError( "WARNING: The maximum transmission range used for the UDG connectivity model is larger than the maximum transmission range specified for the GeometricNodeCollection.\nAs a result, not all connections will be found! Either fix the problem in the project-specific configuration file or the '-overwrite' command line argument."); } - rMaxSquare = rMaxSquare * rMaxSquare; + setRMaxSquare(getRMaxSquare() * getRMaxSquare()); - initialized = true; + setInitialized(true); } - this.squareRadius = rMaxSquare; + this.setSquareRadius(getRMaxSquare()); + } + + private double getSquareRadius() { + return squareRadius; + } + + private void setSquareRadius(double squareRadius) { + this.squareRadius = squareRadius; } } diff --git a/src/main/java/projects/defaultProject/models/distributionModels/Circle.java b/src/main/java/projects/defaultProject/models/distributionModels/Circle.java index e054b9e50a07e321d58d27e89bf13d951e4efcc8..1f4c2182bc8539a521600303707909f82da18ad4 100644 --- a/src/main/java/projects/defaultProject/models/distributionModels/Circle.java +++ b/src/main/java/projects/defaultProject/models/distributionModels/Circle.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.distributionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.models.DistributionModel; import sinalgo.nodes.Position; @@ -43,36 +46,39 @@ import sinalgo.nodes.Position; /** * Distributes the nodes regularly on a circle. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class Circle extends DistributionModel { - private double radius = 0.0; - private double oneStep = 0.0; - private int number = 0; + private double radius; + private double oneStep; + private int number; @Override public void initialize() { String parameter = this.getParamString(); if (parameter.equals("")) { if (Configuration.getDimX() < Configuration.getDimY()) { - this.radius = Configuration.getDimX() / 3.0; + this.setRadius(Configuration.getDimX() / 3.0); } else { - this.radius = Configuration.getDimY() / 3.0; + this.setRadius(Configuration.getDimY() / 3.0); } } else { - this.radius = Double.parseDouble(parameter); + this.setRadius(Double.parseDouble(parameter)); } - this.oneStep = 360.0 / this.numberOfNodes; + this.setOneStep(360.0 / this.numberOfNodes); } @Override public Position getNextPosition() { Position pos = new Position(); - pos.setXCoord((Configuration.getDimX() / 2.0) + (this.radius * Math.cos(Math.toRadians((this.number * this.oneStep))))); - pos.setYCoord((Configuration.getDimY() / 2.0) + (this.radius * Math.sin(Math.toRadians((this.number * this.oneStep))))); + pos.setXCoord((Configuration.getDimX() / 2.0) + (this.getRadius() * Math.cos(Math.toRadians((this.getNumber() * this.getOneStep()))))); + pos.setYCoord((Configuration.getDimY() / 2.0) + (this.getRadius() * Math.sin(Math.toRadians((this.getNumber() * this.getOneStep()))))); - this.number++; + this.setNumber(this.getNumber() + 1); return pos; } + } diff --git a/src/main/java/projects/defaultProject/models/distributionModels/Grid2D.java b/src/main/java/projects/defaultProject/models/distributionModels/Grid2D.java index 595d8a564e061d02dc94b0c7e3ab54e789fa74b6..ecda20e4973e8640e4aef77a567fbe62dd717753 100644 --- a/src/main/java/projects/defaultProject/models/distributionModels/Grid2D.java +++ b/src/main/java/projects/defaultProject/models/distributionModels/Grid2D.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.distributionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoFatalException; import sinalgo.models.DistributionModel; @@ -45,11 +48,14 @@ import sinalgo.nodes.Position; * Aligns the nodes about equally spaced on a gird covering the entire * deployment area. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class Grid2D extends DistributionModel { private double size; // the cell-size of the gird private int numNodesPerLine; // number of nodes on the x-axis - private int i, j; // loop counters + private int i; + private int j; // loop counters @Override public void initialize() { @@ -60,19 +66,20 @@ public class Grid2D extends DistributionModel { if (tmp < 0) { throw new SinalgoFatalException("negative sqrt"); } - this.size = (-b - Math.sqrt(tmp)) / (2 * a); - this.numNodesPerLine = (int) Math.round(Configuration.getDimX() / this.size) - 1; - this.i = 0; - this.j = 1; + this.setSize((-b - Math.sqrt(tmp)) / (2 * a)); + this.setNumNodesPerLine((int) Math.round(Configuration.getDimX() / this.getSize()) - 1); + this.setI(0); + this.setJ(1); } @Override public Position getNextPosition() { - this.i++; - if (this.i > this.numNodesPerLine) { - this.i = 1; - this.j++; + this.setI(this.getI() + 1); + if (this.getI() > this.getNumNodesPerLine()) { + this.setI(1); + this.setJ(this.getJ() + 1); } - return new Position(this.i * this.size, this.j * this.size, 0); + return new Position(this.getI() * this.getSize(), this.getJ() * this.getSize(), 0); } + } diff --git a/src/main/java/projects/defaultProject/models/distributionModels/Line2D.java b/src/main/java/projects/defaultProject/models/distributionModels/Line2D.java index 45426c35d8eec79f73293240a7fb2af6b2ddaa96..1c0356db91bafcbeb2d28c8d91311c25a7c6a5c9 100644 --- a/src/main/java/projects/defaultProject/models/distributionModels/Line2D.java +++ b/src/main/java/projects/defaultProject/models/distributionModels/Line2D.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.distributionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.exception.SinalgoWrappedException; @@ -58,6 +61,8 @@ import sinalgo.nodes.Position; * where the nodes are placed on a line from (FromX,FromY) to (ToX,ToY). If only * one node is placed, it placed in the middle of the line. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class Line2D extends DistributionModel { private double dx; @@ -72,34 +77,35 @@ public class Line2D extends DistributionModel { && Configuration.hasParameter("DistributionModel/Line/ToX") && Configuration.hasParameter("DistributionModel/Line/ToY")) { try { - this.previousPositionX = Configuration.getDoubleParameter("DistributionModel/Line/FromX"); - this.previousPositionY = Configuration.getDoubleParameter("DistributionModel/Line/FromY"); - this.dx = Configuration.getDoubleParameter("DistributionModel/Line/ToX") - this.previousPositionX; - this.dy = Configuration.getDoubleParameter("DistributionModel/Line/ToY") - this.previousPositionY; + this.setPreviousPositionX(Configuration.getDoubleParameter("DistributionModel/Line/FromX")); + this.setPreviousPositionY(Configuration.getDoubleParameter("DistributionModel/Line/FromY")); + this.setDx(Configuration.getDoubleParameter("DistributionModel/Line/ToX") - this.getPreviousPositionX()); + this.setDy(Configuration.getDoubleParameter("DistributionModel/Line/ToY") - this.getPreviousPositionY()); } catch (CorruptConfigurationEntryException e) { throw new SinalgoWrappedException(e); } if (this.numberOfNodes <= 1) { // place the single node in the middle - this.dx /= 2; - this.dy /= 2; + this.setDx(this.getDx() / 2); + this.setDy(this.getDy() / 2); } else { - this.dx /= (this.numberOfNodes - 1); - this.dy /= (this.numberOfNodes - 1); - this.previousPositionX -= this.dx; - this.previousPositionY -= this.dy; + this.setDx(this.getDx() / (this.numberOfNodes - 1)); + this.setDy(this.getDy() / (this.numberOfNodes - 1)); + this.setPreviousPositionX(this.getPreviousPositionX() - this.getDx()); + this.setPreviousPositionY(this.getPreviousPositionY() - this.getDy()); } } else { // default horizontal line - this.dy = 0; - this.dx = ((double) Configuration.getDimX()) / (this.numberOfNodes + 1); - this.previousPositionX = 0; - this.previousPositionY = Configuration.getDimY() / 2; + this.setDy(0); + this.setDx(((double) Configuration.getDimX()) / (this.numberOfNodes + 1)); + this.setPreviousPositionX(0); + this.setPreviousPositionY(Configuration.getDimY() / 2); } } @Override public Position getNextPosition() { - this.previousPositionX += this.dx; - this.previousPositionY += this.dy; - return new Position(this.previousPositionX, this.previousPositionY, 0); + this.setPreviousPositionX(this.getPreviousPositionX() + this.getDx()); + this.setPreviousPositionY(this.getPreviousPositionY() + this.getDy()); + return new Position(this.getPreviousPositionX(), this.getPreviousPositionY(), 0); } + } diff --git a/src/main/java/projects/defaultProject/models/distributionModels/PositionFile.java b/src/main/java/projects/defaultProject/models/distributionModels/PositionFile.java index 58e8e575604419edd3398761e9200f6fdaf4f950..28b33f2ad6eda4f43e3d0b272d3728a8ef49e434 100644 --- a/src/main/java/projects/defaultProject/models/distributionModels/PositionFile.java +++ b/src/main/java/projects/defaultProject/models/distributionModels/PositionFile.java @@ -1,5 +1,8 @@ package projects.defaultProject.models.distributionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.io.positionFile.PositionFileIO; import sinalgo.models.DistributionModel; import sinalgo.nodes.Position; @@ -18,17 +21,20 @@ import java.io.LineNumberReader; */ public class PositionFile extends DistributionModel { - private LineNumberReader reader = null; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private LineNumberReader reader; @Override public Position getNextPosition() { - if (this.reader == null) { + if (this.getReader() == null) { if (super.getParamString().equals("")) { - this.reader = PositionFileIO.getPositionFileReader(null); + this.setReader(PositionFileIO.getPositionFileReader(null)); } else { - this.reader = PositionFileIO.getPositionFileReader(super.getParamString()); + this.setReader(PositionFileIO.getPositionFileReader(super.getParamString())); } } - return PositionFileIO.getNextPosition(this.reader); + return PositionFileIO.getNextPosition(this.getReader()); } + } diff --git a/src/main/java/projects/defaultProject/models/distributionModels/Random.java b/src/main/java/projects/defaultProject/models/distributionModels/Random.java index cb11305711d9e73561f0380616ee44d0d88c4a91..3ebb634439c8754017a4a829d8228749c360af70 100644 --- a/src/main/java/projects/defaultProject/models/distributionModels/Random.java +++ b/src/main/java/projects/defaultProject/models/distributionModels/Random.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.distributionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.models.DistributionModel; import sinalgo.nodes.Position; import sinalgo.tools.Tools; @@ -48,10 +51,13 @@ import sinalgo.tools.statistics.Distribution; public class Random extends DistributionModel { // The random-number generator + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private java.util.Random rand = Distribution.getRandom(); @Override public Position getNextPosition() { - return Tools.getRandomPosition(this.rand); + return Tools.getRandomPosition(this.getRand()); } + } diff --git a/src/main/java/projects/defaultProject/models/interferenceModels/NoInterference.java b/src/main/java/projects/defaultProject/models/interferenceModels/NoInterference.java index a431f25d89554f2aaf2f258abdecd4c9e6922f82..41733e6a986e8cec6857706870d8d4e66668fc38 100644 --- a/src/main/java/projects/defaultProject/models/interferenceModels/NoInterference.java +++ b/src/main/java/projects/defaultProject/models/interferenceModels/NoInterference.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.interferenceModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.models.InterferenceModel; import sinalgo.nodes.messages.Packet; @@ -46,6 +49,8 @@ import sinalgo.runtime.Main; */ public class NoInterference extends InterferenceModel { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static boolean firstTime = true; @Override @@ -58,12 +63,12 @@ public class NoInterference extends InterferenceModel { */ public NoInterference() { super(false); - if (firstTime && Configuration.isInterference() && Configuration.isShowOptimizationHints()) { + if (isFirstTime() && Configuration.isInterference() && Configuration.isShowOptimizationHints()) { Main.warning("At least some nodes use the 'NoInterference' interfernce model. " + "If you do not consider interference at all in your project, you can " + "considerably improve performance by turning off interference in the " + "XML configuration file."); - firstTime = false; // important to only have one message. + setFirstTime(false); // important to only have one message. } } } diff --git a/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java b/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java index 911a0d9fbbb6e0836ecf53ea6e7e2a4b0f6db03a..109d94f2e508da79c76fd2ff7a1d0f5d05a2daad 100644 --- a/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java +++ b/src/main/java/projects/defaultProject/models/interferenceModels/SINR.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.interferenceModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.exception.SinalgoFatalException; @@ -63,6 +66,8 @@ import sinalgo.tools.logging.LogL; * <SINR alpha="..." beta="..." noise="..."/> <br> * where alpha, beta, and noise are three floating point values. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class SINR extends InterferenceModel { private int alpha;// the path-loss exponent, good fefault value would be 2 @@ -74,17 +79,17 @@ public class SINR extends InterferenceModel { */ public SINR() { try { - this.alpha = Configuration.getIntegerParameter("SINR/alpha"); + this.setAlpha(Configuration.getIntegerParameter("SINR/alpha")); } catch (CorruptConfigurationEntryException e) { throw new SinalgoFatalException("The configuration entry SINR/alpha is not a valid double:\n\n" + e.getMessage()); } try { - this.beta = Configuration.getDoubleParameter("SINR/beta"); + this.setBeta(Configuration.getDoubleParameter("SINR/beta")); } catch (CorruptConfigurationEntryException e) { throw new SinalgoFatalException("The configuration entry SINR/beta is not a valid double:\n\n" + e.getMessage()); } try { - this.ambientNoise = Configuration.getDoubleParameter("SINR/noise"); + this.setAmbientNoise(Configuration.getDoubleParameter("SINR/noise")); } catch (CorruptConfigurationEntryException e) { throw new SinalgoFatalException("The configuration entry SINR/noise is not a valid double:\n\n" + e.getMessage()); } @@ -94,11 +99,11 @@ public class SINR extends InterferenceModel { public boolean isDisturbed(Packet p) { Position receiverPos = p.getDestination().getPosition(); double distanceFromSource = p.getOrigin().getPosition().distanceTo(receiverPos); - double poweredDistanceFromSource = Math.pow(distanceFromSource, this.alpha); + double poweredDistanceFromSource = Math.pow(distanceFromSource, this.getAlpha()); double signal = p.getIntensity() / poweredDistanceFromSource; - double noise = this.ambientNoise; + double noise = this.getAmbientNoise(); for (Packet pack : SinalgoRuntime.getPacketsInTheAir()) { // iterate over all active packets if (pack == p) { @@ -119,11 +124,11 @@ public class SINR extends InterferenceModel { Position pos = pack.getOrigin().getPosition(); double distance = pos.distanceTo(receiverPos); - double poweredDistance = Math.pow(distance, this.alpha); + double poweredDistance = Math.pow(distance, this.getAlpha()); noise += pack.getIntensity() / poweredDistance; } - boolean disturbed = signal < this.beta * noise; + boolean disturbed = signal < this.getBeta() * noise; if (LogL.INTERFERENCE_DETAIL) { Global.getLog().logln("Node " + p.getDestination().getID() + " is checking a packet from " + p.getOrigin().getID()); @@ -134,4 +139,5 @@ public class SINR extends InterferenceModel { return disturbed; } + } diff --git a/src/main/java/projects/defaultProject/models/messageTransmissionModels/ConstantTime.java b/src/main/java/projects/defaultProject/models/messageTransmissionModels/ConstantTime.java index b5eff200a88e26d48f8da04f72c43dd1954cc7f8..ba3e774fa0ad7ccb24face88431c59f80943e7d1 100644 --- a/src/main/java/projects/defaultProject/models/messageTransmissionModels/ConstantTime.java +++ b/src/main/java/projects/defaultProject/models/messageTransmissionModels/ConstantTime.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.messageTransmissionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.models.MessageTransmissionModel; @@ -52,6 +55,8 @@ import sinalgo.runtime.Main; */ public class ConstantTime extends MessageTransmissionModel { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private double time = 1.0; /** @@ -61,7 +66,7 @@ public class ConstantTime extends MessageTransmissionModel { */ public ConstantTime() { try { - this.time = Configuration.getDoubleParameter("MessageTransmission/ConstantTime"); + this.setTime(Configuration.getDoubleParameter("MessageTransmission/ConstantTime")); } catch (CorruptConfigurationEntryException e) { Main.warning( "Missing or wrong entry in the configuration file for the ConstantTime DefaultMessageTransmissionModel:\n" @@ -71,6 +76,7 @@ public class ConstantTime extends MessageTransmissionModel { @Override public double timeToReach(Node startNode, Node endNode, Message msg) { - return this.time; + return this.getTime(); } + } diff --git a/src/main/java/projects/defaultProject/models/messageTransmissionModels/RandomTime.java b/src/main/java/projects/defaultProject/models/messageTransmissionModels/RandomTime.java index 4b9eea31680a88bd29377a94cbdcb1c95fa2115e..67ec82d7216eb0da1f97dc5e626bb29492bfaa99 100644 --- a/src/main/java/projects/defaultProject/models/messageTransmissionModels/RandomTime.java +++ b/src/main/java/projects/defaultProject/models/messageTransmissionModels/RandomTime.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.messageTransmissionModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.nodes.Node; import sinalgo.nodes.messages.Message; @@ -57,6 +60,8 @@ import sinalgo.tools.statistics.Distribution; */ public class RandomTime extends sinalgo.models.MessageTransmissionModel { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private Distribution dist; /** @@ -66,15 +71,16 @@ public class RandomTime extends sinalgo.models.MessageTransmissionModel { * @throws CorruptConfigurationEntryException if the configuration is corrupt. */ public RandomTime() throws CorruptConfigurationEntryException { - this.dist = Distribution.getDistributionFromConfigFile("RandomMessageTransmission"); + this.setDist(Distribution.getDistributionFromConfigFile("RandomMessageTransmission")); } @Override public double timeToReach(Node startNode, Node endNode, Message msg) { - double time = this.dist.nextSample(); + double time = this.getDist().nextSample(); if (time <= 0) { time = 1e-9; } return time; } + } diff --git a/src/main/java/projects/defaultProject/models/mobilityModels/NoMobility.java b/src/main/java/projects/defaultProject/models/mobilityModels/NoMobility.java index 8856a4435920ac3687e54892f5388cb5b891f981..ad6edb4579dc9562f1ccd8088754a7ba9815b82e 100644 --- a/src/main/java/projects/defaultProject/models/mobilityModels/NoMobility.java +++ b/src/main/java/projects/defaultProject/models/mobilityModels/NoMobility.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.mobilityModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.models.MobilityModel; import sinalgo.nodes.Node; @@ -47,6 +50,8 @@ import sinalgo.runtime.Main; */ public class NoMobility extends MobilityModel { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static boolean firstTime = true; @Override @@ -59,11 +64,11 @@ public class NoMobility extends MobilityModel { */ public NoMobility() { super(false); - if (firstTime && Configuration.isMobility() && Configuration.isShowOptimizationHints()) { + if (isFirstTime() && Configuration.isMobility() && Configuration.isShowOptimizationHints()) { Main.warning("At least some nodes use the '" + this.getClass().getSimpleName() + "' mobility model. " + "If you do not consider mobility at all in your project, you can " + "considerably improve performance by turning off mobility in the " + "XML configuration file."); - firstTime = false; // important to only have one message. + setFirstTime(false); // important to only have one message. } } } diff --git a/src/main/java/projects/defaultProject/models/mobilityModels/PerfectRWP.java b/src/main/java/projects/defaultProject/models/mobilityModels/PerfectRWP.java index 6b170da586f0ef0d9883016b856ef532da06537c..734379378959ab40768a1a0fcebc247382910245 100644 --- a/src/main/java/projects/defaultProject/models/mobilityModels/PerfectRWP.java +++ b/src/main/java/projects/defaultProject/models/mobilityModels/PerfectRWP.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.mobilityModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.nodes.Node; import sinalgo.nodes.Position; @@ -74,19 +77,21 @@ import sinalgo.nodes.Position; */ public class PerfectRWP extends RandomWayPoint { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private boolean initialize = true; // smooth start @Override public Position getNextPos(Node n) { - if (this.initialize) { - this.initialize = false; + if (this.isInitialize()) { + this.setInitialize(false); - double speed = Math.abs(speedDistribution.nextSample()); // units per round - double wt = Math.ceil(waitingTimeDistribution.nextSample()); // potential waiting time + double speed = Math.abs(getSpeedDistribution().nextSample()); // units per round + double wt = Math.ceil(getWaitingTimeDistribution().nextSample()); // potential waiting time Position startPos = this.getNextWayPoint(); this.setNextDestination(this.getNextWayPoint()); double mt = startPos.distanceTo(this.getNextDestination()) / speed; // time of the move - double fraction = (wt + mt) * random.nextDouble(); + double fraction = (wt + mt) * getRandom().nextDouble(); double dx = this.getNextDestination().getXCoord() - startPos.getXCoord(); double dy = this.getNextDestination().getYCoord() - startPos.getYCoord(); if (fraction < wt) { @@ -94,7 +99,7 @@ public class PerfectRWP extends RandomWayPoint { this.setRemaining_waitingTime((int) Math.ceil(wt - fraction)); this.setRemaining_hops(0); - double movedFraction = random.nextDouble(); + double movedFraction = getRandom().nextDouble(); startPos.setXCoord(startPos.getXCoord() + dx * movedFraction); startPos.setYCoord(startPos.getYCoord() + dy * movedFraction); return startPos; // don't consider initial distribution diff --git a/src/main/java/projects/defaultProject/models/mobilityModels/RandomDirection.java b/src/main/java/projects/defaultProject/models/mobilityModels/RandomDirection.java index d3659a1ae87e48cc41cc098acacf56e1e3b228d5..fb13e65f8f0fa27010fc985501f1878b2ae66d09 100644 --- a/src/main/java/projects/defaultProject/models/mobilityModels/RandomDirection.java +++ b/src/main/java/projects/defaultProject/models/mobilityModels/RandomDirection.java @@ -105,14 +105,26 @@ import java.util.Random; public class RandomDirection extends MobilityModel { // we assume that these distributions are the same for all nodes + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static Distribution speedDistribution; // how fast the nodes move + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static Distribution waitingTimeDistribution; // how long nodes wait before starting the next mobility phase + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static Distribution moveTimeDistribution; // for how long the node moves when it moves // a flag set to true after initialization of the static vars of this class has been done. - protected static boolean initialized = false; + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private static boolean initialized; - protected static Random random = Distribution.getRandom(); // a random generator of the framework + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private static Random random = Distribution.getRandom(); // a random generator of the framework @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) @@ -121,10 +133,12 @@ public class RandomDirection extends MobilityModel { // the current position, to detect if the node has been moved // by other means than this mobility model between successive calls to getNextPos() - private Position currentPosition = null; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private Position currentPosition; - private int remaining_hops = 0; // the remaining hops until a new path has to be determined - private int remaining_waitingTime = 0; + private int remaining_hops; // the remaining hops until a new path has to be determined + private int remaining_waitingTime; private boolean initialize = true; // to detect very first time to start smoothly @@ -138,8 +152,8 @@ public class RandomDirection extends MobilityModel { * @param moveTime The time during which the node is supposed to move */ private void initializeNextMove(double moveSpeed, double moveTime) { - double angleXY = 2 * Math.PI * random.nextDouble(); // 0 .. 360 - double angleZ = Math.PI * (0.5 - random.nextDouble()); // -90 .. 90 + double angleXY = 2 * Math.PI * getRandom().nextDouble(); // 0 .. 360 + double angleZ = Math.PI * (0.5 - getRandom().nextDouble()); // -90 .. 90 if (Main.getRuntime().getTransformator().getNumberOfDimensions() == 2) { angleZ = 0; // remain in the XY-plane } @@ -162,9 +176,9 @@ public class RandomDirection extends MobilityModel { if (this.initialize) { // called the very first time such that not all nodes start moving in the first // round of the simulation. // use a sample to determine in which phase we are. - double wt = Math.abs(waitingTimeDistribution.nextSample()); - double mt = Math.abs(moveTimeDistribution.nextSample()); - double fraction = random.nextDouble() * (wt + mt); + double wt = Math.abs(getWaitingTimeDistribution().nextSample()); + double mt = Math.abs(getMoveTimeDistribution().nextSample()); + double fraction = getRandom().nextDouble() * (wt + mt); if (fraction < wt) { // the node starts waiting, but depending on fraction, may already have waited // some time @@ -172,7 +186,7 @@ public class RandomDirection extends MobilityModel { this.setRemaining_hops(0); } else { // the node starts moving - double speed = Math.abs(speedDistribution.nextSample()); // units per round + double speed = Math.abs(getSpeedDistribution().nextSample()); // units per round this.initializeNextMove(speed, mt + wt - fraction); } this.setCurrentPosition(n.getPosition()); // initially, currentPos is null @@ -198,8 +212,8 @@ public class RandomDirection extends MobilityModel { // move if (this.remaining_hops == 0) { // we start to move, determine next random target // determine the next point to which this node moves to - double speed = Math.abs(speedDistribution.nextSample()); // units per round - double time = Math.abs(moveTimeDistribution.nextSample()); // rounds + double speed = Math.abs(getSpeedDistribution().nextSample()); // units per round + double time = Math.abs(getMoveTimeDistribution().nextSample()); // rounds this.initializeNextMove(speed, time); } double newx = n.getPosition().getXCoord() + this.moveVector.getXCoord(); @@ -250,7 +264,7 @@ public class RandomDirection extends MobilityModel { if (this.remaining_hops <= 1) { // was last round of mobility // set the next waiting time that executes after this mobility phase - this.remaining_waitingTime = (int) Math.ceil(Math.abs(waitingTimeDistribution.nextSample())); + this.remaining_waitingTime = (int) Math.ceil(Math.abs(getWaitingTimeDistribution().nextSample())); this.remaining_hops = 0; } else { this.remaining_hops--; @@ -267,11 +281,11 @@ public class RandomDirection extends MobilityModel { * @see RandomWayPoint */ public RandomDirection() throws CorruptConfigurationEntryException { - if (!initialized) { - moveTimeDistribution = Distribution.getDistributionFromConfigFile("RandomDirection/MoveTime"); - speedDistribution = Distribution.getDistributionFromConfigFile("RandomDirection/NodeSpeed"); - waitingTimeDistribution = Distribution.getDistributionFromConfigFile("RandomDirection/WaitingTime"); - initialized = true; + if (!isInitialized()) { + setMoveTimeDistribution(Distribution.getDistributionFromConfigFile("RandomDirection/MoveTime")); + setSpeedDistribution(Distribution.getDistributionFromConfigFile("RandomDirection/NodeSpeed")); + setWaitingTimeDistribution(Distribution.getDistributionFromConfigFile("RandomDirection/WaitingTime")); + setInitialized(true); } } } diff --git a/src/main/java/projects/defaultProject/models/mobilityModels/RandomWayPoint.java b/src/main/java/projects/defaultProject/models/mobilityModels/RandomWayPoint.java index 2fc3a0576fbc7ea7696dd7eda1124b2fd3484c44..63fdc10599c2003ec208723b076241372f94d1b9 100644 --- a/src/main/java/projects/defaultProject/models/mobilityModels/RandomWayPoint.java +++ b/src/main/java/projects/defaultProject/models/mobilityModels/RandomWayPoint.java @@ -101,14 +101,23 @@ import java.util.Random; public class RandomWayPoint extends MobilityModel { // we assume that these distributions are the same for all nodes - protected static Distribution speedDistribution; - protected static Distribution waitingTimeDistribution; + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private static Distribution speedDistribution; + + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private static Distribution waitingTimeDistribution; // a flag set to true after initialization of the static vars of this class has been done. - private static boolean initialized = false; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static boolean initialized; // a random generator of the framework - protected static Random random = Distribution.getRandom(); + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private static Random random = Distribution.getRandom(); // The point where this node is moving to private Position nextDestination = new Position(); @@ -117,12 +126,12 @@ public class RandomWayPoint extends MobilityModel { private Position moveVector = new Position(); // the current position, to detect if the node has been moved by other means than this mobility model between successive calls to getNextPos() - private Position currentPosition = null; + private Position currentPosition; // the remaining hops until a new path has to be determined - private int remaining_hops = 0; + private int remaining_hops; - private int remaining_waitingTime = 0; + private int remaining_waitingTime; @Override public Position getNextPos(Node n) { @@ -147,7 +156,7 @@ public class RandomWayPoint extends MobilityModel { if (this.remaining_hops == 0) { // determine the speed at which this node moves - double speed = Math.abs(speedDistribution.nextSample()); // units per round + double speed = Math.abs(getSpeedDistribution().nextSample()); // units per round // determine the next point where this node moves to this.nextDestination = this.getNextWayPoint(); @@ -166,7 +175,7 @@ public class RandomWayPoint extends MobilityModel { if (this.remaining_hops <= 1) { // don't add the moveVector, as this may move over the destination. nextPosition.assign(this.nextDestination); // set the next waiting time that executes after this mobility phase - this.remaining_waitingTime = (int) Math.ceil(waitingTimeDistribution.nextSample()); + this.remaining_waitingTime = (int) Math.ceil(getWaitingTimeDistribution().nextSample()); this.remaining_hops = 0; } else { double newx = n.getPosition().getXCoord() + this.moveVector.getXCoord(); @@ -186,7 +195,7 @@ public class RandomWayPoint extends MobilityModel { * @return the next waypoint where this node moves after having waited. */ protected Position getNextWayPoint() { - return Tools.getRandomPosition(random); + return Tools.getRandomPosition(getRandom()); } /** @@ -196,10 +205,10 @@ public class RandomWayPoint extends MobilityModel { * @throws CorruptConfigurationEntryException When a needed configuration entry is missing. */ public RandomWayPoint() throws CorruptConfigurationEntryException { - if (!initialized) { - speedDistribution = Distribution.getDistributionFromConfigFile("RandomWayPoint/Speed"); - waitingTimeDistribution = Distribution.getDistributionFromConfigFile("RandomWayPoint/WaitingTime"); - initialized = true; + if (!isInitialized()) { + setSpeedDistribution(Distribution.getDistributionFromConfigFile("RandomWayPoint/Speed")); + setWaitingTimeDistribution(Distribution.getDistributionFromConfigFile("RandomWayPoint/WaitingTime")); + setInitialized(true); } } } diff --git a/src/main/java/projects/defaultProject/models/reliabilityModels/LossyDelivery.java b/src/main/java/projects/defaultProject/models/reliabilityModels/LossyDelivery.java index 82b9349533b37234a7c8d3e531819279e524e84a..a58ac2e31e46e983e2ab565159433b06f8682d2f 100644 --- a/src/main/java/projects/defaultProject/models/reliabilityModels/LossyDelivery.java +++ b/src/main/java/projects/defaultProject/models/reliabilityModels/LossyDelivery.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.models.reliabilityModels; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; import sinalgo.exception.SinalgoFatalException; @@ -43,6 +46,8 @@ import sinalgo.models.ReliabilityModel; import sinalgo.nodes.messages.Packet; import sinalgo.tools.statistics.Distribution; +import java.util.Random; + /** * A loossy reliability model that drops messages with a constant probability. * <p> @@ -51,15 +56,17 @@ import sinalgo.tools.statistics.Distribution; * <p> * <LossyDelivery dropRate="..."/> */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class LossyDelivery extends ReliabilityModel { - private java.util.Random rand = Distribution.getRandom(); + private Random rand = Distribution.getRandom(); private double dropRate; // default is 0 @Override public boolean reachesDestination(Packet p) { - double r = this.rand.nextDouble(); - return (r > this.dropRate); + double r = this.getRand().nextDouble(); + return (r > this.getDropRate()); } /** @@ -67,9 +74,10 @@ public class LossyDelivery extends ReliabilityModel { */ public LossyDelivery() { try { - this.dropRate = Configuration.getDoubleParameter("LossyDelivery/dropRate"); + this.setDropRate(Configuration.getDoubleParameter("LossyDelivery/dropRate")); } catch (CorruptConfigurationEntryException e) { throw new SinalgoFatalException("Missing configuration entry for the Message Transmission Model:\n" + e.getMessage()); } } + } diff --git a/src/main/java/projects/defaultProject/nodes/edges/BooleanEdge.java b/src/main/java/projects/defaultProject/nodes/edges/BooleanEdge.java index 8f2456894f8bfef152b2b96bfff0b8efe03fb4ec..f808bbacfb32278efd5aca91e16d2384bca50490 100644 --- a/src/main/java/projects/defaultProject/nodes/edges/BooleanEdge.java +++ b/src/main/java/projects/defaultProject/nodes/edges/BooleanEdge.java @@ -63,7 +63,7 @@ public class BooleanEdge extends Edge { */ @Getter @Setter - private static boolean onlyUseFlagedEdges = false; + private static boolean onlyUseFlagedEdges; /** * @return Whether this edge is drawn on the GUI or to PostScript. diff --git a/src/main/java/projects/defaultProject/nodes/timers/DirectMessageTimer.java b/src/main/java/projects/defaultProject/nodes/timers/DirectMessageTimer.java index d7c849a53809fbc59012741a8d4f379694c94f7e..0632654cbe910b50f2a3e9f27e9f4f0fa5bf7791 100644 --- a/src/main/java/projects/defaultProject/nodes/timers/DirectMessageTimer.java +++ b/src/main/java/projects/defaultProject/nodes/timers/DirectMessageTimer.java @@ -1,5 +1,8 @@ package projects.defaultProject.nodes.timers; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.Node; import sinalgo.nodes.messages.Message; import sinalgo.nodes.timers.Timer; @@ -11,6 +14,8 @@ import sinalgo.nodes.timers.Timer; * <p> * The message is sent by the node who starts the timer. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class DirectMessageTimer extends Timer { private Message msg; // the msg to send @@ -23,12 +28,13 @@ public class DirectMessageTimer extends Timer { * @param n The node to send the msg to */ public DirectMessageTimer(Message m, Node n) { - this.msg = m; - this.target = n; + this.setMsg(m); + this.setTarget(n); } @Override public void fire() { - this.getTargetNode().sendDirect(this.msg, this.target); + this.getTargetNode().sendDirect(this.getMsg(), this.getTarget()); } + } diff --git a/src/main/java/projects/defaultProject/nodes/timers/MessageTimer.java b/src/main/java/projects/defaultProject/nodes/timers/MessageTimer.java index 7a0b9aec7de2fd65dafcb3b19d77cae3b98b40c8..9a9baf442878bdf6477e2b64b71e5774c632084a 100644 --- a/src/main/java/projects/defaultProject/nodes/timers/MessageTimer.java +++ b/src/main/java/projects/defaultProject/nodes/timers/MessageTimer.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.defaultProject.nodes.timers; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.Node; import sinalgo.nodes.messages.Message; import sinalgo.nodes.timers.Timer; @@ -44,6 +47,8 @@ import sinalgo.nodes.timers.Timer; * A timer that sends a message at a given time. The message may be unicast to a * specific node or broadcast. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class MessageTimer extends Timer { private Node receiver; // the receiver of the message, null if the message should be broadcast @@ -60,8 +65,8 @@ public class MessageTimer extends Timer { * @param receiver The receiver of the message. */ public MessageTimer(Message msg, Node receiver) { - this.msg = msg; - this.receiver = receiver; + this.setMsg(msg); + this.setReceiver(receiver); } /** @@ -70,16 +75,17 @@ public class MessageTimer extends Timer { * @param msg The message to be sent when this timer fires. */ public MessageTimer(Message msg) { - this.msg = msg; - this.receiver = null; // indicates broadcasting + this.setMsg(msg); + this.setReceiver(null); // indicates broadcasting } @Override public void fire() { - if (this.receiver != null) { // there's a receiver => unicast the message - this.getTargetNode().send(this.msg, this.receiver); + if (this.getReceiver() != null) { // there's a receiver => unicast the message + this.getTargetNode().send(this.getMsg(), this.getReceiver()); } else { // there's no reciever => broadcast the message - this.getTargetNode().broadcast(this.msg); + this.getTargetNode().broadcast(this.getMsg()); } } + } diff --git a/src/main/java/projects/sample1/CustomGlobal.java b/src/main/java/projects/sample1/CustomGlobal.java index 9ea707a8e4d6aa845f3aee2fc55692d29c35e911..3cbdb0ed23b60f85e0f9a504daf0ec49c017816d 100644 --- a/src/main/java/projects/sample1/CustomGlobal.java +++ b/src/main/java/projects/sample1/CustomGlobal.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package projects.sample1; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import projects.sample1.nodes.nodeImplementations.S1Node; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -70,6 +73,8 @@ import java.util.Enumeration; * framework with custom methods that can be called either through the menu * or via a button that is added to the GUI. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class CustomGlobal extends AbstractCustomGlobal { private Logging log = Logging.getLogger("s1_log.txt"); @@ -82,27 +87,27 @@ public class CustomGlobal extends AbstractCustomGlobal { { if (Configuration.hasParameter("exitAfter")) { try { - this.exitAfterFixedRounds = Configuration.getBooleanParameter("exitAfter"); + this.setExitAfterFixedRounds(Configuration.getBooleanParameter("exitAfter")); } catch (CorruptConfigurationEntryException e1) { throw new SinalgoFatalException("The 'exitAfter' needs to be a valid boolean."); } - if (this.exitAfterFixedRounds) { + if (this.isExitAfterFixedRounds()) { try { - this.exitAfterNumRounds = Configuration.getIntegerParameter("exitAfter/rounds"); + this.setExitAfterNumRounds(Configuration.getIntegerParameter("exitAfter/rounds")); } catch (CorruptConfigurationEntryException e) { throw new SinalgoFatalException( "The 'exitAfter/rounds' parameter specifies the maximum time the simulation runs. It needs to be a valid integer."); } } } else { - this.exitAfterFixedRounds = false; + this.setExitAfterFixedRounds(false); } } @Override public boolean hasTerminated() { - if (this.exitAfterFixedRounds) { - return this.exitAfterNumRounds <= Global.getCurrentTime(); + if (this.isExitAfterFixedRounds()) { + return this.getExitAfterNumRounds() <= Global.getCurrentTime(); } if (Tools.isSimulationInGuiMode()) { @@ -142,7 +147,7 @@ public class CustomGlobal extends AbstractCustomGlobal { @Override public void postRound() { double dt = System.currentTimeMillis() - Global.getStartTimeOfRound().getTime(); - this.log.logln("Round " + (int) (Global.getCurrentTime()) + " time: " + dt + " Msg/Round: " + this.getLog().logln("Round " + (int) (Global.getCurrentTime()) + " time: " + dt + " Msg/Round: " + Global.getNumberOfMessagesInThisRound()); } @@ -212,5 +217,4 @@ public class CustomGlobal extends AbstractCustomGlobal { public void onExit() { // perform some cleanup operations here } - } diff --git a/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java b/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java index 1657d7f33fb8e5506ef3d6d94f0df640a5f89ba4..62700434ff519a2c17738a7a0aacdcc52a0ddde8 100644 --- a/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java +++ b/src/main/java/projects/sample1/nodes/nodeImplementations/S1Node.java @@ -70,18 +70,18 @@ public class S1Node extends Node { /** * number of messages sent by this node in the current round */ - private int msgSentInThisRound = 0; + private int msgSentInThisRound; /** * total number of messages sent by this node */ - private int msgSent = 0; + private int msgSent; /** * The amount to increment the data of the message each time it goes throug a * node. */ - private int increment = 0; + private int increment; Logging log = Logging.getLogger("s1_log"); diff --git a/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java b/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java index 699eaaace99b3401acbca245e0700e9e6540b101..ed80ea9fac884f2fd530dfbbdcdc0beb7c72899b 100644 --- a/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java +++ b/src/main/java/projects/sample2/nodes/nodeImplementations/S2Node.java @@ -61,14 +61,14 @@ public class S2Node extends Node { @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) - private static int maxNeighbors = 0; // global field containing the max number of neighbors any node ever had + private static int maxNeighbors; // global field containing the max number of neighbors any node ever had @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) - private static boolean isColored = false; + private static boolean isColored; - private boolean isMaxNode = false; // flag set to true when this node has most neighbors - private boolean drawAsNeighbor = false; // flag set by a neighbor to color specially + private boolean isMaxNode; // flag set to true when this node has most neighbors + private boolean drawAsNeighbor; // flag set by a neighbor to color specially // The set of nodes this node has already seen private TreeSet<S2Node> neighbors = new TreeSet<>(); diff --git a/src/main/java/projects/sample3/CustomGlobal.java b/src/main/java/projects/sample3/CustomGlobal.java index 8739c1efe4cb2e463296621c83a60d1adaed33f3..2b51c8ef1c71ab5103c853f1cdd8512d235ac0ef 100644 --- a/src/main/java/projects/sample3/CustomGlobal.java +++ b/src/main/java/projects/sample3/CustomGlobal.java @@ -80,7 +80,7 @@ public class CustomGlobal extends AbstractCustomGlobal { } } - private boolean automaticSMS = false; + private boolean automaticSMS; @AbstractCustomGlobal.GlobalMethod(menuText = "Toggle Automatic SMS") public void toggleAutomaticSMS() { diff --git a/src/main/java/projects/sample3/models/connectivityModels/AntennaConnection.java b/src/main/java/projects/sample3/models/connectivityModels/AntennaConnection.java index 1dcafc41a8a069bb3b77badb9da5075de7bda771..4432e3b5f20796eb167b5b80a29f0354b3ab1683 100644 --- a/src/main/java/projects/sample3/models/connectivityModels/AntennaConnection.java +++ b/src/main/java/projects/sample3/models/connectivityModels/AntennaConnection.java @@ -50,7 +50,7 @@ import sinalgo.runtime.Main; */ public class AntennaConnection extends ConnectivityModelHelper { - private static boolean initialized = false; // indicates whether the static fields of this class have already been + private static boolean initialized; // indicates whether the static fields of this class have already been // initialized private static double rMaxSquare; // we reuse the rMax value from the GeometricNodeCollection. diff --git a/src/main/java/projects/sample3/models/distributionModels/GridDistribution.java b/src/main/java/projects/sample3/models/distributionModels/GridDistribution.java index d4a50c229ea31c88c2a26ec8858327ea4e8aa746..5edf9e63019e5f487cf851b97dcd6817ee4afc21 100644 --- a/src/main/java/projects/sample3/models/distributionModels/GridDistribution.java +++ b/src/main/java/projects/sample3/models/distributionModels/GridDistribution.java @@ -58,10 +58,10 @@ public class GridDistribution extends DistributionModel { private Random rand = Distribution.getRandom(); - private double radius = 0; + private double radius; private Vector<Position> positions = new Vector<>(); - private int returnNum = 0; + private int returnNum; @Override public void initialize() { diff --git a/src/main/java/projects/sample3/nodes/messages/InviteMessage.java b/src/main/java/projects/sample3/nodes/messages/InviteMessage.java index f3db4e1b165ece629392c532a0a91ba90e5998ad..602c5672722086e2e6aac531d275434a7dfcba6c 100644 --- a/src/main/java/projects/sample3/nodes/messages/InviteMessage.java +++ b/src/main/java/projects/sample3/nodes/messages/InviteMessage.java @@ -11,7 +11,7 @@ import sinalgo.nodes.messages.Message; @Setter public class InviteMessage extends Message { - private boolean requireSubscription = false; // if true, the receiver needs to subscribe even if it is already + private boolean requireSubscription; // if true, the receiver needs to subscribe even if it is already // subscribed @Override diff --git a/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java b/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java index 6535c925d861b2d87000c226c47739d484f432d2..b99496801be1d05929556afa498dfd1ae6521a71 100644 --- a/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java +++ b/src/main/java/projects/sample3/nodes/nodeImplementations/MobileNode.java @@ -1,6 +1,10 @@ package projects.sample3.nodes.nodeImplementations; -import projects.sample3.nodes.messages.*; +import projects.sample3.nodes.messages.ByeBye; +import projects.sample3.nodes.messages.InviteMessage; +import projects.sample3.nodes.messages.SmsAckMessage; +import projects.sample3.nodes.messages.SmsMessage; +import projects.sample3.nodes.messages.SubscirbeMessage; import projects.sample3.nodes.timers.SmsTimer; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -22,9 +26,9 @@ public class MobileNode extends Node { private Logging log = Logging.getLogger();// ("smsLog.txt"); - private Antenna currentAntenna = null; // the antenna ths node is connected to, null if this node is not connected to + private Antenna currentAntenna; // the antenna ths node is connected to, null if this node is not connected to // an antenna - private int seqIDCounter = 0; + private int seqIDCounter; public Antenna getCurrentAntenna() { return this.currentAntenna; diff --git a/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java b/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java index 258f48fe62c2b8a766ca62010f5b53fd23c21428..8f16f718cff9ad9ca912cf12403acc106c7b5619 100644 --- a/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java +++ b/src/main/java/projects/sample3/nodes/timers/InviteMsgTimer.java @@ -18,13 +18,13 @@ public class InviteMsgTimer extends Timer { private Distribution dist; private int refreshRate; - private int refreshCounter = 0; + private int refreshCounter; // If set to true, the antenna requires the nodes to register again // such that it can drop old mobileNodes @Getter @Setter - private boolean requireSubscription = false; + private boolean requireSubscription; public InviteMsgTimer() { try { diff --git a/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java b/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java index 03ff1685610c6d7b7164339d23c3766ecad51876..091bbe2cbf80d4b1f3590c8443677861eabc3f2c 100644 --- a/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java +++ b/src/main/java/projects/sample4/nodes/nodeImplementations/S4Node.java @@ -174,7 +174,7 @@ public class S4Node extends Node { }, "Select a node to which you want to send a direct 'PINK' message."); } - private boolean simpleDraw = false; + private boolean simpleDraw; @Override public void init() { @@ -205,7 +205,7 @@ public class S4Node extends Node { // not called in async mode! } - private boolean drawRound = false; + private boolean drawRound; private boolean isDrawRound() { if (this.drawRound) { diff --git a/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java b/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java index 3eb948bc5db03c3f948a8c97fc1945a994c661f6..3b4717b01eb2987329d2ddef73f0f2f305934858 100644 --- a/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java +++ b/src/main/java/projects/sample5/nodes/messages/FloodFindMsg.java @@ -40,7 +40,7 @@ public class FloodFindMsg extends Message { */ private int sequenceID; - private RetryFloodingTimer retryTimer = null; + private RetryFloodingTimer retryTimer; /** * The node to which a route should be established. diff --git a/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java b/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java index d91016c6e594e2f3013c245ce3546431990f0eb2..aa5a4598bb0c20170ac9756cb16a7faeff3fb436 100644 --- a/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java +++ b/src/main/java/projects/sample5/nodes/messages/PayloadMsg.java @@ -18,7 +18,7 @@ public class PayloadMsg extends Message { 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 - private boolean requireACK = false; // Indicates whether this msg needs to be ACKed + private boolean requireACK; // Indicates whether this msg needs to be ACKed /** * Constructor diff --git a/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java b/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java index 2666e0d14b4e90bd13695ffc1379a185c75f58aa..73ba5da8d406d368aa1fd4ff28963c31c4899197 100644 --- a/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java +++ b/src/main/java/projects/sample5/nodes/nodeImplementations/FNode.java @@ -44,7 +44,7 @@ public class FNode extends Node { } // counter, incremented and added for each msg sent (not forwarded) by this node - private int seqID = 0; // an ID used to distinguish successive msg + private int seqID; // an ID used to distinguish successive msg // The routing table of this node, maps destination node to a routing entry private Hashtable<Node, RoutingEntry> routingTable = new Hashtable<>(); diff --git a/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java b/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java index 106486cecdfd47a59408c8c37dfe04cad0b9f24e..36865213c92bd699cc2bf6fe8bfdbafc42ecf96f 100644 --- a/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java +++ b/src/main/java/projects/sample6/nodes/nodeImplementations/LeafNode.java @@ -20,7 +20,7 @@ public class LeafNode extends TreeNode { // A counter that may be reset by the user @Getter @Setter - private static int smallIdCounter = 0; + private static int smallIdCounter; private int smallID; diff --git a/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java b/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java index 9fbab4cd9be8f878ce47faa8ca72157bda7d8f81..8b844a51aaf919068f6bfde90f4ab944af9a8e33 100644 --- a/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java +++ b/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java @@ -20,7 +20,7 @@ public class TreeNode extends Node { @Getter @Setter - private TreeNode parent = null; // the parentGUI in the tree, null if this node is the root + private TreeNode parent; // the parentGUI in the tree, null if this node is the root @Override public void checkRequirements() throws WrongConfigurationException { diff --git a/src/main/java/sinalgo/Run.java b/src/main/java/sinalgo/Run.java index 7c7bfd92546f8c52424113bbf8c03f753e21e089..929f586e00c98138f49bc37d1f0dcce35dfd6b89 100644 --- a/src/main/java/sinalgo/Run.java +++ b/src/main/java/sinalgo/Run.java @@ -253,7 +253,7 @@ public class Run { return Global.getProjectName(); } - private static Process mainProcess = null; // the simulation process, may be null + private static Process mainProcess; // the simulation process, may be null /** * A shutdown hook to kill the simulation process when this process is killed. diff --git a/src/main/java/sinalgo/configuration/AppConfig.java b/src/main/java/sinalgo/configuration/AppConfig.java index d5bd75f335bf562a9dabd679fab105f64211888c..52182ea10f833499d5edd812b07bfd77ac1f8b85 100644 --- a/src/main/java/sinalgo/configuration/AppConfig.java +++ b/src/main/java/sinalgo/configuration/AppConfig.java @@ -73,21 +73,21 @@ public class AppConfig { private int projectSelectorWindowHeight = 400; private int projectSelectorWindowPosX = 50; private int projectSelectorWindowPosY = 50; - private boolean projectSelectorIsMaximized = false; + private boolean projectSelectorIsMaximized; private int projectSelectorSelectedTab = 1; // 1 = description, 2 = config private String lastChosenProject = ""; private int guiWindowWidth = 800; private int guiWindowHeight = 600; private int guiWindowPosX = 50; private int guiWindowPosY = 50; - private boolean guiIsMaximized = false; - private long seedFromLastRun = 0; + private boolean guiIsMaximized; + private long seedFromLastRun; private int helpWindowWidth = 500; private int helpWindowHeight = 500; private int helpWindowPosX = 200; private int helpWindowPosY = 200; - private boolean helpWindowIsMaximized = false; + private boolean helpWindowIsMaximized; private boolean guiControlPanelExpandSimulation = true; private boolean guiControlPanelShowFullViewPanel = true; @@ -99,7 +99,7 @@ public class AppConfig { private String lastSelectedFileDirectory = ""; // where the user pointed last to open a file private boolean checkForSinalgoUpdate = true; // check for updates - private long timeStampOfLastUpdateCheck = 0; // machine time when Sinalgo checked last for an update + private long timeStampOfLastUpdateCheck; // machine time when Sinalgo checked last for an update private int generateNodesDlgNumNodes = 100; // # of nodes to generate @@ -107,7 +107,7 @@ public class AppConfig { @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) - private static AppConfig singletonInstance = null; + private static AppConfig singletonInstance; @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) diff --git a/src/main/java/sinalgo/configuration/Configuration.java b/src/main/java/sinalgo/configuration/Configuration.java index 1ba2e41f2fca1bcccc276070b10735d058ac310c..eec441a36dfee557f822fbaa5f6f85f9b539d7a4 100644 --- a/src/main/java/sinalgo/configuration/Configuration.java +++ b/src/main/java/sinalgo/configuration/Configuration.java @@ -69,7 +69,14 @@ import java.util.List; import java.util.Map.Entry; import java.util.Scanner; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.*; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_CONNECTIVITY; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_DISTRIBUTION; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_INTERFERENCE; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_MESSAGE_TRANSMISSION; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_MOBILITY; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_RELIABILITY; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.NODES_EDGES; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.NODES_IMPLEMENTATIONS; /** * This class provides globally visible constants and access to the custom @@ -246,7 +253,7 @@ public class Configuration { @Setter @SectionInConfigFile("Simulation") @DefaultInConfigFile("Switches between synchronous and asynchronous mode.") - private static boolean asynchronousMode = false; + private static boolean asynchronousMode; /** */ @Getter @@ -314,7 +321,7 @@ public class Configuration { @Setter @DefaultInConfigFile("If set to true, the application exits as soon as the\n" + "termination criteria is met. This flag only affects\n" + "the GUI mode.") - private static boolean exitOnTerminationInGUI = false; + private static boolean exitOnTerminationInGUI; /** */ @Getter @@ -322,7 +329,7 @@ public class Configuration { @DefaultInConfigFile("If set true, in asynchronous mode the connections are initialized\n" + "before the first event executes. Note that this flag is useless in synchronous mode\n" + "as the connections are updated in every step anyway.") - private static boolean initializeConnectionsOnStartup = false; + private static boolean initializeConnectionsOnStartup; /** */ @Getter @@ -338,7 +345,7 @@ public class Configuration { + "a unicast message is dropped. In synchronous mode, the sender \n" + "is informed in the round after the message should have arrived, and \n" + "immediately upon arrival in asynchronous mode.") - private static boolean generateNAckMessages = false; + private static boolean generateNAckMessages; /** */ @Getter @@ -372,13 +379,13 @@ public class Configuration { @SectionInConfigFile("Random number generators") @DefaultInConfigFile("If set to true, the random number generators of the\n" + "framework use the same seed as in the previous run.") - private static boolean useSameSeedAsInPreviousRun = false; + private static boolean useSameSeedAsInPreviousRun; @Getter @Setter @DefaultInConfigFile("If set to true, and useSameSeedAsInPreviousRun is set to false, \n" + "the random number generators of the\n" + "framework uses the specified fixed seed.") - private static boolean useFixedSeed = false; + private static boolean useFixedSeed; /** */ @Getter @@ -424,7 +431,7 @@ public class Configuration { @Getter @Setter @DefaultInConfigFile("If set to true, the log files are flushed every time\n" + "a new log is added.") - private static boolean eagerFlush = false; + private static boolean eagerFlush; // ------------------------------------------------------------------------- // GUI @@ -441,7 +448,7 @@ public class Configuration { @Getter @Setter @DefaultInConfigFile("If true, the graph edges are drawn as directed arrows,\n otherwise simple lines.") - private static boolean drawArrows = false; + private static boolean drawArrows; /** */ @Getter @@ -499,7 +506,7 @@ public class Configuration { @SectionInConfigFile("Background map in 2D") @DefaultInConfigFile("If set to true, the background of a 2D simulation is colored\n" + "according to a map, specified in a map-file, specified\n" + "by the field map") - private static boolean useMap = false; + private static boolean useMap; /** */ @Getter @@ -568,7 +575,7 @@ public class Configuration { @OptionalInConfigFile("Show the models implemented by all projects in the drop\n" + "down options. When set to false, only the models by the\n" + "selected project and the default project are shown.") - private static boolean showModelsOfAllProjects = false; + private static boolean showModelsOfAllProjects; // ------------------------------------------------------------------------- // The default transformation and node collection implementations for the 2D / @@ -642,7 +649,7 @@ public class Configuration { @Setter @SectionInConfigFile("Animation Settings") @OptionalInConfigFile("Draw an envelope for each message that is being sent") - private static boolean showMessageAnimations = false; + private static boolean showMessageAnimations; /** */ @Getter diff --git a/src/main/java/sinalgo/gui/GUI.java b/src/main/java/sinalgo/gui/GUI.java index 6109af40fbef0591b07e6b6e4c32bf050499c3c8..01ff80432dbacbe712fa7b49dc789f5248e8cef7 100644 --- a/src/main/java/sinalgo/gui/GUI.java +++ b/src/main/java/sinalgo/gui/GUI.java @@ -46,7 +46,12 @@ import sinalgo.exception.SinalgoFatalException; import sinalgo.gui.controlPanel.ControlPanel; import sinalgo.gui.controlPanel.MaximizedControlPanel; import sinalgo.gui.controlPanel.MinimizedControlPanel; -import sinalgo.gui.dialogs.*; +import sinalgo.gui.dialogs.AboutDialog; +import sinalgo.gui.dialogs.GenerateNodesDialog; +import sinalgo.gui.dialogs.GlobalSettingsDialog; +import sinalgo.gui.dialogs.GraphInfoDialog; +import sinalgo.gui.dialogs.GraphPreferencesDialog; +import sinalgo.gui.dialogs.HelpDialog; import sinalgo.gui.transformation.PositionTransformation; import sinalgo.io.eps.Exporter; import sinalgo.nodes.Position; @@ -62,7 +67,13 @@ import javax.swing.*; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -592,7 +603,7 @@ public class GUI extends JFrame implements ActionListener { } } - private JPanel guiPanel = null; + private JPanel guiPanel; /** * Switches between the two modes for the control panel depending on the boolean @@ -636,7 +647,7 @@ public class GUI extends JFrame implements ActionListener { */ @Getter @Setter - private boolean firstTimePainted = false; + private boolean firstTimePainted; @Override public void paint(Graphics g) { diff --git a/src/main/java/sinalgo/gui/GraphPanel.java b/src/main/java/sinalgo/gui/GraphPanel.java index f54bb00a6b6d8b51d0d22e8b397b87008960f4b9..43b3da6482c97c49f724ad32f64b84825ec0f838 100644 --- a/src/main/java/sinalgo/gui/GraphPanel.java +++ b/src/main/java/sinalgo/gui/GraphPanel.java @@ -64,7 +64,13 @@ import sinalgo.tools.logging.Logging; import javax.swing.*; import javax.swing.event.MouseInputListener; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import java.util.ConcurrentModificationException; import java.util.Enumeration; import java.util.Stack; @@ -79,14 +85,14 @@ public class GraphPanel extends JPanel { private static final long serialVersionUID = -7446360484673626267L; - private Image offscreen = null; + private Image offscreen; // needs to be set to true whenever offscreen has been assigned a new object @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private boolean newOffscreen = true; - private boolean forcedDraw = false; + private boolean forcedDraw; private NodePopupMenu nodePopupMenu; private EdgePopupMenu edgePopupMenu; @@ -103,8 +109,8 @@ public class GraphPanel extends JPanel { private Point rotateStartPoint; private Vector<Node> nodesToHighlight = new Vector<>(10); private Vector<Node> nodesToDrawCoordCube = new Vector<>(10); - private Node toolTipDrawCoordCube = null; - private Node nodeToDragDrawCoordCube = null; + private Node toolTipDrawCoordCube; + private Node nodeToDragDrawCoordCube; private int minMouseMovementUntilNodeMovement = 10; // threshold (in mouse-pixels) for 3D before moving a node // this scales the underlying image @@ -112,7 +118,7 @@ public class GraphPanel extends JPanel { private int imageSizeY; private Point currentCursorPosition = new Point(0, 0); // the position of the cursor - private Rectangle zoomRect = null; + private Rectangle zoomRect; private int zoomRectMinSize = 5; private Logging log = Logging.getLogger(); // system wide logger @@ -125,7 +131,7 @@ public class GraphPanel extends JPanel { */ @Getter @Setter - private static boolean firstTimePainted = false; + private static boolean firstTimePainted; private final PositionTransformation pt; private long myLastPtVersionNumber = -1; @@ -135,10 +141,10 @@ public class GraphPanel extends JPanel { private int cancelAreaHeight; private int cancelAreaOffsetX; // dimension of the cancel area printed directly // onto the graphics - private Node userSelectsNodeCurrentFocus = null; // the node over which the mouse currently hovers, if the user is + private Node userSelectsNodeCurrentFocus; // the node over which the mouse currently hovers, if the user is // to select a node // Set to true while the user is asked to select a node - private boolean userSelectsNodeMode = false; + private boolean userSelectsNodeMode; private Stack<Tuple<NodeSelectionHandler, String>> userSelectsNodeHandler = new Stack<>(); // stack // of // handlers, diff --git a/src/main/java/sinalgo/gui/ProjectSelector.java b/src/main/java/sinalgo/gui/ProjectSelector.java index 5f3afb37be89c0a15104286e5c0ed191cf57299b..8b578abcb0919b98884eef0ef8cccc9c7b8fa176 100644 --- a/src/main/java/sinalgo/gui/ProjectSelector.java +++ b/src/main/java/sinalgo/gui/ProjectSelector.java @@ -69,10 +69,26 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.text.JTextComponent; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; -import java.io.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.StringReader; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -111,7 +127,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec private JTabbedPane right = new JTabbedPane(); - private boolean showOptionalFields = false; + private boolean showOptionalFields; private Vector<ConfigEntry> projectEntries; @@ -433,8 +449,8 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec return result.toString(); } - private MultiLineToolTipJComboBox asynchronousSimulationCB = null; - private MultiLineToolTipJComboBox mobilityCB = null; + private MultiLineToolTipJComboBox asynchronousSimulationCB; + private MultiLineToolTipJComboBox mobilityCB; /** * Generate the GUI components to show the config for a given project @@ -996,7 +1012,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec private class UserInputListener implements KeyListener, ActionListener { @Getter - private boolean isModified = false; + private boolean isModified; public void reset() { ProjectSelector.this.getSaveConfig().setEnabled(false); @@ -1083,13 +1099,13 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec * member is set only when the GUI is created, and may remain NULL when this * entry does not have a value field (e.g. a comment, or section header) */ - private JComponent valueComponent = null; + private JComponent valueComponent; /** * The GUI component for this entry that holds the text for this entry. This * member is set only when the GUI is created. */ - private JComponent textComponent = null; + private JComponent textComponent; } diff --git a/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java b/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java index 1e58440c76ec2a96113a4b27b4525bfd3f500d2f..dc2c6f9a9417c57d5dc6106529915bd8b13c124a 100644 --- a/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java @@ -103,7 +103,7 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) - private static JButton start = null; // reused to keep the picture + private static JButton start; // reused to keep the picture @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) @@ -122,17 +122,17 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou @Setter private Color bgColor = new Color(this.getBackground().getRed(), this.getBackground().getGreen(), this.getBackground().getBlue()); - private GUI parentGUI = null; + private GUI parentGUI; private JTextField roundsPerformed = new JTextField(0); private JTextField timePerformed = new JTextField(0); private JTextField mousePositionField = new JTextField(8); private JPanel info = new JPanel(); private MultiLineToolTipJList eventJList = new MultiLineToolTipJList(); - private JButton abort = null; - private JButton runMenuButton = null; + private JButton abort; + private JButton runMenuButton; private JButton exit = new JButton("Exit"); - private ZoomPanel zoomPanel = null; + private ZoomPanel zoomPanel; // A list of all buttons that are disabled while a simulation runs @Getter(AccessLevel.PRIVATE) diff --git a/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java b/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java index 9d15c715f1cf5a91784ed16b96f2c462a5e30cc7..bc6b98b395b28d60962f53d1ca249acf14b8afa0 100644 --- a/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java @@ -673,7 +673,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis */ @Getter @Setter - private Event event = null; + private Event event; private EventQueueElement(String displayableText, String tooltip) { this.setDisplayableText(displayableText); diff --git a/src/main/java/sinalgo/gui/controlPanel/ZoomPanel.java b/src/main/java/sinalgo/gui/controlPanel/ZoomPanel.java index 82bbb92b1b425199ef05bf8fa8080ee54831f345..a1b4a97ef2d848b2eab738ccd0025f87ff9dd8f0 100644 --- a/src/main/java/sinalgo/gui/controlPanel/ZoomPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/ZoomPanel.java @@ -130,8 +130,8 @@ public class ZoomPanel extends JPanel implements MouseInputListener, MouseWheelL } } - private Point shiftStartPoint = null; - private Point rotateStartPoint = null; + private Point shiftStartPoint; + private Point rotateStartPoint; @Override public void mousePressed(MouseEvent e) { diff --git a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java index 132caaed1d13f739c6a8b733930707484fdba1d8..23a54b07dc106112023cf2c717d21ba5c27eb783 100644 --- a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java @@ -47,7 +47,12 @@ import sinalgo.gui.GUI; import sinalgo.gui.GuiHelper; import sinalgo.gui.helper.NonRegularGridLayout; import sinalgo.gui.helper.UnborderedJTextField; -import sinalgo.models.*; +import sinalgo.models.ConnectivityModel; +import sinalgo.models.DistributionModel; +import sinalgo.models.InterferenceModel; +import sinalgo.models.MobilityModel; +import sinalgo.models.Model; +import sinalgo.models.ReliabilityModel; import sinalgo.nodes.Node; import sinalgo.nodes.Position; import sinalgo.runtime.Global; @@ -62,7 +67,12 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.Vector; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.*; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_CONNECTIVITY; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_DISTRIBUTION; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_INTERFERENCE; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_MOBILITY; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_RELIABILITY; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.NODES_IMPLEMENTATIONS; /** * The Dialog to generate a number of new Nodes. @@ -117,8 +127,8 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog private JCheckBox allModelsCheckBox; - private PercentualProgressDialog pf = null; - private boolean canceled = false; + private PercentualProgressDialog pf; + private boolean canceled; private GUI parentGUI; diff --git a/src/main/java/sinalgo/gui/dialogs/HelpDialog.java b/src/main/java/sinalgo/gui/dialogs/HelpDialog.java index 4b149afaaa9d6b69f98c5f02f755b8ebdf06e9cf..02beee1bad316b9dd6179d4b7c9f366be130efe7 100644 --- a/src/main/java/sinalgo/gui/dialogs/HelpDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/HelpDialog.java @@ -49,7 +49,11 @@ import javax.swing.event.HyperlinkListener; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLFrameHyperlinkEvent; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.io.IOException; import java.net.URL; @@ -62,8 +66,8 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener private JEditorPane html; private JButton menuButton = new JButton("Menu"); - private URL currentURL = null; - private URL defaultURL = null; + private URL currentURL; + private URL defaultURL; private HelpDialog(JFrame parent) { // is private, use showHelp() to create it in a new thread this.setTitle("Sinalgo Help (source: https://github.com/andrebrait/sinalgo)"); @@ -143,7 +147,7 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener }; } - private MenuDialog menuDlg = null; // The menu dialog if its currently shown, otherwise null + private MenuDialog menuDlg; // The menu dialog if its currently shown, otherwise null private void showMenu() { Point p = this.getMenuButton().getLocationOnScreen(); diff --git a/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java b/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java index bfc344d2c7b289c9f2a7399e3eebe5b59002bb57..373527a46116ab53c79f45d5f7d7961a985aa560 100644 --- a/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java +++ b/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java @@ -89,7 +89,7 @@ public class NonRegularGridLayout extends GridLayout { */ @Getter(AccessLevel.PRIVATE) @Setter - private boolean alignToLeft = false; + private boolean alignToLeft; @Override public Dimension preferredLayoutSize(Container parent) { diff --git a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java index d8510d29fbbdb2d51f8487aae0052a7429334a2c..8883c445218c36717fb64b194e6aa3c518be989f 100644 --- a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java +++ b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java @@ -91,7 +91,7 @@ public class MultiLineToolTip extends JToolTip { * @return The number of columns the tooltip has. */ @Getter - private int columns = 0; + private int columns; /** * The fixed with of the tooltip. @@ -99,7 +99,7 @@ public class MultiLineToolTip extends JToolTip { * @return The fixed width of the tooltip. */ @Getter - private int fixedWidth = 0; + private int fixedWidth; } // used such that the tooltip can display several lines of text (e.g. newlines) diff --git a/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java b/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java index 8621aa16cc14e8ac81dfae2462e5654920497afd..2c6fb317014783f89591df47ce2a8bd679f428e2 100644 --- a/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java @@ -55,7 +55,7 @@ public abstract class AbstractPopupMenu extends JPopupMenu { private static final long serialVersionUID = 6108642977345194041L; @Getter - private GUI parentGUI = null; + private GUI parentGUI; private JMenuItem zoomIn = new JMenuItem("Zoom In"); private JMenuItem zoomOut = new JMenuItem("Zoom Out"); diff --git a/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java b/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java index 4e8acf5b393933b179acee855bd58765981e117d..16693c6793d57a0e61ec3a769b28175e95e0a5bd 100644 --- a/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java @@ -57,7 +57,7 @@ public class EdgePopupMenu extends AbstractPopupMenu implements ActionListener { private static final long serialVersionUID = 1879611828353447896L; - private Edge edge = null; + private Edge edge; private JMenuItem info = new JMenuItem("Info"); private JMenuItem delete = new JMenuItem("Delete"); diff --git a/src/main/java/sinalgo/gui/popups/NodePopupMenu.java b/src/main/java/sinalgo/gui/popups/NodePopupMenu.java index 37116e2467973c88946f9aebd533de9e94bc8f05..f227e2d7dcbd4bb1d317de05daf1b2b7ef3eaa24 100644 --- a/src/main/java/sinalgo/gui/popups/NodePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/NodePopupMenu.java @@ -66,7 +66,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { private HashMap<String, Method> methodsAndDescriptions = new HashMap<>(); - private Node node = null; + private Node node; private JMenuItem info = new JMenuItem("Info"); private JMenuItem delete = new JMenuItem("Delete Node"); private JMenuItem showCoordinateCube = new JMenuItem("Show coordinate cube"); diff --git a/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java b/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java index 9be4a30663c647d127672ed8f9a3fa3ce9a40c3b..d6b04b37804c6c04cd3d923bf5171a057f4291c1 100644 --- a/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java @@ -59,7 +59,7 @@ public class SpacePopupMenu extends AbstractPopupMenu implements ActionListener private static final long serialVersionUID = 8356598949303688723L; - private Point pos = null; + private Point pos; private JMenuItem add = new JMenuItem("Add Node"); /** diff --git a/src/main/java/sinalgo/gui/transformation/PositionTransformation.java b/src/main/java/sinalgo/gui/transformation/PositionTransformation.java index 5fdfafdb5e60bed89ae7afc41977d02404cf12d4..64a60243dbefc6d340f5b424f1ab75d040249756 100644 --- a/src/main/java/sinalgo/gui/transformation/PositionTransformation.java +++ b/src/main/java/sinalgo/gui/transformation/PositionTransformation.java @@ -75,7 +75,7 @@ public abstract class PositionTransformation { // I.e. in each public method call that changes the transformation, increment // this member. @Getter - private long versionNumber = 0; + private long versionNumber; /** * The current zoom factor used to draw the elements of the field diff --git a/src/main/java/sinalgo/gui/transformation/Transformation3D.java b/src/main/java/sinalgo/gui/transformation/Transformation3D.java index da68ccf6554fcd47d8e91e1b9437b7489db2801e..300f42284f5a6b830bbc83de4efc4bb932bff42f 100644 --- a/src/main/java/sinalgo/gui/transformation/Transformation3D.java +++ b/src/main/java/sinalgo/gui/transformation/Transformation3D.java @@ -55,7 +55,7 @@ public class Transformation3D extends PositionTransformation { private double[][] tm = new double[4][4]; // the 4x4 transformation matrix private double[][] rotm = new double[4][4]; // the 4x4 transformation matrix private double[][] tempm = new double[4][4]; // the 4x4 transformation matrix - private double tmAngleX = 0, tmAngleY = 0, tmAngleZ = 0; // the rotation angles of tm around the x, y, and z axis + private double tmAngleX, tmAngleY, tmAngleZ; // the rotation angles of tm around the x, y, and z axis // Two placeholders used to draw polygons private int[] polyLineX = new int[5]; diff --git a/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java b/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java index 9fa6c26c5f9e3fd5709d17464a5ad9480ab7c893..8f9919a1092f7cae2d85e8531fc1ad0ba9783238 100644 --- a/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java +++ b/src/main/java/sinalgo/io/eps/EPSOutputPrintStream.java @@ -68,14 +68,14 @@ import java.util.HashMap; @Setter(AccessLevel.PRIVATE) public class EPSOutputPrintStream extends PrintStream { - private int boundingBoxX = 0; - private int boundingBoxY = 0; - private int boundingBoxWidth = 0; - private int boundingBoxHeight = 0; + private int boundingBoxX; + private int boundingBoxY; + private int boundingBoxWidth; + private int boundingBoxHeight; private HashMap<String, String> macros = new HashMap<>(); - private double colorR = 0; - private double colorG = 0; - private double colorB = 0; + private double colorR; + private double colorG; + private double colorB; private double lineWidth = 1.0; /** diff --git a/src/main/java/sinalgo/io/eps/Exporter.java b/src/main/java/sinalgo/io/eps/Exporter.java index 029f2e3d3ade96b4f3783556935826dd744bb967..55b7fef87e704ee9a11ff42716bdaf8d78117d0b 100644 --- a/src/main/java/sinalgo/io/eps/Exporter.java +++ b/src/main/java/sinalgo/io/eps/Exporter.java @@ -52,7 +52,11 @@ import sinalgo.runtime.SinalgoRuntime; import javax.swing.*; import javax.swing.filechooser.FileFilter; import java.awt.*; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.Enumeration; import java.util.Random; @@ -64,7 +68,7 @@ public class Exporter { @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) - private JFrame parentFrame = null; + private JFrame parentFrame; /** * Creates a new Exporter instance with a given JFrame as parentGUI. The parentGUI diff --git a/src/main/java/sinalgo/io/mapIO/Map.java b/src/main/java/sinalgo/io/mapIO/Map.java index 00b5ac8da1d25569e073e560c388bffcfcbf6e1a..f4e8fed769adaee9453ee00223dafefdc4f3126a 100644 --- a/src/main/java/sinalgo/io/mapIO/Map.java +++ b/src/main/java/sinalgo/io/mapIO/Map.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.io.mapIO; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoFatalException; import sinalgo.gui.transformation.PositionTransformation; @@ -57,12 +60,16 @@ import java.io.InputStream; * The bitmap file may have any dimension, the framework scales to fit exactly * the deployment area. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class Map { private int[][] grid; private ColorModel colorModel = ColorModel.getRGBdefault(); // Color model to undertand RGB - private int imgWidth, imgHeight; // width / height of this BG image - private double xRatio, yRatio; + private int imgWidth; + private int imgHeight; // width / height of this BG image + private double xRatio; + private double yRatio; /** * @param aMapImageFile The name of the BMP file containing the background image. The @@ -76,13 +83,13 @@ public class Map { if ((img = ImageIO.read(in)) == null) { throw new FileNotFoundException("\n'" + aMapImageFile + "' - This image format is not supported."); } - this.imgWidth = img.getWidth(); - this.imgHeight = img.getHeight(); - this.grid = new int[this.imgWidth][this.imgHeight]; + this.setImgWidth(img.getWidth()); + this.setImgHeight(img.getHeight()); + this.setGrid(new int[this.getImgWidth()][this.getImgHeight()]); // copy the image data - for (int i = 0; i < this.imgWidth; i++) { - for (int j = 0; j < this.imgHeight; j++) { - this.grid[i][j] = img.getRGB(i, j); + for (int i = 0; i < this.getImgWidth(); i++) { + for (int j = 0; j < this.getImgHeight(); j++) { + this.getGrid()[i][j] = img.getRGB(i, j); } } } catch (FileNotFoundException e) { @@ -90,8 +97,8 @@ public class Map { } catch (IOException e) { throw new FileNotFoundException("Background map: Cannot open the image file\n" + e.getMessage()); } - this.xRatio = ((double) this.imgWidth) / Configuration.getDimX(); - this.yRatio = ((double) this.imgHeight) / Configuration.getDimY(); + this.setXRatio(((double) this.getImgWidth()) / Configuration.getDimX()); + this.setYRatio(((double) this.getImgHeight()) / Configuration.getDimY()); } /** @@ -103,21 +110,21 @@ public class Map { * @return The color of the specified position on the deployment area. */ private int getColorRGB(double x, double y) { - int imgx = (int) Math.floor(this.xRatio * x); - int imgy = (int) Math.floor(this.yRatio * y); + int imgx = (int) Math.floor(this.getXRatio() * x); + int imgy = (int) Math.floor(this.getYRatio() * y); if (imgx < 0) { imgx = 0; } - if (imgx >= this.imgWidth) { - imgx = this.imgWidth - 1; + if (imgx >= this.getImgWidth()) { + imgx = this.getImgWidth() - 1; } if (imgy < 0) { imgy = 0; } - if (imgy >= this.imgHeight) { - imgy = this.imgHeight - 1; + if (imgy >= this.getImgHeight()) { + imgy = this.getImgHeight() - 1; } - return this.grid[imgx][imgy]; + return this.getGrid()[imgx][imgy]; } /** @@ -140,9 +147,9 @@ public class Map { */ public boolean isWhite(double x, double y) { int color = this.getColorRGB(x, y); - int r = this.colorModel.getRed(color); // translate to default RGB values - int g = this.colorModel.getGreen(color); // translate to default RGB values - int b = this.colorModel.getBlue(color); // translate to default RGB values + int r = this.getColorModel().getRed(color); // translate to default RGB values + int g = this.getColorModel().getGreen(color); // translate to default RGB values + int b = this.getColorModel().getBlue(color); // translate to default RGB values return r + g + b == 765; // r,g,b == 255 } @@ -157,9 +164,9 @@ public class Map { */ public boolean isBlack(double x, double y) { int color = this.getColorRGB(x, y); - int r = this.colorModel.getRed(color); // translate to default RGB values - int g = this.colorModel.getGreen(color); // translate to default RGB values - int b = this.colorModel.getBlue(color); // translate to default RGB values + int r = this.getColorModel().getRed(color); // translate to default RGB values + int g = this.getColorModel().getGreen(color); // translate to default RGB values + int b = this.getColorModel().getBlue(color); // translate to default RGB values return r + g + b == 0; // r,g,b == 0 } @@ -172,8 +179,8 @@ public class Map { */ public boolean isColor(double x, double y, Color c) { int color = this.getColorRGB(x, y); - return c.getRed() == this.colorModel.getRed(color) && c.getBlue() == this.colorModel.getBlue(color) - && c.getGreen() == this.colorModel.getGreen(color); + return c.getRed() == this.getColorModel().getRed(color) && c.getBlue() == this.getColorModel().getBlue(color) + && c.getGreen() == this.getColorModel().getGreen(color); } /** @@ -184,7 +191,7 @@ public class Map { */ public int getRed(double x, double y) { int color = this.getColorRGB(x, y); - return this.colorModel.getRed(color); // translate to default RGB values + return this.getColorModel().getRed(color); // translate to default RGB values } /** @@ -195,7 +202,7 @@ public class Map { */ public int getBlue(double x, double y) { int color = this.getColorRGB(x, y); - return this.colorModel.getBlue(color); // translate to default RGB values + return this.getColorModel().getBlue(color); // translate to default RGB values } /** @@ -206,7 +213,7 @@ public class Map { */ public int getGreen(double x, double y) { int color = this.getColorRGB(x, y); - return this.colorModel.getGreen(color); // translate to default RGB values + return this.getColorModel().getGreen(color); // translate to default RGB values } /** @@ -221,15 +228,15 @@ public class Map { throw new SinalgoFatalException("Background maps are not supported in 3D.\n" + "Do not specify a " + "map while running a simulation in 3D."); } - double lengthX = 1 / this.xRatio; - double lengthY = 1 / this.yRatio; + double lengthX = 1 / this.getXRatio(); + double lengthY = 1 / this.getYRatio(); - for (int i = 0; i < this.imgWidth; i++) { - for (int j = 0; j < this.imgHeight; j++) { + for (int i = 0; i < this.getImgWidth(); i++) { + for (int j = 0; j < this.getImgHeight(); j++) { pt.translateToGUIPosition(i * lengthX, j * lengthY, 0); // top left corner of cell int topLeftX = pt.getGuiX(), topLeftY = pt.getGuiY(); pt.translateToGUIPosition((i + 1) * lengthX, (j + 1) * lengthY, 0); // bottom right corner of cell - Color col = new Color(this.grid[i][j]); + Color col = new Color(this.getGrid()[i][j]); g.setColor(col); g.fillRect(topLeftX, topLeftY, pt.getGuiX() - topLeftX, pt.getGuiY() - topLeftY); } @@ -237,12 +244,12 @@ public class Map { } public void drawToPostScript(EPSOutputPrintStream pw, PositionTransformation pt) { - double lengthX = 1 / this.xRatio; - double lengthY = 1 / this.yRatio; + double lengthX = 1 / this.getXRatio(); + double lengthY = 1 / this.getYRatio(); - for (int i = 0; i < this.imgWidth; i++) { - for (int j = 0; j < this.imgHeight; j++) { - Color col = new Color(this.grid[i][j]); + for (int i = 0; i < this.getImgWidth(); i++) { + for (int j = 0; j < this.getImgHeight(); j++) { + Color col = new Color(this.getGrid()[i][j]); if (col == Color.WHITE) { continue; // don't paint white } @@ -255,5 +262,4 @@ public class Map { } } } - } diff --git a/src/main/java/sinalgo/io/versionTest/VersionTester.java b/src/main/java/sinalgo/io/versionTest/VersionTester.java index 8437b05e08f79b727e5acc7b81b9fab453c91ec8..6addfb8e1494badcfb0dca6acb765f7db77bd6da 100644 --- a/src/main/java/sinalgo/io/versionTest/VersionTester.java +++ b/src/main/java/sinalgo/io/versionTest/VersionTester.java @@ -1,5 +1,8 @@ package sinalgo.io.versionTest; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.runtime.Main; @@ -12,8 +15,13 @@ import java.net.URLConnection; public class VersionTester extends Thread { - private static boolean isRunning = false; - private static boolean displayIfOK = false; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static boolean isRunning; + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static boolean displayIfOK; /** * Tests whether the installed version of Sinalgo is the most recent one. @@ -24,8 +32,8 @@ public class VersionTester extends Thread { * version is up to date. */ public static void testVersion(boolean testIfEnabled, boolean displayIfVersionMatch) { - displayIfOK = displayIfVersionMatch; - if (isRunning) { + setDisplayIfOK(displayIfVersionMatch); + if (isRunning()) { return; } if (testIfEnabled) { @@ -43,7 +51,7 @@ public class VersionTester extends Thread { @Override public void run() { - isRunning = true; + setRunning(true); try { URL url = new URL("https://github.com/andrebrait/sinalgo/raw/master/VERSION"); URLConnection con = url.openConnection(); @@ -60,7 +68,7 @@ public class VersionTester extends Thread { String line = in.readLine(); // we're only interested in the very first line if (line != null) { if (line.equals(Configuration.VERSION_STRING)) { - if (displayIfOK) { + if (isDisplayIfOK()) { Main.info("You are using the most recent version of Sinalgo."); } } else { @@ -91,7 +99,7 @@ public class VersionTester extends Thread { + ">---------------------------------------------------------------------\n"; Main.warning(msg); } finally { - isRunning = false; + setRunning(false); AppConfig.getAppConfig().setTimeStampOfLastUpdateCheck(System.currentTimeMillis()); } } diff --git a/src/main/java/sinalgo/io/xml/XMLParser.java b/src/main/java/sinalgo/io/xml/XMLParser.java index 772598fd9c0d5a72f2c4eda133c660758ac62e22..f1ee749d017f3a98ebc9718d4b5fedd2a228cd00 100644 --- a/src/main/java/sinalgo/io/xml/XMLParser.java +++ b/src/main/java/sinalgo/io/xml/XMLParser.java @@ -72,7 +72,7 @@ public class XMLParser { */ @Getter @Setter - private static boolean blockParse = false; + private static boolean blockParse; /** * This method parses the framework node of the xml configuration file. All diff --git a/src/main/java/sinalgo/nodes/InboxPacketBuffer.java b/src/main/java/sinalgo/nodes/InboxPacketBuffer.java index 5a1a9160a4be277e050e9693bce3040caa89826c..79479c5d7070c8ce1d1cbdcf9c12ff5e4468c61a 100644 --- a/src/main/java/sinalgo/nodes/InboxPacketBuffer.java +++ b/src/main/java/sinalgo/nodes/InboxPacketBuffer.java @@ -55,7 +55,7 @@ public class InboxPacketBuffer extends DoublyLinkedList<Packet> implements Packe private PacketCollection arrivingPackets = new PacketCollection(); private ReusableListIterator<Packet> bufferIterator = this.iterator(); - private Inbox inbox = null; + private Inbox inbox; /** * The default constructor of the dllPacketBuffer-class. diff --git a/src/main/java/sinalgo/nodes/Node.java b/src/main/java/sinalgo/nodes/Node.java index 269f278e9ffe9aea3bef2d3c4c3ea142a67052ed..1bab38aba15d5bef6b52952ab00686c3159070f7 100644 --- a/src/main/java/sinalgo/nodes/Node.java +++ b/src/main/java/sinalgo/nodes/Node.java @@ -47,10 +47,18 @@ import sinalgo.exception.SinalgoFatalException; import sinalgo.exception.WrongConfigurationException; import sinalgo.gui.transformation.PositionTransformation; import sinalgo.io.eps.EPSOutputPrintStream; -import sinalgo.models.*; +import sinalgo.models.ConnectivityModel; +import sinalgo.models.InterferenceModel; +import sinalgo.models.MobilityModel; +import sinalgo.models.Model; +import sinalgo.models.ReliabilityModel; import sinalgo.nodes.edges.Edge; -import sinalgo.nodes.messages.*; +import sinalgo.nodes.messages.Inbox; +import sinalgo.nodes.messages.Message; +import sinalgo.nodes.messages.NackBox; +import sinalgo.nodes.messages.Packet; import sinalgo.nodes.messages.Packet.PacketType; +import sinalgo.nodes.messages.PacketCollection; import sinalgo.nodes.timers.Timer; import sinalgo.runtime.GUIRuntime; import sinalgo.runtime.Global; @@ -251,7 +259,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { */ @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) - private Inbox inbox = null; + private Inbox inbox; /** * The nackBox that contains the packets that did not arrive in the previous @@ -268,7 +276,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { */ @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) - private NackBox nackBox = null; + private NackBox nackBox; /** * The ID of the node. The system requires two nodes not to have the same ID. @@ -672,7 +680,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { */ @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) - private static Polygon routePolygon = null; + private static Polygon routePolygon; /** * This method draws this node to the specified Graphics. Each node is @@ -1000,7 +1008,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { // A boolean indicating whether the neighborhood of this node has changed in // this round. - private boolean neighborhoodChanged = false; + private boolean neighborhoodChanged; // !!! NOTE: this is a static vector used by all nodes! // it gets cleared by every node at the begining of the step-method and thus can @@ -1021,7 +1029,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { /** * A counter to assign each node a unique ID, at the time when it is generated. */ - private static long idCounter = 0; + private static long idCounter; /** * <b>This member is framework internal and should not be used by the project @@ -1046,7 +1054,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { */ @Getter @Setter - private NodeCollectionInfoInterface nodeCollectionInfo = null; + private NodeCollectionInfoInterface nodeCollectionInfo; /** * <b>This member is framework internal and should not be used by the project @@ -1058,7 +1066,7 @@ public abstract class Node implements DoublyLinkedListEntry, Comparable<Node> { */ @Getter @Setter - private boolean holdInNodeCollection = false; + private boolean holdInNodeCollection; /** * A node-internal iterator over all outgoing edges of this node. diff --git a/src/main/java/sinalgo/nodes/TimerCollection.java b/src/main/java/sinalgo/nodes/TimerCollection.java index 5fb470a7de078ca6e4b3f7f84227991a610b77aa..d6836920a37173e3bdc788cf2a737166b11a0d3a 100644 --- a/src/main/java/sinalgo/nodes/TimerCollection.java +++ b/src/main/java/sinalgo/nodes/TimerCollection.java @@ -56,11 +56,11 @@ public class TimerCollection implements Iterable<Timer> { private Vector<Timer> timers = new Vector<>(0); // the instance of the reusable iterator - private ReusableIter iter = null; + private ReusableIter iter; // the number of modifications (addings in our case) that are done on this // collection. - private int modCount = 0; + private int modCount; /** * This method returns the number of timers in this collection. This doesn't diff --git a/src/main/java/sinalgo/nodes/edges/Edge.java b/src/main/java/sinalgo/nodes/edges/Edge.java index 92e99c848d9cdf2d7fb97d4160cf21200643ceeb..7d34a80ec18a363451d994676241f37d3cb2bbce 100644 --- a/src/main/java/sinalgo/nodes/edges/Edge.java +++ b/src/main/java/sinalgo/nodes/edges/Edge.java @@ -250,7 +250,7 @@ public class Edge implements DoublyLinkedListEntry { */ @Getter @Setter(AccessLevel.PRIVATE) - private long ID = 0; // The (unique) ID of this edge. + private long ID; // The (unique) ID of this edge. /** * A reference to the edge connecting the two end-nodes of this edge in the @@ -265,7 +265,7 @@ public class Edge implements DoublyLinkedListEntry { */ @Getter @Setter - private Edge oppositeEdge = null; + private Edge oppositeEdge; /** * <b>This member is framework internal and should not be used by the project @@ -278,7 +278,7 @@ public class Edge implements DoublyLinkedListEntry { */ @Getter @Setter - private int numberOfMessagesOnThisEdge = 0; + private int numberOfMessagesOnThisEdge; /** * Called by the framework whenever a message is sent over this edge. This edge @@ -314,7 +314,7 @@ public class Edge implements DoublyLinkedListEntry { */ @Getter @Setter - private boolean valid = false; + private boolean valid; /** * <b>This member is framework internal and should not be used by the project @@ -381,7 +381,7 @@ public class Edge implements DoublyLinkedListEntry { @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) - private static Constructor<?> constructor = null; + private static Constructor<?> constructor; @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) @@ -389,7 +389,7 @@ public class Edge implements DoublyLinkedListEntry { @Getter @Setter - private static long numEdgesOnTheFly = 0; + private static long numEdgesOnTheFly; /** * <b>This member is framework internal and should not be used by the project diff --git a/src/main/java/sinalgo/nodes/edges/EdgePool.java b/src/main/java/sinalgo/nodes/edges/EdgePool.java index 9786f7890bb1ed8a732536ce4b64b46473bdf7d9..49354b11074e8629acbc292055febde4a1b49f3f 100644 --- a/src/main/java/sinalgo/nodes/edges/EdgePool.java +++ b/src/main/java/sinalgo/nodes/edges/EdgePool.java @@ -48,7 +48,7 @@ import java.util.Stack; public class EdgePool { private static Hashtable<String, Stack<Edge>> stacks = new Hashtable<>(); - private static Stack<Edge> lastStack = null; + private static Stack<Edge> lastStack; private static String lastStackTypeName = ""; /** diff --git a/src/main/java/sinalgo/nodes/messages/Inbox.java b/src/main/java/sinalgo/nodes/messages/Inbox.java index 920137fc4aaee1ec7d1820a532f3028825d6e893..88175ce5ef8297481dde613fd4dcfaaf9265642b 100644 --- a/src/main/java/sinalgo/nodes/messages/Inbox.java +++ b/src/main/java/sinalgo/nodes/messages/Inbox.java @@ -304,9 +304,9 @@ public class Inbox implements ReusableIterator<Message>, Iterable<Message> { // ----------------------------------------------------------------------------------- private Iterator<Packet> packetIter; // The iterator over the packet list. - private Packet activePacket = null; // The actual packet to return the information for. + private Packet activePacket; // The actual packet to return the information for. private AbstractList<Packet> packetList; // the packet list - private Packet singlePacket = null; // if the inbox is initialized for a single packet, it is stored here. + private Packet singlePacket; // if the inbox is initialized for a single packet, it is stored here. /** * <b>This is a framework internal method. Project developers should not need to diff --git a/src/main/java/sinalgo/nodes/messages/Packet.java b/src/main/java/sinalgo/nodes/messages/Packet.java index 1c57b15b4d96cf443864afe5027366772adcc9a9..78f86348718c9002277bf0d3364c9da9f0824b51 100644 --- a/src/main/java/sinalgo/nodes/messages/Packet.java +++ b/src/main/java/sinalgo/nodes/messages/Packet.java @@ -149,7 +149,7 @@ public final class Packet implements DoublyLinkedListEntry, Comparable<Packet> { @Getter @Setter - private static int numPacketsOnTheFly = 0; // number of packets in the system, not yet freed + private static int numPacketsOnTheFly; // number of packets in the system, not yet freed /** * Constructor to create new Packet objects. If possible, this method returns a diff --git a/src/main/java/sinalgo/nodes/messages/PacketCollection.java b/src/main/java/sinalgo/nodes/messages/PacketCollection.java index 03e285b2f112bd9509e61015aabd2f0cd8ae3848..58c5275da441bdaac49ba5a3f7d63b93865755d2 100644 --- a/src/main/java/sinalgo/nodes/messages/PacketCollection.java +++ b/src/main/java/sinalgo/nodes/messages/PacketCollection.java @@ -61,7 +61,7 @@ public class PacketCollection extends SortableVector<Packet> { } // the instance of the iterator over the PacketCollection - private ReusableIter iter = null; + private ReusableIter iter; @Override public Iterator<Packet> iterator() { diff --git a/src/main/java/sinalgo/nodes/timers/Timer.java b/src/main/java/sinalgo/nodes/timers/Timer.java index 0ee4abadbdc1ef93129b89197aed493f18f3f091..ffd3fc27ee4133bb893f6c0f98bf4c3227150fd7 100644 --- a/src/main/java/sinalgo/nodes/timers/Timer.java +++ b/src/main/java/sinalgo/nodes/timers/Timer.java @@ -67,7 +67,7 @@ public abstract class Timer implements Comparable<Timer> { */ @Getter @Setter(AccessLevel.PRIVATE) - private Node targetNode = null; + private Node targetNode; /** * The time this timer goes off. @@ -76,7 +76,7 @@ public abstract class Timer implements Comparable<Timer> { */ @Getter @Setter(AccessLevel.PRIVATE) - private double fireTime = 0; // The time when this timer fires. + private double fireTime; // The time when this timer fires. /** * Starts this <b>global timer</b> to go off after the indicated time, where the diff --git a/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java b/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java index 56e6a2ad98aab527c15c9125b771894b8b1a7a36..c514e85b207e708574a6b6a6f927ec8c16112fb6 100644 --- a/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java +++ b/src/main/java/sinalgo/runtime/AsynchronousRuntimeThread.java @@ -58,26 +58,26 @@ public class AsynchronousRuntimeThread extends Thread { */ @Getter @Setter - private long numberOfEvents = 0; + private long numberOfEvents; /** * Indicates whether the connectivity is initialized or not. In Asynchronous * mode the connectivity is generated once at startup and then it does not * change anymore. */ - private static boolean connectivityInitialized = false; + private static boolean connectivityInitialized; /** * The number events the gui will be redrawn after. */ @Getter @Setter - private long refreshRate = 0; + private long refreshRate; @Getter(AccessLevel.PRIVATE) private GUIRuntime runtime; - private static Node lastEventNode = null; + private static Node lastEventNode; /** * The Condtructor for the AsynchronousRuntimeThread creating an instancs with a diff --git a/src/main/java/sinalgo/runtime/Global.java b/src/main/java/sinalgo/runtime/Global.java index befc1a9e989781f44ab16e00ed1175192916f3c4..ae39368fc750cfd408283e1b7997d94f6807ae62 100644 --- a/src/main/java/sinalgo/runtime/Global.java +++ b/src/main/java/sinalgo/runtime/Global.java @@ -48,7 +48,13 @@ import sinalgo.runtime.AbstractCustomGlobal.GlobalMethod; import sinalgo.tools.Tools; import sinalgo.tools.logging.Logging; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.regex.Matcher; @@ -88,7 +94,7 @@ public class Global { */ @Getter @Setter - private static boolean isRunning = false; + private static boolean isRunning; /** * This is the date of the last start of a simulation. This means this is the @@ -97,7 +103,7 @@ public class Global { */ @Getter @Setter - private static Date startTime = null; + private static Date startTime; /** * This is the date of the start of the last round started. Only really @@ -105,7 +111,7 @@ public class Global { */ @Getter @Setter - private static Date startTimeOfRound = null; + private static Date startTimeOfRound; /** * The default log file generated for each run. You may add your own log output, @@ -117,7 +123,7 @@ public class Global { */ @Getter @Setter - private static Logging log = null; // only install after logging has been activated. + private static Logging log; // only install after logging has been activated. /* * Some Information about the global state of the simulation. You can add other @@ -129,14 +135,14 @@ public class Global { */ @Getter @Setter - private static int numberOfMessagesInThisRound = 0; + private static int numberOfMessagesInThisRound; /** * Global information about the number of messages sent in all previous rounds. */ @Getter @Setter - private static int numberOfMessagesOverAll = 0; + private static int numberOfMessagesOverAll; /** * The current time of the simulation. @@ -147,7 +153,7 @@ public class Global { */ @Getter @Setter - private static double currentTime = 0; + private static double currentTime; /** * A boolean whose value changes in every round s.t. in every second round, this @@ -166,7 +172,7 @@ public class Global { */ @Getter @Setter - private static MessageTransmissionModel messageTransmissionModel = null; + private static MessageTransmissionModel messageTransmissionModel; /** * This is the instance of the custom global class. It is initialized by default @@ -183,7 +189,7 @@ public class Global { */ @Getter @Setter - private static boolean useProject = false; + private static boolean useProject; /** * The name of the actual Project. It is specified by the command line. @@ -298,7 +304,7 @@ public class Global { */ @Getter @Setter - private static boolean isGuiMode = false; + private static boolean isGuiMode; /** * True if runing in asynchronousMode, false otherwise. diff --git a/src/main/java/sinalgo/runtime/SinalgoRuntime.java b/src/main/java/sinalgo/runtime/SinalgoRuntime.java index 815bc0e6ec92e513701cfaefec3264c7d01a3245..2fcf7171330999656accb3e530b175c0eb9a5946 100644 --- a/src/main/java/sinalgo/runtime/SinalgoRuntime.java +++ b/src/main/java/sinalgo/runtime/SinalgoRuntime.java @@ -104,7 +104,7 @@ public abstract class SinalgoRuntime { */ @Getter @Setter - private static Map map = null; + private static Map map; // some information on the rounds @@ -115,7 +115,7 @@ public abstract class SinalgoRuntime { */ @Getter @Setter(AccessLevel.PRIVATE) - private int numberOfRounds = 0; + private int numberOfRounds; /** * true if a running simulation should be stopped at the e @@ -124,7 +124,7 @@ public abstract class SinalgoRuntime { */ @Getter @Setter(AccessLevel.PACKAGE) - private boolean abort = false; + private boolean abort; // these are local variables to ensure the 'communication' between the parsing // -gen parameters (where these variables are written diff --git a/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java b/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java index 818681a80b57ea5e69b8c4adcdbafffa10fc5824..4200a5442f3ae7a08d65a220247cde5676a886cb 100644 --- a/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java +++ b/src/main/java/sinalgo/runtime/SynchronousRuntimeThread.java @@ -56,7 +56,7 @@ public class SynchronousRuntimeThread extends Thread { */ @Getter @Setter - private long numberOfRounds = 0; + private long numberOfRounds; @Getter(AccessLevel.PRIVATE) private GUIRuntime runtime; // If in GUI-MODE, this member holds the the GUIRuntime diff --git a/src/main/java/sinalgo/runtime/events/EventQueue.java b/src/main/java/sinalgo/runtime/events/EventQueue.java index 022dc6437fc73fe1e77e21d61655ee948c5233b2..c42485ba74c688a10fd5cbcf774ba5c710445b43 100644 --- a/src/main/java/sinalgo/runtime/events/EventQueue.java +++ b/src/main/java/sinalgo/runtime/events/EventQueue.java @@ -43,7 +43,11 @@ import sinalgo.nodes.Node; import sinalgo.nodes.edges.Edge; import sinalgo.runtime.SinalgoRuntime; -import java.util.*; +import java.util.Comparator; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.TreeSet; +import java.util.Vector; /** * The queue that stores the events of the asynchronous mode. The entries @@ -64,7 +68,7 @@ public class EventQueue extends TreeSet<Event> { */ @Getter @Setter - private static long eventNumber = 0; + private static long eventNumber; /** * The constructor for the EventQueue. Constructs a TreeSet with the correct diff --git a/src/main/java/sinalgo/runtime/events/PacketEvent.java b/src/main/java/sinalgo/runtime/events/PacketEvent.java index 29593c98e15d1b991356aeedc249af217377051e..1de7297826d2fa6a36adf8d883c77c9af73f9cff 100644 --- a/src/main/java/sinalgo/runtime/events/PacketEvent.java +++ b/src/main/java/sinalgo/runtime/events/PacketEvent.java @@ -62,7 +62,7 @@ public class PacketEvent extends Event { @Getter @Setter - private static int numPacketEventsOnTheFly = 0; + private static int numPacketEventsOnTheFly; public static int getNumFreedPacketEvents() { return unusedPacketEvents.size(); diff --git a/src/main/java/sinalgo/runtime/events/TimerEvent.java b/src/main/java/sinalgo/runtime/events/TimerEvent.java index a2ea1d8fa0bcfebf64717bd7d22fcd6d202836a2..8d076659e0c411d44f2455d64faa08408cf0517b 100644 --- a/src/main/java/sinalgo/runtime/events/TimerEvent.java +++ b/src/main/java/sinalgo/runtime/events/TimerEvent.java @@ -55,7 +55,7 @@ public class TimerEvent extends Event { @Getter @Setter - private static int numTimerEventsOnTheFly = 0; + private static int numTimerEventsOnTheFly; public static int getNumFreedTimerEvents() { return unusedTimerEvents.size(); diff --git a/src/main/java/sinalgo/runtime/nodeCollection/Geometric2DNodeCollection.java b/src/main/java/sinalgo/runtime/nodeCollection/Geometric2DNodeCollection.java index bb6225de98c257216a7d78edab4d7916e322bfc9..147155762cf69370a0393e9132551f6d2888071a 100644 --- a/src/main/java/sinalgo/runtime/nodeCollection/Geometric2DNodeCollection.java +++ b/src/main/java/sinalgo/runtime/nodeCollection/Geometric2DNodeCollection.java @@ -94,7 +94,7 @@ public class Geometric2DNodeCollection extends AbstractNodeCollection { // The instance of the GeometricNodeEnumeration. This is the instance that is // either created or reset by the // getPossibleNeighborsEnumeration method. - private GeometricNodeEnumeration geometricNodeEnumeration = null; + private GeometricNodeEnumeration geometricNodeEnumeration; /** * The constructor for the GeometricNodeCollection class. @@ -192,8 +192,8 @@ public class Geometric2DNodeCollection extends AbstractNodeCollection { class GeometricNodeEnumeration implements Enumeration<Node> { - private GeometricNodeListEnumeration sNLE = null; - private Iterator<Node> nI = null; + private GeometricNodeListEnumeration sNLE; + private Iterator<Node> nI; /** * The constructor for the GeometricNodeEnumeration class. This Enumeration is diff --git a/src/main/java/sinalgo/runtime/nodeCollection/Geometric3DNodeCollection.java b/src/main/java/sinalgo/runtime/nodeCollection/Geometric3DNodeCollection.java index ca1ac0fe2ff74ee00b9b94894b8461ae41c88ec0..657a586c9727a4d4a793e7383494d259eb446b97 100644 --- a/src/main/java/sinalgo/runtime/nodeCollection/Geometric3DNodeCollection.java +++ b/src/main/java/sinalgo/runtime/nodeCollection/Geometric3DNodeCollection.java @@ -45,7 +45,11 @@ import sinalgo.nodes.Node; import sinalgo.nodes.Position; import sinalgo.runtime.Main; -import java.util.*; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Vector; /** * This 3D node collection implementation stores nodes placed in a 3 dimensional @@ -65,11 +69,11 @@ public class Geometric3DNodeCollection extends AbstractNodeCollection { // a flat list for fast iteration over all nodes private Vector<Node> flatList = new Vector<>(); - private boolean flatListChanged = false; + private boolean flatListChanged; private Node[] sortedNodeArray = new Node[1]; - private int sortedNodeArraySize = 0; // Number of non-null nodes in sortedNodeArray - private DepthComparator myDepthComparator = null; + private int sortedNodeArraySize; // Number of non-null nodes in sortedNodeArray + private DepthComparator myDepthComparator; // the maximal distance between any two connected nodes private double rMax; @@ -122,7 +126,7 @@ public class Geometric3DNodeCollection extends AbstractNodeCollection { return (int) Math.floor(c / this.rMax); } - private long lastVersionNumber = 0; + private long lastVersionNumber; @Override public Enumeration<Node> getSortedNodeEnumeration(boolean backToFront) { @@ -286,7 +290,7 @@ public class Geometric3DNodeCollection extends AbstractNodeCollection { class Geometric3DNodeEnumeration implements Enumeration<Node> { int ox, oy, oz; // base position for the 3-dimensional iteration - int dx = 0, dy = 0, dz = -1; // the offset from the base position + int dx, dy, dz = -1; // the offset from the base position Iterator<Node> iterator; /** @@ -368,7 +372,7 @@ public class Geometric3DNodeCollection extends AbstractNodeCollection { this.backToFront = backToFront; } - int currentIndex = 0; + int currentIndex; @Override public boolean hasMoreElements() { @@ -392,8 +396,8 @@ public class Geometric3DNodeCollection extends AbstractNodeCollection { */ private class DepthComparator implements Comparator<Node> { - PositionTransformation pt = null; - Transformation3D t3d = null; + PositionTransformation pt; + Transformation3D t3d; /** * Creates a new DepthComparator instance. Note that the DepthComparator only diff --git a/src/main/java/sinalgo/runtime/nodeCollection/SquarePositionCollection.java b/src/main/java/sinalgo/runtime/nodeCollection/SquarePositionCollection.java index 037d9491e3e140563d47b4c1741cf39d59ca2e75..2f1f7fcec4a69f0452daaf548d87b4c7af73bf7e 100644 --- a/src/main/java/sinalgo/runtime/nodeCollection/SquarePositionCollection.java +++ b/src/main/java/sinalgo/runtime/nodeCollection/SquarePositionCollection.java @@ -46,7 +46,7 @@ import java.util.Enumeration; */ public class SquarePositionCollection { - private SquarePositionCollectionEnumeration enumeration = null; + private SquarePositionCollectionEnumeration enumeration; /** * The storage for the SquarePos. This storage is an array and always has the @@ -54,7 +54,7 @@ public class SquarePositionCollection { */ private SquarePos[] squares = new SquarePos[9]; private boolean[] used = new boolean[9]; - private int nextUnused = 0; + private int nextUnused; /** * The only constructor for the SquarePositionCollection. It fills the data @@ -112,7 +112,7 @@ public class SquarePositionCollection { private class SquarePositionCollectionEnumeration implements ReusableEnumeration<SquarePos> { - private int position = 0; + private int position; @Override public void reset() { diff --git a/src/main/java/sinalgo/tools/logging/Logging.java b/src/main/java/sinalgo/tools/logging/Logging.java index 4eefab8510a2d408f855f29d32c244d4976e1748..77812d71ee8fc2c6378223b21d504ddc95f23994 100644 --- a/src/main/java/sinalgo/tools/logging/Logging.java +++ b/src/main/java/sinalgo/tools/logging/Logging.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.logging; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoFatalException; import sinalgo.io.IOUtils; @@ -181,10 +184,10 @@ public class Logging { * @return The logging instance */ public static Logging getLogger() { - if (instance == null) { + if (getInstance() == null) { if (activated) { if (Configuration.isOutputToConsole()) { - instance = new Logging(System.out); + setInstance(new Logging(System.out)); } else { return getLogger(Configuration.getLogFileName()); } @@ -194,7 +197,7 @@ public class Logging { + "before parsing of the -overwrite parameters."); } } - return instance; + return getInstance(); } /** @@ -256,11 +259,11 @@ public class Logging { */ public static Logging getLogger(String logFileName, boolean append) { if (activated) { - if (loggers.containsKey(logFileName)) { - return loggers.get(logFileName); + if (getLoggers().containsKey(logFileName)) { + return getLoggers().get(logFileName); } else { Logging l = new Logging(logFileName, append); - loggers.put(logFileName, l); + getLoggers().put(logFileName, l); return l; } } else { @@ -278,9 +281,9 @@ public class Logging { */ public void log(boolean logFlag, String txt) { if (logFlag) { - this.out.print(txt); + this.getOut().print(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } } @@ -291,9 +294,9 @@ public class Logging { * @param txt The text to log. */ public void log(String txt) { - this.out.print(txt); + this.getOut().print(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } @@ -305,9 +308,9 @@ public class Logging { */ public void logln(boolean logFlag, String txt) { if (logFlag) { - this.out.println(txt); + this.getOut().println(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } } @@ -318,9 +321,9 @@ public class Logging { * @param txt The log message to be printed. */ public void logln(String txt) { - this.out.println(txt); + this.getOut().println(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } @@ -328,9 +331,9 @@ public class Logging { * Adds a line-break to the log-file. */ public void logln() { - this.out.println(); + this.getOut().println(); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } @@ -341,11 +344,11 @@ public class Logging { * @param txt The log message to be printed. */ public void logPos(String txt) { - this.out.print(getCodePosition(1)); - this.out.print(" "); - this.out.print(txt); + this.getOut().print(getCodePosition(1)); + this.getOut().print(" "); + this.getOut().print(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } @@ -358,11 +361,11 @@ public class Logging { */ public void logPos(boolean logFlag, String txt) { if (logFlag) { - this.out.print(getCodePosition(1)); - this.out.print(" "); - this.out.print(txt); + this.getOut().print(getCodePosition(1)); + this.getOut().print(" "); + this.getOut().print(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } } @@ -374,11 +377,11 @@ public class Logging { * @param txt The log message to be printed. */ public void logPosln(String txt) { - this.out.print(getCodePosition(1)); - this.out.print(" "); - this.out.println(txt); + this.getOut().print(getCodePosition(1)); + this.getOut().print(" "); + this.getOut().println(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } @@ -391,11 +394,11 @@ public class Logging { */ public void logPosln(boolean logFlag, String txt) { if (logFlag) { - this.out.print(getCodePosition(1)); - this.out.print(" "); - this.out.println(txt); + this.getOut().print(getCodePosition(1)); + this.getOut().print(" "); + this.getOut().println(txt); if (Configuration.isEagerFlush()) { - this.out.flush(); + this.getOut().flush(); } } } @@ -406,15 +409,7 @@ public class Logging { * @return The print stream where this logger logs to. */ public PrintStream getOutputStream() { - return this.out; - } - - /** - * @return The time-prefix used for the directories when logToTimeDirectory in - * the config file is enabled. - */ - public static String getTimePrefix() { - return timePrefix; + return this.getOut(); } public static String getTimeDirectoryName() { @@ -477,6 +472,7 @@ public class Logging { return df.format(new Date()); } + // ----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------- // Framework specific methods and member variables @@ -484,18 +480,43 @@ public class Logging { // methods // ----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------- + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static Logging instance; - private static Logging instance = null; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static HashMap<String, Logging> loggers = new HashMap<>(); + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private PrintStream out; - private static String timePrefix; // the time when the simulation started - can be prefixed to the log-files to - // distringish different rounds. - // a boolean, indicating whether the logging mechanism is already activated. - // This means that the -overwrite - // parameters are already processed. (@see runtime.Main#parseOverwriteParameters - // for details) - private static boolean activated = false; + /** + * The time when the simulation started - can be prefixed to the log-files to + * distringish different rounds. + * + * @return The time-prefix used for the directories when logToTimeDirectory in + * the config file is enabled. + */ + @Getter + @Setter(AccessLevel.PRIVATE) + private static String timePrefix; + + // + /** + * <b>This member is framework internal and should not be used by the project + * developer.</b> Tests whether the framework has been configured to an extend + * that logging may be used. Before this method returns true, logging must not + * be used. Indicates whether the logging mechanism is already activated. + * This means that the -overwrite parameters are already processed. + * (@see runtime.Main#parseOverwriteParameters for details) + * + * @return Whether the logging has been activated - and therefore may be used. + */ + @Getter + @Setter(AccessLevel.PRIVATE) + private static boolean activated; /** * <b>This member is framework internal and should not be used by the project @@ -526,9 +547,9 @@ public class Logging { } if (append) { - this.out = new PrintStream(new FileOutputStream(dir + aFileName, true)); + this.setOut(new PrintStream(new FileOutputStream(dir + aFileName, true))); } else { - this.out = new PrintStream(dir + aFileName); + this.setOut(new PrintStream(dir + aFileName)); } } catch (FileNotFoundException e) { throw new SinalgoFatalException("Could not open the logfile " + aFileName); @@ -542,7 +563,7 @@ public class Logging { * @param aStream The stream this logger should print to. */ private Logging(PrintStream aStream) { - this.out = aStream; + this.setOut(aStream); } /** @@ -555,21 +576,10 @@ public class Logging { public static void activate() { if (timePrefix == null) { SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy_HH.mm.ss.SSS"); - timePrefix = df.format(new Date()); + setTimePrefix(df.format(new Date())); } - activated = true; + setActivated(true); Global.setLog(Logging.getLogger()); // the default logger } - /** - * <b>This member is framework internal and should not be used by the project - * developer.</b> Tests whether the framework has been configured to an extend - * that logging may be used. Before this method returns true, logging must not - * be used. - * - * @return Whether the logging has been activated - and therefore may be used. - */ - public static boolean isActivated() { - return activated; - } } diff --git a/src/main/java/sinalgo/tools/statistics/ConstantDistribution.java b/src/main/java/sinalgo/tools/statistics/ConstantDistribution.java index ca81f7d3aa8a0166d47dfdce549ab66c38a6540b..724d222a1bd50b331d06eadf323ffb698c6509a0 100644 --- a/src/main/java/sinalgo/tools/statistics/ConstantDistribution.java +++ b/src/main/java/sinalgo/tools/statistics/ConstantDistribution.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.statistics; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -52,6 +55,8 @@ import sinalgo.exception.CorruptConfigurationEntryException; */ public class ConstantDistribution extends Distribution { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private double value; // the value of this distribution /** @@ -60,7 +65,7 @@ public class ConstantDistribution extends Distribution { * @param value The value to be returned by this distribution. */ public ConstantDistribution(double value) { - this.value = value; + this.setValue(value); } /** @@ -72,11 +77,12 @@ public class ConstantDistribution extends Distribution { * @throws CorruptConfigurationEntryException If the configuration file is corrupt. */ public ConstantDistribution(String mainTagPath) throws CorruptConfigurationEntryException { - this.value = Configuration.getDoubleParameter(mainTagPath + "/constant"); + this.setValue(Configuration.getDoubleParameter(mainTagPath + "/constant")); } @Override public double nextSample() { - return this.value; + return this.getValue(); } + } diff --git a/src/main/java/sinalgo/tools/statistics/DataSeries.java b/src/main/java/sinalgo/tools/statistics/DataSeries.java index b835a178608da126589cb09f0f8d207c6f43ae71..52cd66d3fabced3866b8ef6ab71e03a705de8982 100644 --- a/src/main/java/sinalgo/tools/statistics/DataSeries.java +++ b/src/main/java/sinalgo/tools/statistics/DataSeries.java @@ -64,16 +64,16 @@ public class DataSeries implements Externalizable { * * @return The sum of all samples added to this data series. */ - private double sum = 0; // The sum of all samples + private double sum; // The sum of all samples - private double squaredSum = 0; // the sum of the square of all samples + private double squaredSum; // the sum of the square of all samples /** * The number of samples added to this data series. * * @return the number of samples added to this data series. */ - private int numberOfSamples = 0; + private int numberOfSamples; @Getter(AccessLevel.PRIVATE) private double min = Double.MAX_VALUE, max = Double.MIN_VALUE; // the min. and max. values added diff --git a/src/main/java/sinalgo/tools/statistics/Distribution.java b/src/main/java/sinalgo/tools/statistics/Distribution.java index c4ca28bdc04ce6455fe726fe302d9d0e7bf6afc6..bbf6fa6cd5d5abf1c5a5a25366d8e786cd28d499 100644 --- a/src/main/java/sinalgo/tools/statistics/Distribution.java +++ b/src/main/java/sinalgo/tools/statistics/Distribution.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.statistics; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -66,8 +69,13 @@ import java.util.Random; */ public abstract class Distribution { - protected static Random randomGenerator; // the singleton instance of the random object. Be sure to initialize + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private static Random randomGenerator; // the singleton instance of the random object. Be sure to initialize // before using the first time! + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static long randomSeed; // the seed used for the random object /** @@ -77,7 +85,7 @@ public abstract class Distribution { */ public static long getSeed() { getRandom(); // initialize the random generator if it's not already done - return randomSeed; + return getRandomSeed(); } /** @@ -98,20 +106,20 @@ public abstract class Distribution { */ public static Random getRandom() { // construct the singleton random object if it does not yet exist - if (randomGenerator == null) { + if (getRandomGenerator() == null) { if (Configuration.isUseSameSeedAsInPreviousRun()) { - randomSeed = AppConfig.getAppConfig().getSeedFromLastRun(); + setRandomSeed(AppConfig.getAppConfig().getSeedFromLastRun()); } else { if (Configuration.isUseFixedSeed()) { - randomSeed = Configuration.getFixedSeed(); + setRandomSeed(Configuration.getFixedSeed()); } else { - randomSeed = (new java.util.Random()).nextLong(); - Configuration.setFixedSeed(randomSeed); + setRandomSeed((new Random()).nextLong()); + Configuration.setFixedSeed(getRandomSeed()); } } - randomGenerator = new Random(randomSeed); // use a random seed + setRandomGenerator(new Random(getRandomSeed())); // use a random seed } - return randomGenerator; + return getRandomGenerator(); } /** diff --git a/src/main/java/sinalgo/tools/statistics/ExponentialDistribution.java b/src/main/java/sinalgo/tools/statistics/ExponentialDistribution.java index a7acf9751cb40bfeb5c9ed9d011ab80a99761eef..ae11a9c77c7aaf1add18a70fbdb9fe29acff145f 100644 --- a/src/main/java/sinalgo/tools/statistics/ExponentialDistribution.java +++ b/src/main/java/sinalgo/tools/statistics/ExponentialDistribution.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.statistics; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -55,6 +58,8 @@ import java.util.Random; */ public class ExponentialDistribution extends Distribution { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private double lambda; /** @@ -65,7 +70,7 @@ public class ExponentialDistribution extends Distribution { * 1/lambda. */ public ExponentialDistribution(double lambda) { - this.lambda = lambda; + this.setLambda(lambda); } /** @@ -77,12 +82,12 @@ public class ExponentialDistribution extends Distribution { * @throws CorruptConfigurationEntryException If the configuration file is corrupt. */ public ExponentialDistribution(String mainTagPath) throws CorruptConfigurationEntryException { - this.lambda = Configuration.getDoubleParameter(mainTagPath + "/lambda"); + this.setLambda(Configuration.getDoubleParameter(mainTagPath + "/lambda")); } @Override public double nextSample() { - return -Math.log(randomGenerator.nextDouble()) / this.lambda; + return -Math.log(getRandomGenerator().nextDouble()) / this.getLambda(); } /** @@ -106,4 +111,5 @@ public class ExponentialDistribution extends Distribution { Random r = Distribution.getRandom(); return -Math.log(r.nextDouble()) / lambda; } + } diff --git a/src/main/java/sinalgo/tools/statistics/GaussianDistribution.java b/src/main/java/sinalgo/tools/statistics/GaussianDistribution.java index d5340f3ef6cfae8e3d6f769c083f557c9ed4d446..6fa9652c7de65447cb4a4d7d86cd1b92d48cb9a8 100644 --- a/src/main/java/sinalgo/tools/statistics/GaussianDistribution.java +++ b/src/main/java/sinalgo/tools/statistics/GaussianDistribution.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.statistics; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -52,6 +55,8 @@ import java.util.Random; * <p> * is expected. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class GaussianDistribution extends Distribution { private double mean; // the mean of the distribution @@ -64,8 +69,8 @@ public class GaussianDistribution extends Distribution { * @param var The variance of the distribution. */ public GaussianDistribution(double mean, double var) { - this.mean = mean; - this.var = var; + this.setMean(mean); + this.setVar(var); } /** @@ -77,13 +82,13 @@ public class GaussianDistribution extends Distribution { * @throws CorruptConfigurationEntryException If the configuration file is corrupt. */ public GaussianDistribution(String mainTagPath) throws CorruptConfigurationEntryException { - this.mean = Configuration.getDoubleParameter(mainTagPath + "/mean"); - this.var = Configuration.getDoubleParameter(mainTagPath + "/variance"); + this.setMean(Configuration.getDoubleParameter(mainTagPath + "/mean")); + this.setVar(Configuration.getDoubleParameter(mainTagPath + "/variance")); } @Override public double nextSample() { - return this.mean + randomGenerator.nextGaussian() * Math.sqrt(this.var); + return this.getMean() + getRandomGenerator().nextGaussian() * Math.sqrt(this.getVar()); } /** @@ -99,4 +104,5 @@ public class GaussianDistribution extends Distribution { Random r = Distribution.getRandom(); return mean + r.nextGaussian() * Math.sqrt(variance); } + } diff --git a/src/main/java/sinalgo/tools/statistics/PoissonDistribution.java b/src/main/java/sinalgo/tools/statistics/PoissonDistribution.java index 710c0d17262daa62e637fbe5a50f970b3f3797cf..7a35e8ae1951b2c0442769d5cd9e8f7f7ab23015 100644 --- a/src/main/java/sinalgo/tools/statistics/PoissonDistribution.java +++ b/src/main/java/sinalgo/tools/statistics/PoissonDistribution.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.statistics; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -55,6 +58,8 @@ import java.util.Random; */ public class PoissonDistribution extends Distribution { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private double expLambda; // e^-lambda /** @@ -63,7 +68,7 @@ public class PoissonDistribution extends Distribution { * @param lambda The mean (and also variance) of the distribution. */ public PoissonDistribution(double lambda) { - this.expLambda = Math.exp(-lambda); + this.setExpLambda(Math.exp(-lambda)); } /** @@ -76,7 +81,7 @@ public class PoissonDistribution extends Distribution { */ public PoissonDistribution(String mainTagPath) throws CorruptConfigurationEntryException { double lambda = Configuration.getDoubleParameter(mainTagPath + "/lambda"); - this.expLambda = Math.exp(-lambda); + this.setExpLambda(Math.exp(-lambda)); } @Override @@ -84,8 +89,8 @@ public class PoissonDistribution extends Distribution { double product = 1; int count = 0; int result = 0; - while (product >= this.expLambda) { - product *= randomGenerator.nextDouble(); + while (product >= this.getExpLambda()) { + product *= getRandomGenerator().nextDouble(); result = count; count++; // keep result one behind } @@ -116,4 +121,5 @@ public class PoissonDistribution extends Distribution { } return result; } + } diff --git a/src/main/java/sinalgo/tools/statistics/UniformDistribution.java b/src/main/java/sinalgo/tools/statistics/UniformDistribution.java index fb553e583f924433578f38158caa24012abb2e55..393d2ea8d87f333d89db6f76e08a9f0d605ae4ec 100644 --- a/src/main/java/sinalgo/tools/statistics/UniformDistribution.java +++ b/src/main/java/sinalgo/tools/statistics/UniformDistribution.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.statistics; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.CorruptConfigurationEntryException; @@ -53,6 +56,8 @@ import java.util.Random; * <p> * is expected. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class UniformDistribution extends Distribution { private double min; // the min value of the range to choose a value from @@ -67,9 +72,9 @@ public class UniformDistribution extends Distribution { * @throws NumberFormatException If min > max. */ public UniformDistribution(double min, double max) throws NumberFormatException { - this.min = min; - this.range = max - min; - if (this.range < 0) { + this.setMin(min); + this.setRange(max - min); + if (this.getRange() < 0) { throw new NumberFormatException( "Invalid arguments to create a uniform distribution. The upper bound of the range must be at least as big as the lower bound."); } @@ -84,9 +89,9 @@ public class UniformDistribution extends Distribution { * @throws CorruptConfigurationEntryException If the configuration file is corrupt. */ public UniformDistribution(String mainTagPath) throws CorruptConfigurationEntryException { - this.min = Configuration.getDoubleParameter(mainTagPath + "/min"); - this.range = Configuration.getDoubleParameter(mainTagPath + "/max") - this.min; - if (this.range < 0) { + this.setMin(Configuration.getDoubleParameter(mainTagPath + "/min")); + this.setRange(Configuration.getDoubleParameter(mainTagPath + "/max") - this.getMin()); + if (this.getRange() < 0) { throw new CorruptConfigurationEntryException( "Invalid arguments to create a uniform distribution. The upper bound of the range must be at least as big as the lower bound."); } @@ -94,7 +99,7 @@ public class UniformDistribution extends Distribution { @Override public double nextSample() { - return this.min + this.range * randomGenerator.nextDouble(); + return this.getMin() + this.getRange() * getRandomGenerator().nextDouble(); } /** diff --git a/src/main/java/sinalgo/tools/storage/DoublyLinkedList.java b/src/main/java/sinalgo/tools/storage/DoublyLinkedList.java index b4f6fbd99d1f9c9c98e971cca6f75c1ad2e5e951..ef733f5e71247fcd54f3baf01e89f75bb4da6b39 100644 --- a/src/main/java/sinalgo/tools/storage/DoublyLinkedList.java +++ b/src/main/java/sinalgo/tools/storage/DoublyLinkedList.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.storage; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.exception.DoublyLinkedListErrorException; import sinalgo.tools.logging.Logging; @@ -80,16 +83,18 @@ import java.util.NoSuchElementException; * * @param <E> The generic type the DLL is created for. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterable<E> { private boolean keepFinger; // if true, the finger is not removed from the objects list after the object is // removed from this list. - private int size = 0; // # of elements in the list - private int modCount = 0; // # of modifications + private int size; // # of elements in the list + private int modCount; // # of modifications private DoublyLinkedListEntry.Finger head = new DoublyLinkedListEntry.Finger(null, null); // before the first entry // of the list, the // terminator - private DoublyLinkedListEntry.Finger tail = this.head; // the last entry, points to head if the list is empty + private DoublyLinkedListEntry.Finger tail = this.getHead(); // the last entry, points to head if the list is empty /** * Creates a new instance of a Doubly Linked List. @@ -106,7 +111,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * set to false, the finger is removed. */ public DoublyLinkedList(boolean keepFinger) { - this.keepFinger = keepFinger; + this.setKeepFinger(keepFinger); } /** @@ -115,7 +120,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * <code>iterator()</code>. */ public DoublyLinkedList() { - this.keepFinger = false; + this.setKeepFinger(false); } /** @@ -129,7 +134,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * list. */ public boolean append(E entry) { - return this.addAfter(entry, this.tail); + return this.addAfter(entry, this.getTail()); } /** @@ -164,18 +169,18 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab return false; // already in list } f = entry.getDoublyLinkedListFinger().getNewFinger(this, entry); // get new finger - if (pos == this.tail) { // insert at the end - f.setPrevious(this.tail); - this.tail.setNext(f); - this.tail = f; + if (pos == this.getTail()) { // insert at the end + f.setPrevious(this.getTail()); + this.getTail().setNext(f); + this.setTail(f); } else { // insert not after last entry f.setNext(pos.getNext()); f.setPrevious(pos); pos.getNext().setPrevious(f); // must exist, as pos != tail pos.setNext(f); } - this.size++; - this.modCount++; + this.setSize(this.getSize() + 1); + this.setModCount(this.getModCount() + 1); return true; } @@ -203,24 +208,24 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab return false; // already in list } f = entry.getDoublyLinkedListFinger().getNewFinger(this, entry); // get new finger - if (pos == this.head) { // insert in front (actually, we don't insert BEFORE the head, but after the + if (pos == this.getHead()) { // insert in front (actually, we don't insert BEFORE the head, but after the // head) - f.setNext(this.head.getNext()); - f.setPrevious(this.head); - if (this.head != this.tail) { // not empty list - this.head.getNext().setPrevious(f); + f.setNext(this.getHead().getNext()); + f.setPrevious(this.getHead()); + if (this.getHead() != this.getTail()) { // not empty list + this.getHead().getNext().setPrevious(f); } else { - this.tail = f; + this.setTail(f); } - this.head.setNext(f); + this.getHead().setNext(f); } else { // insert not before first entry f.setNext(pos); f.setPrevious(pos.getPrevious()); pos.getPrevious().setNext(f); pos.setPrevious(f); } - this.size++; - this.modCount++; + this.setSize(this.getSize() + 1); + this.setModCount(this.getModCount() + 1); return true; } @@ -257,18 +262,18 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab return false; // not in list and no finger } if (f.getNext() == null && f.getPrevious() == null) { - f.getObject().getDoublyLinkedListFinger().releaseFinger(f, this.keepFinger); + f.getObject().getDoublyLinkedListFinger().releaseFinger(f, this.isKeepFinger()); return false; // not in list, but had a dummy finger. } f.getPrevious().setNext(f.getNext()); // there's always a previous if (f.getNext() != null) { f.getNext().setPrevious(f.getPrevious()); } else { // was last entry - this.tail = f.getPrevious(); + this.setTail(f.getPrevious()); } - f.getObject().getDoublyLinkedListFinger().releaseFinger(f, this.keepFinger); - this.size--; - this.modCount++; + f.getObject().getDoublyLinkedListFinger().releaseFinger(f, this.isKeepFinger()); + this.setSize(this.getSize() - 1); + this.setModCount(this.getModCount() + 1); return true; } @@ -280,9 +285,9 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab */ @SuppressWarnings("unchecked") public E pop() { - if (this.head.getNext() != null) { - DoublyLinkedListEntry e = this.head.getNext().getObject(); - this.remove(this.head.getNext()); + if (this.getHead().getNext() != null) { + DoublyLinkedListEntry e = this.getHead().getNext().getObject(); + this.remove(this.getHead().getNext()); return (E) e; } return null; @@ -295,8 +300,8 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab */ @SuppressWarnings("unchecked") public E peek() { - if (this.head.getNext() != null) { - return (E) this.head.getNext().getObject(); + if (this.getHead().getNext() != null) { + return (E) this.getHead().getNext().getObject(); } return null; } @@ -309,7 +314,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * already contained in the list. */ public boolean push(E entry) { - return this.addBefore(entry, this.head); // note that this does not insert the element BEFORE the special entry 'head', + return this.addBefore(entry, this.getHead()); // note that this does not insert the element BEFORE the special entry 'head', // but after head as first elelemtn of the list. } @@ -317,7 +322,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * @return The number of entries in this list. */ public int size() { - return this.size; + return this.getSize(); } /** @@ -326,7 +331,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * @return True if the list is empty, otherwise false. */ public boolean isEmpty() { - return this.size == 0; + return this.getSize() == 0; } @Override @@ -352,7 +357,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab index--; } throw new ArrayIndexOutOfBoundsException( - Logging.getCodePosition() + " Invalid index: index=" + index + " size of list=" + this.size); + Logging.getCodePosition() + " Invalid index: index=" + index + " size of list=" + this.getSize()); } /** @@ -419,7 +424,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab int count = 0; for (E e : this) { count++; - s.append(e.toString()).append((count < this.size) ? ", " : ""); + s.append(e.toString()).append((count < this.getSize()) ? ", " : ""); } return s + "]"; } @@ -431,10 +436,10 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab */ private class ListItr implements ReusableListIterator<E> { - private DoublyLinkedListEntry.Finger lastReturned = DoublyLinkedList.this.head; + private DoublyLinkedListEntry.Finger lastReturned = DoublyLinkedList.this.getHead(); private DoublyLinkedListEntry.Finger next; // finger of next element to be returned private int nextIndex; // 0-based index of next element to be returned - private int expectedModCount = DoublyLinkedList.this.modCount; + private int expectedModCount = DoublyLinkedList.this.getModCount(); /** * Create a new ListItr Object and initialize it such that the next returned @@ -445,17 +450,17 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * initialized. */ private ListItr(int index) { - if (index < 0 || index > DoublyLinkedList.this.size) { - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + DoublyLinkedList.this.size); + if (index < 0 || index > DoublyLinkedList.this.getSize()) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + DoublyLinkedList.this.getSize()); } - if (index < (DoublyLinkedList.this.size >> 1)) { - this.next = DoublyLinkedList.this.head.getNext(); + if (index < (DoublyLinkedList.this.getSize() >> 1)) { + this.next = DoublyLinkedList.this.getHead().getNext(); for (this.nextIndex = 0; this.nextIndex < index; this.nextIndex++) { this.next = this.next.getNext(); } } else { - this.next = DoublyLinkedList.this.tail; - for (this.nextIndex = DoublyLinkedList.this.size - 1; this.nextIndex > index; this.nextIndex--) { + this.next = DoublyLinkedList.this.getTail(); + for (this.nextIndex = DoublyLinkedList.this.getSize() - 1; this.nextIndex > index; this.nextIndex--) { this.next = this.next.getPrevious(); } } @@ -464,24 +469,24 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab @Override public void reset() { this.nextIndex = 0; - this.expectedModCount = DoublyLinkedList.this.modCount; - this.lastReturned = DoublyLinkedList.this.head; - this.next = DoublyLinkedList.this.head.getNext(); + this.expectedModCount = DoublyLinkedList.this.getModCount(); + this.lastReturned = DoublyLinkedList.this.getHead(); + this.next = DoublyLinkedList.this.getHead().getNext(); } @Override public boolean hasNext() { - if (DoublyLinkedList.this.size == 0) { + if (DoublyLinkedList.this.getSize() == 0) { return false; } - return this.nextIndex != DoublyLinkedList.this.size; + return this.nextIndex != DoublyLinkedList.this.getSize(); } @Override @SuppressWarnings("unchecked") public E next() { this.checkForComodification(); - if (this.nextIndex == DoublyLinkedList.this.size) { // reached end of list. + if (this.nextIndex == DoublyLinkedList.this.getSize()) { // reached end of list. throw new NoSuchElementException(); } @@ -505,7 +510,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab if (this.next != null) { this.lastReturned = this.next = this.next.getPrevious(); } else { - this.lastReturned = this.next = DoublyLinkedList.this.tail.getPrevious(); // index > 0 => not tail is not head. + this.lastReturned = this.next = DoublyLinkedList.this.getTail().getPrevious(); // index > 0 => not tail is not head. } this.nextIndex--; this.checkForComodification(); @@ -525,7 +530,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab @Override public void remove() { this.checkForComodification(); - if (this.lastReturned == DoublyLinkedList.this.head) { + if (this.lastReturned == DoublyLinkedList.this.getHead()) { throw new IllegalStateException(); } DoublyLinkedListEntry.Finger lastNext = this.lastReturned.getNext(); @@ -538,13 +543,13 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab } else { this.nextIndex--; } - this.lastReturned = DoublyLinkedList.this.head; // cannot remove twice + this.lastReturned = DoublyLinkedList.this.getHead(); // cannot remove twice this.expectedModCount++; } @Override public void set(E o) { - if (this.lastReturned == DoublyLinkedList.this.head) { + if (this.lastReturned == DoublyLinkedList.this.getHead()) { throw new IllegalStateException(); } this.checkForComodification(); @@ -561,7 +566,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab } this.lastReturned.getPrevious().setNext(f); // there's always a previous // release the finger of the old entry - this.lastReturned.getObject().getDoublyLinkedListFinger().releaseFinger(this.lastReturned, DoublyLinkedList.this.keepFinger); + this.lastReturned.getObject().getDoublyLinkedListFinger().releaseFinger(this.lastReturned, DoublyLinkedList.this.isKeepFinger()); if (this.lastReturned == this.next) { // restore the pointers this.lastReturned = this.next = f; } else { @@ -578,7 +583,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab @Override public void add(E o) { this.checkForComodification(); - this.lastReturned = DoublyLinkedList.this.head; + this.lastReturned = DoublyLinkedList.this.getHead(); if (this.next == null) { // append to the end of the list if (DoublyLinkedList.this.append(o)) { this.expectedModCount++; @@ -600,7 +605,7 @@ public class DoublyLinkedList<E extends DoublyLinkedListEntry> implements Iterab * methods. */ final void checkForComodification() { - if (DoublyLinkedList.this.modCount != this.expectedModCount) { + if (DoublyLinkedList.this.getModCount() != this.expectedModCount) { throw new ConcurrentModificationException(); } } diff --git a/src/main/java/sinalgo/tools/storage/DoublyLinkedListEntry.java b/src/main/java/sinalgo/tools/storage/DoublyLinkedListEntry.java index 932b7e85f6373dbf1e6b0d9a38fee11bff7a1bfa..8de6427f9c094a05fd6aec6484bec3ac2c4d1c16 100644 --- a/src/main/java/sinalgo/tools/storage/DoublyLinkedListEntry.java +++ b/src/main/java/sinalgo/tools/storage/DoublyLinkedListEntry.java @@ -36,9 +36,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.storage; +import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.Vector; @@ -70,6 +73,8 @@ public interface DoublyLinkedListEntry { * linked list. It manages the 'next' and 'previous' pointers to the different * lists this entry is stored in. */ + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) class DLLFingerList { /** @@ -77,6 +82,7 @@ public interface DoublyLinkedListEntry { * doublyLinkedLists this element is contained in. */ private Vector<Finger> list = new Vector<>(1); + /** * THe number of fingers this list. */ @@ -90,8 +96,8 @@ public interface DoublyLinkedListEntry { * finger is associated with the list. */ public Finger getFinger(DoublyLinkedList<?> dll) { - for (int i = 0; i < this.numberOfUsedFingers; i++) { - Finger f = this.list.elementAt(i); + for (int i = 0; i < this.getNumberOfUsedFingers(); i++) { + Finger f = this.getList().elementAt(i); if (f != null && f.getList() == dll) { return f; } @@ -112,15 +118,15 @@ public interface DoublyLinkedListEntry { */ public Finger getNewFinger(DoublyLinkedList<?> dll, DoublyLinkedListEntry entry) { Finger f; - if (this.numberOfUsedFingers < this.list.size()) { - f = this.list.elementAt(this.numberOfUsedFingers); + if (this.getNumberOfUsedFingers() < this.getList().size()) { + f = this.getList().elementAt(this.getNumberOfUsedFingers()); } else { f = new Finger(); - this.list.add(f); + this.getList().add(f); } f.setList(dll); f.setObject(entry); - this.numberOfUsedFingers++; + this.setNumberOfUsedFingers(this.getNumberOfUsedFingers() + 1); return f; } @@ -133,13 +139,13 @@ public interface DoublyLinkedListEntry { * otherwise false. */ public void releaseFinger(Finger f, boolean keep) { - for (int i = 0; i < this.numberOfUsedFingers; i++) { - if (f == this.list.elementAt(i)) { + for (int i = 0; i < this.getNumberOfUsedFingers(); i++) { + if (f == this.getList().elementAt(i)) { if (keep) { this.releaseFingerAt(i); } else { - this.list.remove(i); - this.numberOfUsedFingers--; + this.getList().remove(i); + this.setNumberOfUsedFingers(this.getNumberOfUsedFingers() - 1); } break; } @@ -156,14 +162,14 @@ public interface DoublyLinkedListEntry { * otherwise false. */ public void releaseFinger(DoublyLinkedList<?> dll, boolean keep) { - for (int i = 0; i < this.numberOfUsedFingers; i++) { - Finger f = this.list.elementAt(i); + for (int i = 0; i < this.getNumberOfUsedFingers(); i++) { + Finger f = this.getList().elementAt(i); if (f != null && f.getList() == dll) { if (keep) { this.releaseFingerAt(i); } else { - this.list.remove(i); - this.numberOfUsedFingers--; + this.getList().remove(i); + this.setNumberOfUsedFingers(this.getNumberOfUsedFingers() - 1); } break; // at most one finger per dll } @@ -194,14 +200,15 @@ public interface DoublyLinkedListEntry { * @param offset The offset for the move operation */ private void releaseFingerAt(int offset) { - Finger f = this.list.elementAt(offset); + Finger f = this.getList().elementAt(offset); f.reset(); - this.numberOfUsedFingers--; // is now offset that currently points to last used finger - if (offset < this.numberOfUsedFingers) { - this.list.set(offset, this.list.elementAt(this.numberOfUsedFingers)); - this.list.set(this.numberOfUsedFingers, f); + this.setNumberOfUsedFingers(this.getNumberOfUsedFingers() - 1); // is now offset that currently points to last used finger + if (offset < this.getNumberOfUsedFingers()) { + this.getList().set(offset, this.getList().elementAt(this.getNumberOfUsedFingers())); + this.getList().set(this.getNumberOfUsedFingers(), f); } // else: is already last used finger } + } // end of class DLLFingerList /** diff --git a/src/main/java/sinalgo/tools/storage/SortableVector.java b/src/main/java/sinalgo/tools/storage/SortableVector.java index 7f8d9c9c3cd0f96cf3c82939960efa18542cfb4e..61e82b62c44f31acfcd794f3b38fe7bbe9d55716 100644 --- a/src/main/java/sinalgo/tools/storage/SortableVector.java +++ b/src/main/java/sinalgo/tools/storage/SortableVector.java @@ -36,6 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.tools.storage; +import lombok.NoArgsConstructor; + import java.util.Arrays; import java.util.Comparator; import java.util.Vector; @@ -46,6 +48,7 @@ import java.util.Vector; * * @param <T> */ +@NoArgsConstructor public class SortableVector<T> extends Vector<T> { private static final long serialVersionUID = 2685289788493437402L; @@ -59,13 +62,6 @@ public class SortableVector<T> extends Vector<T> { super(size); } - /** - * Default constructor. - */ - public SortableVector() { - super(); - } - /** * Sorts the contents of this vector. The elements contained in the vector may * not be null, and need to implement the Comparable interface.