Search in sources :

Example 1 with CommandHandlingClass

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);
    }
}
Also used : Set(java.util.Set) Sets(com.google.common.collect.Sets) CommandClass(io.spine.core.CommandClass) ImmutableMap(com.google.common.collect.ImmutableMap) CommandHandlingClass(io.spine.server.command.CommandHandlingClass)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 CommandClass (io.spine.core.CommandClass)1 CommandHandlingClass (io.spine.server.command.CommandHandlingClass)1 Set (java.util.Set)1