SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
2 geänderte Dateien mit 43 neuen und 3 gelöschten Zeilen
Nur Änderungen aus Commit 84150aadd2 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.tracer2;
import de.steamwar.bausystem.region.Region;
import lombok.Getter;
import java.util.HashSet;
import java.util.Set;
@ -28,6 +29,7 @@ public class Trace {
/**
* Region this trace has been recorded in
*/
@Getter
private final Region region;
/**

Datei anzeigen

@ -19,11 +19,20 @@
package de.steamwar.bausystem.features.tracer2;
import java.util.HashMap;
import java.util.Map;
import de.steamwar.bausystem.region.Region;
import java.util.*;
import java.util.stream.Collectors;
public class TraceManager {
/**
* Map of all current traces
*/
private final Map<Integer, Trace> traces = new HashMap<>();
/**
* Utility variable to keep track of the next open trace id
*/
private int currOpenId = 0;
/** Adds a new trace to the global record
@ -31,7 +40,7 @@ public class TraceManager {
* @param trace Trace to be added
* @return id of the newly added trace
*/
public int add(Trace trace){
protected int add(Trace trace){
int id = currOpenId;
traces.put(id, trace);
currOpenId++;
@ -53,4 +62,33 @@ public class TraceManager {
traces.clear();
currOpenId = 1;
}
/** Methode to get all traces in a certain region
*
* @param region Region to look for traces in
* @return All traces recorded in the given Region
*/
public Set<Trace> get(Region region){
return traces.values()
.stream()
.filter((Trace trace) -> trace.getRegion() == region)
.collect(Collectors.toSet());
}
/** Methode to get the trace with specific id
*
* @param id id of the trace
* @return the trace with given id or null if no trace with id is found
*/
public Trace get(int id){
return traces.getOrDefault(id, null);
}
/** Methode to get all traces
*
* @return fresh set of all current traces
*/
public Set<Trace> getAll(){
return new HashSet<>(traces.values());
}
}