Commit 1745865f authored by Riegel's avatar Riegel
Browse files

Code cleaning Ref #69

parent 5a6f4b46
......@@ -30,6 +30,8 @@ import de.hft.stuttgart.citydoctor2.check.HealingMethod;
import de.hft.stuttgart.citydoctor2.check.ModificationListener;
import de.hft.stuttgart.citydoctor2.datastructure.GmlElement;
import java.io.Serial;
/**
* This error is created when an unexpected exception is thrown by the code.
*
......@@ -38,11 +40,12 @@ import de.hft.stuttgart.citydoctor2.datastructure.GmlElement;
*/
public class UnknownCheckError implements CheckError {
@Serial
private static final long serialVersionUID = -6554097632341055596L;
private Checkable c;
private Exception e;
private CheckId checkId;
private final Checkable c;
private final Exception e;
private final CheckId checkId;
public UnknownCheckError(Checkable c, Exception e, Check check) {
this.c = c;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
......@@ -47,12 +48,13 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public abstract class AbstractBuilding extends CityObject {
@Serial
private static final long serialVersionUID = -2196414503088741206L;
private static final Logger logger = LogManager.getLogger(AbstractBuilding.class);
private List<Installation> buildingInstallations = new ArrayList<>(2);
private List<BoundarySurface> boundarySurfaceList = new ArrayList<>();
private final List<Installation> buildingInstallations = new ArrayList<>(2);
private final List<BoundarySurface> boundarySurfaceList = new ArrayList<>();
private org.citygml4j.core.model.building.AbstractBuilding ab;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
......@@ -42,12 +43,13 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public class BoundarySurface extends CityObject {
@Serial
private static final long serialVersionUID = 8793865135393496408L;
private SurfaceFeatureType featureType;
private BoundarySurfaceType type;
private List<Opening> openings = new ArrayList<>(2);
private final List<Opening> openings = new ArrayList<>(2);
private CityObject parent;
private AbstractThematicSurface gmlObject;
......
......@@ -32,7 +32,7 @@ import de.hft.stuttgart.citydoctor2.utils.BoundingBoxCalculator;
*/
public class BoundingBox {
private Vector3d[] bbox;
private final Vector3d[] bbox;
/**
* Creates an axis aligned bounding box containing all points of all polygons
......@@ -142,11 +142,7 @@ public class BoundingBox {
public double getLongestSide() {
double width = getWidth();
double depth = getDepth();
if (width > depth) {
return width;
} else {
return depth;
}
return Math.max(width, depth);
}
/**
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
......@@ -47,10 +48,11 @@ public class BridgeConstructiveElement extends CityObject {
private static final String CANNOT_ADD = "Cannot add ";
@Serial
private static final long serialVersionUID = 7353233899458901155L;
private org.citygml4j.core.model.bridge.BridgeConstructiveElement gmlBridgeElement;
private List<BoundarySurface> boundarySurfaceList = new ArrayList<>();
private final org.citygml4j.core.model.bridge.BridgeConstructiveElement gmlBridgeElement;
private final List<BoundarySurface> boundarySurfaceList = new ArrayList<>();
public BridgeConstructiveElement(org.citygml4j.core.model.bridge.BridgeConstructiveElement gmlObject) {
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
......@@ -35,9 +36,10 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
public class Building extends AbstractBuilding {
@Serial
private static final long serialVersionUID = 588480113268630052L;
private List<BuildingPart> buildingParts = new ArrayList<>(2);
private final List<BuildingPart> buildingParts = new ArrayList<>(2);
public List<BuildingPart> getBuildingParts() {
return buildingParts;
......
......@@ -21,8 +21,11 @@ package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.utils.CopyHandler;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import java.io.Serial;
public class BuildingPart extends AbstractBuilding {
@Serial
private static final long serialVersionUID = 8200322261958679163L;
private Building parent;
......
......@@ -53,17 +53,17 @@ import de.hft.stuttgart.quality.model.types.ValidationPlan;
public class CityDoctorModel {
private static final String COULD_NOT_FIND_FEATURE = "Could not find feature: ";
private List<Building> buildings;
private List<Vegetation> vegetation;
private List<BridgeObject> bridges;
private List<CityObject> land;
private List<TransportationObject> roads;
private List<WaterObject> water;
private final List<Building> buildings;
private final List<Vegetation> vegetation;
private final List<BridgeObject> bridges;
private final List<CityObject> land;
private final List<TransportationObject> roads;
private final List<WaterObject> water;
private CityModel cModel;
private ParserConfiguration config;
private String fileName;
private File file;
private List<CheckError> globalErrors;
private final ParserConfiguration config;
private final String fileName;
private final File file;
private final List<CheckError> globalErrors;
private boolean isValidated = false;
private ValidationPlan plan;
private CityGMLVersion cityGMLVersion;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
......@@ -43,9 +44,10 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public abstract class CityObject extends GmlElement {
@Serial
private static final long serialVersionUID = 651712070755024188L;
private List<Geometry> geometryList = new ArrayList<>();
private final List<Geometry> geometryList = new ArrayList<>();
/**
* Recreates the CityGML4j geometry in this object. The CityGML4j geometry is
......@@ -83,23 +85,11 @@ public abstract class CityObject extends GmlElement {
}
public void removeGeometry(Lod lod) {
Iterator<Geometry> it = geometryList.iterator();
while (it.hasNext()) {
Geometry next = it.next();
if (next.getLod() == lod) {
it.remove();
}
}
geometryList.removeIf(geom -> geom.getLod() == lod);
}
public void removeGeometry(Lod lod, GeometryType type) {
Iterator<Geometry> it = geometryList.iterator();
while (it.hasNext()) {
Geometry next = it.next();
if (next.getLod() == lod && next.getType() == type) {
it.remove();
}
}
geometryList.removeIf(geom -> geom.getLod() == lod && geom.getType() == type);
}
public Geometry getHighestLodGeometry() {
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -41,6 +42,7 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public class ConcretePolygon extends Polygon {
@Serial
private static final long serialVersionUID = -2208347892270418372L;
private LinearRing exterior;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......@@ -33,10 +34,11 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public class Edge implements Serializable, Copyable {
@Serial
private static final long serialVersionUID = -504694863498128296L;
private List<Polygon> adjacentPolygons = new ArrayList<>(2);
private List<LinearRing> adjacentRings = new ArrayList<>(2);
private final List<Polygon> adjacentPolygons = new ArrayList<>(2);
private final List<LinearRing> adjacentRings = new ArrayList<>(2);
private Vertex from;
private Vertex to;
......@@ -78,16 +80,8 @@ public class Edge implements Serializable, Copyable {
}
private boolean isPointOfEdge(Vertex v0, Vertex edgePoint) {
if (v0.equals(edgePoint)) {
return true;
}
// for (Vertex v : v0.getNeighbors()) {
// if (v.equals(edgePoint)) {
// return true;
// }
// }
return false;
}
return v0.equals(edgePoint);
}
public boolean formedByIgnoreDirection(Vertex v1, Vertex v2) {
return (v1 == from && v2 == to) || (v1 == to && v2 == from);
......@@ -146,14 +140,9 @@ public class Edge implements Serializable, Copyable {
return false;
}
if (to == null) {
if (other.to != null) {
return false;
}
} else if (!to.equals(other.to)) {
return false;
}
return true;
}
return other.to == null;
} else return to.equals(other.to);
}
public void addAdjacentPolygon(Polygon p) {
adjacentPolygons.add(p);
......
......@@ -27,6 +27,6 @@ package de.hft.stuttgart.citydoctor2.datastructure;
public enum FeatureType {
BUILDING, TRANSPORTATION, VEGETATION, BRIDGE, LAND, WATER, BOUNDARY_SURFACE, INSTALLATION, OPENING,
BUILDING_PART, BRIDGE_CONSTRUCTION_ELEMENT, BRIDGE_INSTALLATION;
BUILDING_PART, BRIDGE_CONSTRUCTION_ELEMENT, BRIDGE_INSTALLATION
}
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
......@@ -48,16 +49,17 @@ public class Geometry extends GmlElement {
private static final String FAILED_REMOVING_POLYGON = "Removing polygon %s but polygon is not in geometry";
@Serial
private static final long serialVersionUID = 2539031030917731575L;
private static Random r = new Random();
private static final Random r = new Random();
private GeometryType type;
private Lod lod;
private final Lod lod;
private CityObject parent;
private List<Polygon> polygons = new ArrayList<>(2);
private final List<Polygon> polygons = new ArrayList<>(2);
private List<Edge> edges;
private Map<SerializablePair<Vertex, Vertex>, Edge> edgeMap;
private List<Vertex> vertices;
......@@ -153,7 +155,7 @@ public class Geometry extends GmlElement {
}
// only go to size -1 as ring should be closed
for (int i = 0; i < ring.getVertices().size() - 1; i++) {
Vertex v0 = ring.getVertices().get(i + 0);
Vertex v0 = ring.getVertices().get(i);
Vertex v1 = ring.getVertices().get(i + 1);
Edge tempEdge = new Edge(v0, v1);
Edge e = duplicacyMap.get(tempEdge);
......
......@@ -22,6 +22,8 @@ import de.hft.stuttgart.citydoctor2.check.Checkable;
import de.hft.stuttgart.citydoctor2.utils.CopyHandler;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import java.io.Serial;
/**
* A general GML element that has a gml id
*
......@@ -30,6 +32,7 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public abstract class GmlElement extends Checkable implements Copyable {
@Serial
private static final long serialVersionUID = -3242505393303017359L;
private GmlId gmlId;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -30,14 +31,15 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class GmlId implements Serializable {
@Serial
private static final long serialVersionUID = 4273817255150972966L;
/* prefixes for generation */
private static final String GENERAL_GEN = "CityDoctor_%d_%d";
private static final AtomicInteger ID_COUNTER = new AtomicInteger();
private String gmlString;
private boolean generated;
private final String gmlString;
private final boolean generated;
public GmlId(String gmlId) {
this(gmlId, false);
......@@ -85,14 +87,9 @@ public class GmlId implements Serializable {
return false;
}
if (gmlString == null) {
if (other.gmlString != null) {
return false;
}
} else if (!gmlString.equals(other.gmlString)) {
return false;
}
return true;
}
return other.gmlString == null;
} else return gmlString.equals(other.gmlString);
}
/**
* Determines if the GML-ID was generated by CityDoctor or not.
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
......@@ -41,6 +42,7 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
public class Installation extends CityObject {
@Serial
private static final long serialVersionUID = 1576237433322680191L;
private List<BoundarySurface> boundarySurfaces = new ArrayList<>(4);
......
......@@ -29,6 +29,8 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.CityGmlUtils;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import java.io.Serial;
/**
* Represents a land use CityGML object.
*
......@@ -37,6 +39,7 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public class LandObject extends CityObject {
@Serial
private static final long serialVersionUID = 1887455662411087326L;
private LandUse lu;
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
......@@ -38,12 +39,13 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public class LinearRing extends GmlElement {
@Serial
private static final long serialVersionUID = -2488180830514940722L;
private LinearRingType type;
private Polygon parent;
private List<Vertex> vertices = new ArrayList<>();
private final List<Vertex> vertices = new ArrayList<>();
public enum LinearRingType {
EXTERIOR, INTERIOR
......@@ -130,7 +132,7 @@ public class LinearRing extends GmlElement {
public Vector3d calculateNormal() {
double[] coords = new double[3];
for (int i = 0; i < vertices.size() - 1; i++) {
Vertex current = vertices.get(i + 0);
Vertex current = vertices.get(i);
Vertex next = vertices.get(i + 1);
coords[0] += (current.getZ() + next.getZ()) * (current.getY() - next.getY());
coords[1] += (current.getX() + next.getX()) * (current.getZ() - next.getZ());
......
......@@ -18,6 +18,7 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import java.io.Serial;
import java.util.List;
import java.util.Map;
......@@ -39,6 +40,7 @@ import de.hft.stuttgart.citydoctor2.utils.Copyable;
*/
public class LinkedPolygon extends Polygon {
@Serial
private static final long serialVersionUID = -4897578390280277931L;
private Geometry parent;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment