Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
StatusBus keyed directly by status class (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcahoon authored Sep 9, 2024
1 parent 5d3a245 commit b9add62
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/main/java/com/team766/framework3/StatusBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
public class StatusBus extends LoggingBase {

private static StatusBus s_instance = new StatusBus();
private final Map<String, Status> statuses = new LinkedHashMap<String, Status>();

private static String computeKey(Class<? extends Status> statusClass) {
return statusClass.toString();
}
private final Map<Class<? extends Status>, Status> statuses = new LinkedHashMap<>();

/**
* Get the Singleton instance of the {@link StatusBus}.
Expand All @@ -39,8 +35,7 @@ public static StatusBus getInstance() {
* This method also logs the Status to diagnostic logs.
*/
public void publish(Status status) {
String key = computeKey(status.getClass());
statuses.put(key, status);
statuses.put(status.getClass(), status);
// TODO: also publish to data logs
log("StatusBus received Status (" + status.getClass().getName() + "): " + status);
}
Expand All @@ -56,8 +51,7 @@ public void publish(Status status) {
*/
@SuppressWarnings("unchecked")
public <S extends Status> S getStatus(Class<S> statusClass) {
String key = computeKey(statusClass);
return (S) statuses.get(key);
return (S) statuses.get(statusClass);
}

@Override
Expand Down

0 comments on commit b9add62

Please sign in to comment.