From b6811ec488f4660b85fcc2cdf425943187116661 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 28 Jul 2023 12:50:02 -0400 Subject: [PATCH] Removed unnecessary setters from DetectedObject Added unit test for DetectedObject Fixed DetectionType label --- .../lib/objects/detector/DetectedObject.java | 52 ------------------- .../lib/objects/detector/DetectionType.java | 18 +++---- .../objects/detector/DetectedObjectTest.java | 37 +++++++++++-- 3 files changed, 43 insertions(+), 64 deletions(-) diff --git a/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java b/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java index 2fcd67c8..d1b5e7a4 100644 --- a/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java +++ b/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectedObject.java @@ -70,10 +70,6 @@ public String getProjString() { return projString; } - public void setProjString(String projString) { - this.projString = projString; - } - public Double[] getPositionCovariance() { return positionCovariance; } @@ -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) diff --git a/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectionType.java b/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectionType.java index c75aa06d..a0ea9b9b 100644 --- a/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectionType.java +++ b/co-simulation/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/detector/DetectionType.java @@ -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(){ diff --git a/co-simulation/lib/mosaic-objects/src/test/java/org/eclipse/mosaic/lib/objects/detector/DetectedObjectTest.java b/co-simulation/lib/mosaic-objects/src/test/java/org/eclipse/mosaic/lib/objects/detector/DetectedObjectTest.java index d252fc69..3b827851 100644 --- a/co-simulation/lib/mosaic-objects/src/test/java/org/eclipse/mosaic/lib/objects/detector/DetectedObjectTest.java +++ b/co-simulation/lib/mosaic-objects/src/test/java/org/eclipse/mosaic/lib/objects/detector/DetectedObjectTest.java @@ -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; @@ -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()); + + } + }