Added getters to TraceManager
Dieser Commit ist enthalten in:
Ursprung
32fb859764
Commit
84150aadd2
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bausystem.features.tracer2;
|
package de.steamwar.bausystem.features.tracer2;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -28,6 +29,7 @@ public class Trace {
|
|||||||
/**
|
/**
|
||||||
* Region this trace has been recorded in
|
* Region this trace has been recorded in
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
private final Region region;
|
private final Region region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,11 +19,20 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.tracer2;
|
package de.steamwar.bausystem.features.tracer2;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import java.util.Map;
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TraceManager {
|
public class TraceManager {
|
||||||
|
/**
|
||||||
|
* Map of all current traces
|
||||||
|
*/
|
||||||
private final Map<Integer, Trace> traces = new HashMap<>();
|
private final Map<Integer, Trace> traces = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility variable to keep track of the next open trace id
|
||||||
|
*/
|
||||||
private int currOpenId = 0;
|
private int currOpenId = 0;
|
||||||
|
|
||||||
/** Adds a new trace to the global record
|
/** Adds a new trace to the global record
|
||||||
@ -31,7 +40,7 @@ public class TraceManager {
|
|||||||
* @param trace Trace to be added
|
* @param trace Trace to be added
|
||||||
* @return id of the newly added trace
|
* @return id of the newly added trace
|
||||||
*/
|
*/
|
||||||
public int add(Trace trace){
|
protected int add(Trace trace){
|
||||||
int id = currOpenId;
|
int id = currOpenId;
|
||||||
traces.put(id, trace);
|
traces.put(id, trace);
|
||||||
currOpenId++;
|
currOpenId++;
|
||||||
@ -53,4 +62,33 @@ public class TraceManager {
|
|||||||
traces.clear();
|
traces.clear();
|
||||||
currOpenId = 1;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren