Fix some code analysis errors
This commit is contained in:
parent
f14372efb8
commit
750674c436
@ -97,7 +97,7 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar
|
|||||||
this.track = new Track(defaultNoOfVehicles, defaultTrackLength, defaultBrakeProb,
|
this.track = new Track(defaultNoOfVehicles, defaultTrackLength, defaultBrakeProb,
|
||||||
defaultMaxVelocity, defaultDelay, defaultHistoryLength);
|
defaultMaxVelocity, defaultDelay, defaultHistoryLength);
|
||||||
this.viewStack = findViewById(R.id.trackViewStack);
|
this.viewStack = findViewById(R.id.trackViewStack);
|
||||||
this.trackView = new TimeRecordView(this, track);
|
this.trackView = new TimeRecordView(this);
|
||||||
|
|
||||||
viewStack.addView(this.trackView);
|
viewStack.addView(this.trackView);
|
||||||
this.renderer = new Renderer(track, this.trackView.getHolder());
|
this.renderer = new Renderer(track, this.trackView.getHolder());
|
||||||
@ -212,7 +212,7 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar
|
|||||||
this.worker.setStop(true);
|
this.worker.setStop(true);
|
||||||
try {
|
try {
|
||||||
this.worker.join();
|
this.worker.join();
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
this.worker = null;
|
this.worker = null;
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar
|
|||||||
this.worker.setStop(true);
|
this.worker.setStop(true);
|
||||||
try {
|
try {
|
||||||
this.worker.join();
|
this.worker.join();
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ public class Renderer {
|
|||||||
/**
|
/**
|
||||||
* Paint instance of the renderer
|
* Paint instance of the renderer
|
||||||
*/
|
*/
|
||||||
protected Paint paint;
|
final protected Paint paint;
|
||||||
/**
|
/**
|
||||||
* holder of the surface the renderer draws to
|
* holder of the surface the renderer draws to
|
||||||
*/
|
*/
|
||||||
protected SurfaceHolder holder;
|
final protected SurfaceHolder holder;
|
||||||
/**
|
/**
|
||||||
* width of the surface to draw to
|
* width of the surface to draw to
|
||||||
*/
|
*/
|
||||||
@ -137,11 +137,11 @@ public class Renderer {
|
|||||||
canvas = this.holder.lockCanvas();
|
canvas = this.holder.lockCanvas();
|
||||||
synchronized (holder) {
|
synchronized (holder) {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int left = 0;
|
int left;
|
||||||
int hCompensateStart = 0;
|
int hCompensateStart;
|
||||||
int hCompensateEnd = 0;
|
int hCompensateEnd;
|
||||||
int vCompensateStart = 0;
|
int vCompensateStart;
|
||||||
int vCompensateEnd = 0;
|
int vCompensateEnd;
|
||||||
canvas.drawColor(Color.BLACK);
|
canvas.drawColor(Color.BLACK);
|
||||||
for (int curStepIdx = this.track.getVtrList().size()-1; curStepIdx >= 0;
|
for (int curStepIdx = this.track.getVtrList().size()-1; curStepIdx >= 0;
|
||||||
curStepIdx--) {
|
curStepIdx--) {
|
||||||
|
@ -8,7 +8,7 @@ import android.view.ViewGroup;
|
|||||||
* A Surface View which servers as a stage for a renderer.
|
* A Surface View which servers as a stage for a renderer.
|
||||||
*/
|
*/
|
||||||
public class TimeRecordView extends SurfaceView {
|
public class TimeRecordView extends SurfaceView {
|
||||||
public TimeRecordView(Context context, Track track) {
|
public TimeRecordView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,17 @@ public class Track extends Observable {
|
|||||||
/**
|
/**
|
||||||
* list a vehicles on the track
|
* list a vehicles on the track
|
||||||
*/
|
*/
|
||||||
protected List<Vehicle> vehicles;
|
final protected List<Vehicle> vehicles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list of resulting time records of the simulation
|
* list of resulting time records of the simulation
|
||||||
*/
|
*/
|
||||||
protected List<List<VehicleTimeRecord>> vtrList;
|
final protected List<List<VehicleTimeRecord>> vtrList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* length of the track
|
* length of the track
|
||||||
*/
|
*/
|
||||||
protected float trackLength;
|
final protected float trackLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sum of all vehicle speeds during the simulation, used for average calculation
|
* 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
|
* length of the history kept
|
||||||
*/
|
*/
|
||||||
protected int historyLength;
|
final protected int historyLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* average over all velocities in the simulation
|
* average over all velocities in the simulation
|
||||||
@ -64,12 +64,12 @@ public class Track extends Observable {
|
|||||||
/**
|
/**
|
||||||
* currently configured max velocity for all vehicles
|
* currently configured max velocity for all vehicles
|
||||||
*/
|
*/
|
||||||
protected float maxVelocity;
|
final protected float maxVelocity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* currently configured brake probability for all vehicles
|
* currently configured brake probability for all vehicles
|
||||||
*/
|
*/
|
||||||
protected float brakeProb;
|
final protected float brakeProb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* counter for executed simulation steps
|
* counter for executed simulation steps
|
||||||
@ -79,7 +79,7 @@ public class Track extends Observable {
|
|||||||
/**
|
/**
|
||||||
* semaphore protecting the vtrlist
|
* semaphore protecting the vtrlist
|
||||||
*/
|
*/
|
||||||
protected Semaphore listSemaphore;
|
final protected Semaphore listSemaphore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for a new Track.
|
* Constructor for a new Track.
|
||||||
@ -145,15 +145,6 @@ public class Track extends Observable {
|
|||||||
return delayedAvg;
|
return delayedAvg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for vehicles
|
|
||||||
*
|
|
||||||
* @return vehicles
|
|
||||||
*/
|
|
||||||
public List<Vehicle> getVehicles() {
|
|
||||||
return vehicles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for trackLength
|
* Getter for trackLength
|
||||||
*
|
*
|
||||||
@ -265,7 +256,7 @@ public class Track extends Observable {
|
|||||||
}
|
}
|
||||||
for(Vehicle v: vehicles){
|
for(Vehicle v: vehicles){
|
||||||
v.timeElapse();
|
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);
|
records.add(vtr);
|
||||||
}
|
}
|
||||||
steps++;
|
steps++;
|
||||||
@ -274,7 +265,7 @@ public class Track extends Observable {
|
|||||||
update_avg();
|
update_avg();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(waitTime);
|
Thread.sleep(waitTime);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ public class Vehicle {
|
|||||||
/**
|
/**
|
||||||
* a number to index the vehicle
|
* a number to index the vehicle
|
||||||
*/
|
*/
|
||||||
protected int id;
|
final protected int id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* current position of the vehicle on the track
|
* current position of the vehicle on the track
|
||||||
@ -34,7 +34,7 @@ public class Vehicle {
|
|||||||
/**
|
/**
|
||||||
* length of the track the vehicle is placed on
|
* length of the track the vehicle is placed on
|
||||||
*/
|
*/
|
||||||
protected float trackLength;
|
final protected float trackLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new vehicle.
|
* Constructs a new vehicle.
|
||||||
|
@ -4,25 +4,20 @@ package de.hems.trafficsim;
|
|||||||
* Model class which keeps the previous simulation data for analysis.
|
* Model class which keeps the previous simulation data for analysis.
|
||||||
*/
|
*/
|
||||||
public class VehicleTimeRecord {
|
public class VehicleTimeRecord {
|
||||||
/**
|
|
||||||
* the id of the vehicle it belongs to
|
|
||||||
*/
|
|
||||||
protected int id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the position of the vehicle after the last simulation step
|
* 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
|
* the velocity of the vehicle during the last simulation step
|
||||||
*/
|
*/
|
||||||
protected float velocity;
|
final protected float velocity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the maximum velocity of the vehicle
|
* the maximum velocity of the vehicle
|
||||||
*/
|
*/
|
||||||
protected float maxVelocity;
|
final protected float maxVelocity;
|
||||||
|
|
||||||
public float getMaxVelocity() {
|
public float getMaxVelocity() {
|
||||||
return maxVelocity;
|
return maxVelocity;
|
||||||
@ -39,13 +34,11 @@ public class VehicleTimeRecord {
|
|||||||
/**
|
/**
|
||||||
* Construct a new 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 position the position of the vehicle after the last simulation step
|
||||||
* @param velocity the velocity of the vehicle during the last simulation step
|
* @param velocity the velocity of the vehicle during the last simulation step
|
||||||
* @param maxVelocity the maximum velocity of the vehicle
|
* @param maxVelocity the maximum velocity of the vehicle
|
||||||
*/
|
*/
|
||||||
public VehicleTimeRecord(int id, float position, float velocity, float maxVelocity) {
|
public VehicleTimeRecord(float position, float velocity, float maxVelocity) {
|
||||||
this.id = id;
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
this.maxVelocity = maxVelocity;
|
this.maxVelocity = maxVelocity;
|
||||||
|
@ -9,7 +9,7 @@ public class Worker extends Thread {
|
|||||||
/**
|
/**
|
||||||
* the track to simulate
|
* the track to simulate
|
||||||
*/
|
*/
|
||||||
protected Track track;
|
protected final Track track;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop flag, indicating that the worker shall stop
|
* Stop flag, indicating that the worker shall stop
|
||||||
@ -19,12 +19,12 @@ public class Worker extends Thread {
|
|||||||
/**
|
/**
|
||||||
* the MainActivity of the gui
|
* the MainActivity of the gui
|
||||||
*/
|
*/
|
||||||
protected MainActivity gui;
|
protected final MainActivity gui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the Renderer drawing the Track
|
* the Renderer drawing the Track
|
||||||
*/
|
*/
|
||||||
protected Renderer renderer;
|
protected final Renderer renderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount of simulation steps between two frames in the view. Zero means
|
* Amount of simulation steps between two frames in the view. Zero means
|
||||||
@ -74,7 +74,6 @@ public class Worker extends Thread {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Canvas canvas = null;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
this.track.timeElapse();
|
this.track.timeElapse();
|
||||||
|
@ -382,7 +382,7 @@
|
|||||||
<Button
|
<Button
|
||||||
android:id="@+id/clearButton"
|
android:id="@+id/clearButton"
|
||||||
style="@style/Widget.AppCompat.Button.Borderless"
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:onClick="onClearButtonClick"
|
android:onClick="onClearButtonClick"
|
||||||
|
Loading…
Reference in New Issue
Block a user