Commit 40adb55b authored by Jakob Schöttl's avatar Jakob Schöttl

Remove DataKey class and adjust former subclasses

parent 7201a445
package org.vadere.simulator.projects.dataprocessing_mtp;
import java.util.Map;
import org.vadere.simulator.control.SimulationState;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Map;
public class AreaSpeedProcessor extends AreaProcessor<Double> {
private PedestrianPositionProcessor pedPosProc;
......@@ -21,18 +20,17 @@ public class AreaSpeedProcessor extends AreaProcessor<Double> {
this.pedPosProc.update(state);
this.pedVelProc.update(state);
VRectangle measurementArea = this.getMeasurementArea();
Map<PedestrianIdDataKey, VPoint> positionMap = this.pedPosProc.getPositions(new TimestepDataKey(step));
int pedCount = 0;
double sumVelocities = 0.0;
for (Map.Entry<PedestrianIdDataKey, VPoint> entry : positionMap.entrySet()) {
PedestrianIdDataKey pedId = entry.getKey();
VPoint pos = entry.getValue();
final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue();
if (this.getMeasurementArea().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdDataKey(step, pedId.getKey()));
if (getMeasurementArea().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdDataKey(step, pedId));
pedCount++;
}
}
......
package org.vadere.simulator.projects.dataprocessing_mtp;
public abstract class DataKey<K extends Comparable<K>> {
private K key;
protected DataKey(final K key) {
this.key = key;
}
public K getKey() {
return this.key;
}
public boolean equals(Object o) {
if (o instanceof DataKey)
return this.key.equals(((DataKey) o).key);
return false;
}
public int hashCode() {
return this.key.hashCode();
}
public String toString() {
return this.key.toString();
}
}
package org.vadere.simulator.projects.dataprocessing_mtp;
public final class NoDataKey extends DataKey<Integer> implements Comparable<NoDataKey> {
public final class NoDataKey implements Comparable<NoDataKey> {
private static NoDataKey key;
private NoDataKey() {
super(0);
}
private NoDataKey() { }
@Override
public int compareTo(final NoDataKey o) {
return (o instanceof NoDataKey) ? 0 : 1;
return 0;
}
public static NoDataKey key() {
if (NoDataKey.key == null)
NoDataKey.key = new NoDataKey();
if (key == null)
key = new NoDataKey();
return NoDataKey.key;
return key;
}
}
package org.vadere.simulator.projects.dataprocessing_mtp;
public class PedestrianIdDataKey extends DataKey<Integer> implements Comparable<PedestrianIdDataKey> {
public PedestrianIdDataKey(final Integer key) {
super(key);
public class PedestrianIdDataKey implements Comparable<PedestrianIdDataKey> {
private final int pedestrianId;
public PedestrianIdDataKey(int pedestrianId) {
this.pedestrianId = pedestrianId;
}
public int compareTo(PedestrianIdDataKey o) {
return this.getKey().compareTo(o.getKey());
public int getPedestrianId() {
return pedestrianId;
}
public static String getHeader() {
return "pid";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + pedestrianId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PedestrianIdDataKey other = (PedestrianIdDataKey) obj;
if (pedestrianId != other.pedestrianId)
return false;
return true;
}
@Override
public int compareTo(PedestrianIdDataKey o) {
return Integer.compare(pedestrianId, o.pedestrianId);
}
}
package org.vadere.simulator.projects.dataprocessing_mtp;
import org.vadere.simulator.control.SimulationState;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.vadere.simulator.control.SimulationState;
import org.vadere.util.geometry.shapes.VPoint;
public class PedestrianPositionProcessor extends Processor<TimestepPedestrianIdDataKey, VPoint> {
public PedestrianPositionProcessor() {
......@@ -14,7 +14,8 @@ public class PedestrianPositionProcessor extends Processor<TimestepPedestrianIdD
}
public Map<PedestrianIdDataKey, VPoint> getPositions(TimestepDataKey timestepKey) {
return this.getColumn().entrySet().stream().filter(e -> e.getKey().getTimestep() == timestepKey.getKey())
return this.getColumn().entrySet().stream()
.filter(e -> e.getKey().equals(timestepKey))
.collect(Collectors.toMap(e -> new PedestrianIdDataKey(e.getKey().getPedestrianId()), e -> e.getValue()));
}
......
package org.vadere.simulator.projects.dataprocessing_mtp;
import org.vadere.simulator.control.SimulationState;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.vadere.simulator.control.SimulationState;
public abstract class Processor<K extends Comparable<K>, V> {
private int id;
......@@ -59,7 +59,7 @@ public abstract class Processor<K extends Comparable<K>, V> {
}
public V getValue(final K key) {
return column.containsKey(key) ? column.get(key) : null;
return column.get(key);
}
protected void setValue(final K key, final V value) {
......
package org.vadere.simulator.projects.dataprocessing_mtp;
import org.jetbrains.annotations.NotNull;
public class TimestepDataKey extends DataKey<Integer> implements Comparable<TimestepDataKey> {
public TimestepDataKey(int timeStep) {
super(timeStep);
public class TimestepDataKey implements Comparable<TimestepDataKey> {
private final int timestep;
public TimestepDataKey(int timestep) {
this.timestep = timestep;
}
@Override
public int compareTo(final TimestepDataKey o) {
return this.getKey().compareTo(o.getKey());
return Integer.compare(timestep, o.timestep);
}
public static String getHeader() {
......
package org.vadere.simulator.projects.dataprocessing_mtp;
import org.apache.commons.lang3.tuple.Pair;
public class TimestepPedestrianIdDataKey implements Comparable<TimestepPedestrianIdDataKey> {
private final int timestep;
private final int pedestrianId;
public class TimestepPedestrianIdDataKey extends DataKey<Pair<Integer, Integer>>
implements Comparable<TimestepPedestrianIdDataKey> {
public TimestepPedestrianIdDataKey(final Integer timestep, final Integer pedId) {
super(Pair.of(timestep, pedId));
public TimestepPedestrianIdDataKey(int timestep, int pedestrianId) {
this.timestep = timestep;
this.pedestrianId = pedestrianId;
}
public Integer getTimestep() {
return this.getKey().getLeft();
return timestep;
}
public Integer getPedestrianId() {
return this.getKey().getRight();
return pedestrianId;
}
@Override
public int compareTo(TimestepPedestrianIdDataKey o) {
return this.getKey().compareTo(o.getKey());
int result = Integer.compare(timestep, o.timestep);
if (result == 0) {
return Integer.compare(pedestrianId, o.pedestrianId);
}
return result;
}
public static String[] getHeaders() {
......
Markdown is supported
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