diff --git a/app/src/main/java/de/hems/trafficsim/MainActivity.java b/app/src/main/java/de/hems/trafficsim/MainActivity.java index d23c0fe..25e10a1 100644 --- a/app/src/main/java/de/hems/trafficsim/MainActivity.java +++ b/app/src/main/java/de/hems/trafficsim/MainActivity.java @@ -97,7 +97,7 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar this.track = new Track(defaultNoOfVehicles, defaultTrackLength, defaultBrakeProb, defaultMaxVelocity, defaultDelay, defaultHistoryLength); this.viewStack = findViewById(R.id.trackViewStack); - this.trackView = new TimeRecordView(this, track); + this.trackView = new TimeRecordView(this); viewStack.addView(this.trackView); this.renderer = new Renderer(track, this.trackView.getHolder()); @@ -212,7 +212,7 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar this.worker.setStop(true); try { this.worker.join(); - } catch (InterruptedException ex) { + } catch (InterruptedException ignored) { } this.worker = null; } @@ -270,7 +270,7 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar this.worker.setStop(true); try { this.worker.join(); - } catch (InterruptedException ex) { + } catch (InterruptedException ignored) { } } diff --git a/app/src/main/java/de/hems/trafficsim/Renderer.java b/app/src/main/java/de/hems/trafficsim/Renderer.java index 06787d3..1e6d1f0 100644 --- a/app/src/main/java/de/hems/trafficsim/Renderer.java +++ b/app/src/main/java/de/hems/trafficsim/Renderer.java @@ -36,11 +36,11 @@ public class Renderer { /** * Paint instance of the renderer */ - protected Paint paint; + final protected Paint paint; /** * holder of the surface the renderer draws to */ - protected SurfaceHolder holder; + final protected SurfaceHolder holder; /** * width of the surface to draw to */ @@ -137,11 +137,11 @@ public class Renderer { canvas = this.holder.lockCanvas(); synchronized (holder) { int y = 0; - int left = 0; - int hCompensateStart = 0; - int hCompensateEnd = 0; - int vCompensateStart = 0; - int vCompensateEnd = 0; + int left; + int hCompensateStart; + int hCompensateEnd; + int vCompensateStart; + int vCompensateEnd; canvas.drawColor(Color.BLACK); for (int curStepIdx = this.track.getVtrList().size()-1; curStepIdx >= 0; curStepIdx--) { diff --git a/app/src/main/java/de/hems/trafficsim/TimeRecordView.java b/app/src/main/java/de/hems/trafficsim/TimeRecordView.java index 4b3ee7d..c9cfda3 100644 --- a/app/src/main/java/de/hems/trafficsim/TimeRecordView.java +++ b/app/src/main/java/de/hems/trafficsim/TimeRecordView.java @@ -8,7 +8,7 @@ import android.view.ViewGroup; * A Surface View which servers as a stage for a renderer. */ public class TimeRecordView extends SurfaceView { - public TimeRecordView(Context context, Track track) { + public TimeRecordView(Context context) { super(context); this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } diff --git a/app/src/main/java/de/hems/trafficsim/Track.java b/app/src/main/java/de/hems/trafficsim/Track.java index 2f139b0..b5aa035 100644 --- a/app/src/main/java/de/hems/trafficsim/Track.java +++ b/app/src/main/java/de/hems/trafficsim/Track.java @@ -13,17 +13,17 @@ public class Track extends Observable { /** * list a vehicles on the track */ - protected List vehicles; + final protected List vehicles; /** * list of resulting time records of the simulation */ - protected List> vtrList; + final protected List> vtrList; /** * length of the track */ - protected float trackLength; + final protected float trackLength; /** * sum of all vehicle speeds during the simulation, used for average calculation @@ -39,7 +39,7 @@ public class Track extends Observable { /** * length of the history kept */ - protected int historyLength; + final protected int historyLength; /** * average over all velocities in the simulation @@ -64,12 +64,12 @@ public class Track extends Observable { /** * currently configured max velocity for all vehicles */ - protected float maxVelocity; + final protected float maxVelocity; /** * currently configured brake probability for all vehicles */ - protected float brakeProb; + final protected float brakeProb; /** * counter for executed simulation steps @@ -79,7 +79,7 @@ public class Track extends Observable { /** * semaphore protecting the vtrlist */ - protected Semaphore listSemaphore; + final protected Semaphore listSemaphore; /** * Constructor for a new Track. @@ -145,15 +145,6 @@ public class Track extends Observable { return delayedAvg; } - /** - * Getter for vehicles - * - * @return vehicles - */ - public List getVehicles() { - return vehicles; - } - /** * Getter for trackLength * @@ -265,7 +256,7 @@ public class Track extends Observable { } for(Vehicle v: vehicles){ v.timeElapse(); - VehicleTimeRecord vtr = new VehicleTimeRecord(v.id, v.position, v.curVelocity, v.maxVelocity); + VehicleTimeRecord vtr = new VehicleTimeRecord(v.position, v.curVelocity, v.maxVelocity); records.add(vtr); } steps++; @@ -274,7 +265,7 @@ public class Track extends Observable { update_avg(); try { Thread.sleep(waitTime); - } catch (InterruptedException ex) { + } catch (InterruptedException ignored) { } } diff --git a/app/src/main/java/de/hems/trafficsim/Vehicle.java b/app/src/main/java/de/hems/trafficsim/Vehicle.java index 775c0c9..81db285 100644 --- a/app/src/main/java/de/hems/trafficsim/Vehicle.java +++ b/app/src/main/java/de/hems/trafficsim/Vehicle.java @@ -9,7 +9,7 @@ public class Vehicle { /** * a number to index the vehicle */ - protected int id; + final protected int id; /** * current position of the vehicle on the track @@ -34,7 +34,7 @@ public class Vehicle { /** * length of the track the vehicle is placed on */ - protected float trackLength; + final protected float trackLength; /** * Constructs a new vehicle. diff --git a/app/src/main/java/de/hems/trafficsim/VehicleTimeRecord.java b/app/src/main/java/de/hems/trafficsim/VehicleTimeRecord.java index 2da5374..21c4d47 100644 --- a/app/src/main/java/de/hems/trafficsim/VehicleTimeRecord.java +++ b/app/src/main/java/de/hems/trafficsim/VehicleTimeRecord.java @@ -4,25 +4,20 @@ package de.hems.trafficsim; * Model class which keeps the previous simulation data for analysis. */ public class VehicleTimeRecord { - /** - * the id of the vehicle it belongs to - */ - protected int id; - /** * the position of the vehicle after the last simulation step */ - protected float position; + final protected float position; /** * the velocity of the vehicle during the last simulation step */ - protected float velocity; + final protected float velocity; /** * the maximum velocity of the vehicle */ - protected float maxVelocity; + final protected float maxVelocity; public float getMaxVelocity() { return maxVelocity; @@ -39,13 +34,11 @@ public class VehicleTimeRecord { /** * Construct a new VehicleTimeRecord. * - * @param id the id of the vehicle it belongs to * @param position the position of the vehicle after the last simulation step * @param velocity the velocity of the vehicle during the last simulation step * @param maxVelocity the maximum velocity of the vehicle */ - public VehicleTimeRecord(int id, float position, float velocity, float maxVelocity) { - this.id = id; + public VehicleTimeRecord(float position, float velocity, float maxVelocity) { this.position = position; this.velocity = velocity; this.maxVelocity = maxVelocity; diff --git a/app/src/main/java/de/hems/trafficsim/Worker.java b/app/src/main/java/de/hems/trafficsim/Worker.java index 942e93b..0703fa4 100644 --- a/app/src/main/java/de/hems/trafficsim/Worker.java +++ b/app/src/main/java/de/hems/trafficsim/Worker.java @@ -9,7 +9,7 @@ public class Worker extends Thread { /** * the track to simulate */ - protected Track track; + protected final Track track; /** * Stop flag, indicating that the worker shall stop @@ -19,12 +19,12 @@ public class Worker extends Thread { /** * the MainActivity of the gui */ - protected MainActivity gui; + protected final MainActivity gui; /** * the Renderer drawing the Track */ - protected Renderer renderer; + protected final Renderer renderer; /** * Amount of simulation steps between two frames in the view. Zero means @@ -74,7 +74,6 @@ public class Worker extends Thread { */ @Override public void run() { - Canvas canvas = null; int i = 0; while (!stop) { this.track.timeElapse(); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8f9d408..7f5e552 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -382,7 +382,7 @@