Browse Source

Fix some code analysis errors

tags/Release_1
Loch Christian (uib05376) Chris <chris@skalarprodukt.de> 3 years ago
parent
commit
750674c436
8 changed files with 30 additions and 47 deletions
  1. +3
    -3
      app/src/main/java/de/hems/trafficsim/MainActivity.java
  2. +7
    -7
      app/src/main/java/de/hems/trafficsim/Renderer.java
  3. +1
    -1
      app/src/main/java/de/hems/trafficsim/TimeRecordView.java
  4. +9
    -18
      app/src/main/java/de/hems/trafficsim/Track.java
  5. +2
    -2
      app/src/main/java/de/hems/trafficsim/Vehicle.java
  6. +4
    -11
      app/src/main/java/de/hems/trafficsim/VehicleTimeRecord.java
  7. +3
    -4
      app/src/main/java/de/hems/trafficsim/Worker.java
  8. +1
    -1
      app/src/main/res/layout/activity_main.xml

+ 3
- 3
app/src/main/java/de/hems/trafficsim/MainActivity.java View File

@@ -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) {
}
}



+ 7
- 7
app/src/main/java/de/hems/trafficsim/Renderer.java View File

@@ -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--) {


+ 1
- 1
app/src/main/java/de/hems/trafficsim/TimeRecordView.java View File

@@ -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));
}


+ 9
- 18
app/src/main/java/de/hems/trafficsim/Track.java View File

@@ -13,17 +13,17 @@ public class Track extends Observable {
/**
* list a vehicles on the track
*/
protected List<Vehicle> vehicles;
final protected List<Vehicle> vehicles;

/**
* list of resulting time records of the simulation
*/
protected List<List<VehicleTimeRecord>> vtrList;
final protected List<List<VehicleTimeRecord>> 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<Vehicle> 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) {
}
}



+ 2
- 2
app/src/main/java/de/hems/trafficsim/Vehicle.java View File

@@ -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.


+ 4
- 11
app/src/main/java/de/hems/trafficsim/VehicleTimeRecord.java View File

@@ -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;


+ 3
- 4
app/src/main/java/de/hems/trafficsim/Worker.java View File

@@ -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();


+ 1
- 1
app/src/main/res/layout/activity_main.xml View File

@@ -382,7 +382,7 @@
<Button
android:id="@+id/clearButton"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClearButtonClick"


Loading…
Cancel
Save