Skip to content

Commit

Permalink
Removed unnecessary setters from DetectedObject
Browse files Browse the repository at this point in the history
Added unit test for DetectedObject
Fixed DetectionType label
  • Loading branch information
paulbourelly999 committed Jul 28, 2023
1 parent d552372 commit b6811ec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public String getProjString() {
return projString;
}

public void setProjString(String projString) {
this.projString = projString;
}

public Double[] getPositionCovariance() {
return positionCovariance;
}
Expand All @@ -98,87 +94,39 @@ public void setAngularVelocityCovariance(Double[] angularVelocityCovariance) {
this.angularVelocityCovariance = angularVelocityCovariance;
}

public void setType(DetectionType type) {
this.type = type;
}

public double getConfidence() {
return confidence;
}

public void setConfidence(double confidence) {
this.confidence = confidence;
}

public String getSensorId() {
return sensorId;
}

public void setSensorId(String sensorId) {
this.sensorId = sensorId;
}

public String getObjectId() {
return objectId;
}

public void setObjectId(String objectId) {
this.objectId = objectId;
}

public CartesianPoint getPosition() {
return position;
}

public void setPosition(CartesianPoint location) {
this.position = location;
}

public Vector3d getVelocity() {
return velocity;
}

public void setVelocity(Vector3d velocity) {
this.velocity = velocity;
}

public Vector3d getAngularVelocity() {
return angularVelocity;
}

public void setAngularVelocity(Vector3d angularVelocity) {
this.angularVelocity = angularVelocity;
}

public Size getSize() {
return size;
}

public void setSize(Size size) {
this.size = size;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
long temp;
temp = Double.doubleToLongBits(confidence);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((sensorId == null) ? 0 : sensorId.hashCode());
result = prime * result + ((projString == null) ? 0 : projString.hashCode());
result = prime * result + ((objectId == null) ? 0 : objectId.hashCode());
result = prime * result + ((position == null) ? 0 : position.hashCode());
result = prime * result + Arrays.hashCode(positionCovariance);
result = prime * result + ((velocity == null) ? 0 : velocity.hashCode());
result = prime * result + Arrays.hashCode(velocityCovariance);
result = prime * result + ((angularVelocity == null) ? 0 : angularVelocity.hashCode());
result = prime * result + Arrays.hashCode(angularVelocityCovariance);
result = prime * result + ((size == null) ? 0 : size.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ public enum DetectionType {
/**
* Default constructor.
*
* @param name String
* @param label String
*/
DetectionType(String name) {
this.label = name;
DetectionType(String label) {
this.label = label;
}

/**
* Returns the enum mapped from an String name.
* Returns the enum mapped from an String label.
*
* @param name string.
* @return the enum mapped from String name.
* @param label string.
* @return the enum mapped from String label.
*/
public static DetectionType fromName(String name) {
public static DetectionType fromLabel(String label) {
for (DetectionType type: DetectionType.values()) {
if (type.label.equals(name)) {
if (type.label.equals(label)) {
return type;
}
}
throw new IllegalArgumentException("Unknown DetectionType name " + name);
throw new IllegalArgumentException("Unknown DetectionType name " + label);
}

public String getLabel(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
*/
package org.eclipse.mosaic.lib.objects.detector;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.math.Vector3d;
import org.eclipse.mosaic.lib.objects.detector.DetectedObject;
import org.eclipse.mosaic.lib.objects.detector.DetectionType;
import org.eclipse.mosaic.lib.objects.detector.Size;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -147,4 +145,37 @@ public void testDetectObjectJsonDeserialization() {
assertEquals(detectedObject, predictedDetectedObject);
}

@Test
public void testGetterSetterConstructor() {
//Test constructor
DetectedObject detectedObject = new DetectedObject(
DetectionType.VAN,
0.5,
"sensor1",
"projection String",
"Object1",
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(2, 3, 4),
new Vector3d(-4.4,-5.5,-6.6),
new Size(3, 4, 5));
Double[] covarianceMatrix = new Double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
detectedObject.setPositionCovariance(covarianceMatrix);
detectedObject.setVelocityCovariance(covarianceMatrix);
detectedObject.setAngularVelocityCovariance(covarianceMatrix);
// Test Getters
assertEquals(DetectionType.VAN, detectedObject.getType());
assertEquals(0.5, detectedObject.getConfidence(), .01);
assertEquals("sensor1", detectedObject.getSensorId());
assertEquals("projection String", detectedObject.getProjString());
assertEquals("Object1", detectedObject.getObjectId());
assertEquals(CartesianPoint.xyz(1.1, 2, 3.2), detectedObject.getPosition());
assertEquals(new Vector3d(2, 3, 4), detectedObject.getVelocity());
assertEquals(new Vector3d(-4.4, -5.5, -6.6), detectedObject.getAngularVelocity());
assertEquals( new Size(3,4,5), detectedObject.getSize());
assertArrayEquals(covarianceMatrix, detectedObject.getPositionCovariance());
assertArrayEquals(covarianceMatrix, detectedObject.getVelocityCovariance());
assertArrayEquals(covarianceMatrix, detectedObject.getAngularVelocityCovariance());

}

}

0 comments on commit b6811ec

Please sign in to comment.