Skip to content

Refactor GameCommand Lists with Key into Multimaps #9829

@Hanmac

Description

@Hanmac

Cases like this:

public final void addCastCommand(final String valid, final GameCommand c) {
if (commandList.containsKey(valid)) {
commandList.get(valid).add(0, c);
} else {
commandList.put(valid, Lists.newArrayList(c));
}
}
private void executeCastCommand(final Card cast) {
for (Entry<String, List<GameCommand>> ev : commandList.entrySet()) {
if (cast.getType().hasStringType(ev.getKey())) {
execute(ev.getValue());
}
}
}
private static void execute(final List<GameCommand> c) {
final int length = c.size();
for (int i = 0; i < length; i++) {
c.remove(0).run();
}
}

  • First: why are the GameCommands are added in the front? That doesn't make much sense. (see later point)
  • Second: why does execute removes them like that? Wouldn't it be better to iterate over the whole list, and then clean up all entries for the given key? (that might be problematic with new GameCommands added in the front? See above)

another example are player specific Phase Commands:

private final HashMap<Player, ArrayList<GameCommand>> untilMap = new HashMap<>();
private final HashMap<Player, ArrayList<GameCommand>> untilEndMap = new HashMap<>();
private final HashMap<Player, ArrayList<GameCommand>> registerMap = new HashMap<>();

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions