Commit 93ddbe87 authored by Riegel's avatar Riegel
Browse files

Refactor: Delete Copyable and CopyHandler

CopyHandler and the Copyable-Interface are obsolete due to Copy.copy
offering the object-copying functionality with serialization.
parent 21d23e3b
Pipeline #11066 passed with stage
in 1 minute and 27 seconds
......@@ -19,8 +19,6 @@
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
import de.hft.stuttgart.citydoctor2.utils.CopyHandler;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import de.hft.stuttgart.citydoctor2.utils.SerializablePair;
import java.io.Serial;
......@@ -34,7 +32,7 @@ import java.util.Set;
*
* @author Matthias Betz
*/
public class Vertex extends Vector3d implements Copyable {
public class Vertex extends Vector3d {
@Serial
private static final long serialVersionUID = -5525361920397934892L;
......@@ -138,34 +136,4 @@ public class Vertex extends Vector3d implements Copyable {
adjacentRings = new ArrayList<>(2);
}
@Override
public void collectInstances(CopyHandler handler) {
for (SerializablePair<Geometry, HashSet<LinearRing>> pair : adjacentRings) {
handler.addInstance(pair.getValue0());
for (LinearRing lr : pair.getValue1()) {
handler.addInstance(lr);
}
}
}
@Override
public Copyable createCopyInstance() {
return new Vertex(this);
}
@Override
public void fillValues(Copyable original, CopyHandler handler) {
Vertex originalVertex = (Vertex) original;
// vertex point data already filled
for (SerializablePair<Geometry, HashSet<LinearRing>> pair : originalVertex.adjacentRings) {
Geometry geomCopy = handler.getCopyInstance(pair.getValue0());
HashSet<LinearRing> set = new HashSet<>();
for (LinearRing originalRing : pair.getValue1()) {
set.add(handler.getCopyInstance(originalRing));
}
SerializablePair<Geometry, HashSet<LinearRing>> copyPair = new SerializablePair<>(geomCopy, set);
adjacentRings.add(copyPair);
}
}
}
......@@ -21,8 +21,6 @@ package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.CityGmlUtils;
import de.hft.stuttgart.citydoctor2.utils.CopyHandler;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import javafx.scene.paint.Color;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -157,26 +155,4 @@ public class WaterObject extends CityObject {
return "WaterObject [id=" + getGmlId() + "]";
}
@Override
public WaterObject createCopyInstance() {
return new WaterObject();
}
@Override
public void fillValues(Copyable original, CopyHandler handler) {
WaterObject wo = (WaterObject) original;
WaterObject originalWaterObject = (WaterObject) original;
for (BoundarySurface originalBs : originalWaterObject.boundarySurfaceList) {
boundarySurfaceList.add(handler.getCopyInstance(originalBs));
}
gmlWater = wo.gmlWater;
}
@Override
public void collectInstances(CopyHandler handler) {
super.collectInstances(handler);
handler.addInstance(boundarySurfaceList);
}
}
......@@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Copy {
......@@ -36,7 +37,7 @@ public class Copy {
}
@SuppressWarnings("unchecked")
public static <T extends Copyable> T copy(T original) {
public static <T extends Serializable> T copy(T original) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(out);
......
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.utils;
import java.util.Collection;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class CopyHandler {
private final Set<Copyable> toBeDoneInstances = new HashSet<>();
private final Map<Copyable, Copyable> finishedInstances = new IdentityHashMap<>();
@SuppressWarnings("unchecked")
public <T extends Copyable> T copy(T original) {
toBeDoneInstances.add(original);
while (!toBeDoneInstances.isEmpty()) {
handleNextInstance();
}
for (Entry<Copyable, Copyable> e : finishedInstances.entrySet()) {
e.getValue().fillValues(e.getKey(), this);
}
return (T) finishedInstances.get(original);
}
@SuppressWarnings("unchecked")
public <T extends Copyable> T getCopyInstance(T original) {
if (original == null) {
// null gets copied to null
return null;
}
return (T) finishedInstances.get(original);
}
public void addInstance(Copyable copyable) {
if (copyable == null) {
// don't care for null instances
return;
}
if (finishedInstances.containsKey(copyable)) {
// already processed
return;
}
toBeDoneInstances.add(copyable);
}
private void handleNextInstance() {
Iterator<Copyable> iterator = toBeDoneInstances.iterator();
Copyable next = iterator.next();
iterator.remove();
finishedInstances.put(next, next.createCopyInstance());
next.collectInstances(this);
}
public void addInstance(Collection<? extends Copyable> collection) {
if (collection == null) {
return;
}
for (Copyable c : collection) {
addInstance(c);
}
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.utils;
public interface Copyable {
public void collectInstances(CopyHandler handler);
public Copyable createCopyInstance();
public void fillValues(Copyable original, CopyHandler handler);
}
......@@ -55,7 +55,6 @@ import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
public class AbstractBuildingTest {
......@@ -323,21 +322,15 @@ public class AbstractBuildingTest {
}
private AbstractBuilding createAbstractBuilding() {
AbstractBuilding ab = new AbstractBuilding() {
return new AbstractBuilding() {
private static final long serialVersionUID = -448362592456318541L;
@Override
public Copyable createCopyInstance() {
return null;
}
@Override
public CityObject getTopLevelCityObject(){
return null;
}
};
return ab;
}
}
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.AbstractCheck;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import org.citygml4j.core.model.building.BuildingRoom;
import org.citygml4j.core.model.core.AbstractSpaceBoundary;
import org.citygml4j.core.visitor.ObjectVisitor;
import org.junit.Before;
......@@ -27,11 +25,6 @@ public class AbstractRoomTest {
public CityObject getTopLevelCityObject() {
return null;
}
@Override
public Copyable createCopyInstance() {
return null;
}
};
}
......
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.AbstractCheck;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import org.citygml4j.core.visitor.ObjectVisitor;
import org.junit.Before;
import org.junit.Test;
......@@ -26,11 +25,6 @@ public class AbstractTunnelTest {
public CityObject getTopLevelCityObject() {
return null;
}
@Override
public Copyable createCopyInstance() {
return null;
}
};
}
......
......@@ -2,11 +2,9 @@ package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.AbstractCheck;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
import org.citygml4j.core.model.core.AbstractCityObject;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
......@@ -85,10 +83,6 @@ public class CityObjectTest {
return null;
}
@Override
public Copyable createCopyInstance() {
return null;
}
};
}
}
\ No newline at end of file
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