Skip to content

Commit

Permalink
Extend pattern matching of modern Java
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed May 17, 2024
1 parent 76615a8 commit 706ad77
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public static Duration tickToDuration(int tick) {
*/
public static List<RegisteredEvent> registerEvents(List<Source> sources, List<Event> events) {
final AtomicInteger tick = new AtomicInteger(0);
final AtomicInteger clientId = new AtomicInteger(-1);
final AtomicInteger commandSourceId = new AtomicInteger(-1);

return events.stream().map((event) -> switch (event) {
case Event.Advance e -> {
tick.addAndGet(e.ticksToAdvance());
case Event.Advance(int ticksToAdvance) -> {
tick.addAndGet(ticksToAdvance);
yield null;
}

case Event.SetCommandSource e -> {
clientId.set(e.playerIndex());
case Event.SetCommandSource (int playerIndex) -> {
commandSourceId.set(playerIndex);
yield null;
}

default -> new RegisteredEvent(tick.intValue(), sources.get(clientId.intValue()), event);
default -> new RegisteredEvent(tick.intValue(), sources.get(commandSourceId.intValue()), event);
}).filter(Objects::nonNull).toList();
}

Expand Down

0 comments on commit 706ad77

Please sign in to comment.