use of io.spine.server.command.CommandHandlingClass in project core-java by SpineEventEngine.
the class Model method checkDuplicates.
private void checkDuplicates(CommandHandlingClass candidate) throws DuplicateCommandHandlerError {
final Set<CommandClass> candidateCommands = candidate.getCommands();
final ImmutableMap.Builder<Set<CommandClass>, CommandHandlingClass> map = ImmutableMap.builder();
for (ModelClass<?> modelClass : classes.values()) {
if (modelClass instanceof CommandHandlingClass) {
final CommandHandlingClass commandHandler = (CommandHandlingClass) modelClass;
final Set<CommandClass> commandClasses = commandHandler.getCommands();
final Sets.SetView<CommandClass> intersection = Sets.intersection(commandClasses, candidateCommands);
if (intersection.size() > 0) {
map.put(intersection, commandHandler);
}
}
}
final ImmutableMap<Set<CommandClass>, CommandHandlingClass> currentHandlers = map.build();
if (!currentHandlers.isEmpty()) {
throw new DuplicateCommandHandlerError(candidate, currentHandlers);
}
}
Aggregations