s.getProblemInstanceId()); return new ScenarioController(sim, clockController, s, ImmutableMap.copyOf(m), getNumberOfTicks());
s.getProblemInstanceId()); return new ScenarioController(sim, clockController, s, ImmutableMap.copyOf(m), getNumberOfTicks());
/** * Adds the map of {@link Class} to {@link TimedEventHandler} to the * builder. * @param entries The event handler mapping. * @return A new builder instance with the specified handlers added. */ public Builder withEventHandlers( Map<Class<? extends TimedEvent>, TimedEventHandler<?>> entries) { for (final Entry<Class<? extends TimedEvent>, TimedEventHandler<?>> entry : entries .entrySet()) { checkHandlerType(entry.getClass()); } return create( getScenario(), ImmutableMap .<Class<? extends TimedEvent>, TimedEventHandler<?>>builder() .putAll(getEventHandlers()) .putAll(entries) .build(), getNumberOfTicks(), getStopModelBuilder(), isIgnoreRedundantHandlers()); }
/** * Adds the map of {@link Class} to {@link TimedEventHandler} to the * builder. * @param entries The event handler mapping. * @return A new builder instance with the specified handlers added. */ public Builder withEventHandlers( Map<Class<? extends TimedEvent>, TimedEventHandler<?>> entries) { for (final Entry<Class<? extends TimedEvent>, TimedEventHandler<?>> entry : entries .entrySet()) { checkHandlerType(entry.getClass()); } return create( getScenario(), ImmutableMap .<Class<? extends TimedEvent>, TimedEventHandler<?>>builder() .putAll(getEventHandlers()) .putAll(entries) .build(), getNumberOfTicks(), getStopModelBuilder(), isIgnoreRedundantHandlers()); }
/** * Adds an additional stop condition to the controller in OR fashion. The * first stop condition is defined by {@link Scenario#getStopCondition()}. * @param stp The builder that constructs the {@link StopCondition}. * @return A new {@link Builder} instance. * @see StopConditions */ @CheckReturnValue public Builder withOrStopCondition(StopCondition stp) { final StopModelBuilder smb; if (getStopModelBuilder().stopCondition().equals( StopConditions.alwaysFalse())) { smb = StopModelBuilder.create(stp); } else { smb = StopModelBuilder.create(StopConditions.or(getStopModelBuilder() .stopCondition(), stp)); } return create(getScenario(), getEventHandlers(), getNumberOfTicks(), smb, isIgnoreRedundantHandlers()); }
/** * Adds an additional stop condition to the controller in AND fashion. The * first stop condition is defined by {@link Scenario#getStopCondition()}. * @param stp The builder that constructs the {@link StopCondition}. * @return A new {@link Builder} instance. * @see StopConditions */ @CheckReturnValue public Builder withAndStopCondition(StopCondition stp) { final StopModelBuilder smb; if (getStopModelBuilder().stopCondition().equals( StopConditions.alwaysFalse())) { smb = StopModelBuilder.create(stp); } else { smb = StopModelBuilder.create(StopConditions.and(getStopModelBuilder() .stopCondition(), stp)); } return create(getScenario(), getEventHandlers(), getNumberOfTicks(), smb, isIgnoreRedundantHandlers()); }
/** * Adds an additional stop condition to the controller in AND fashion. The * first stop condition is defined by {@link Scenario#getStopCondition()}. * @param stp The builder that constructs the {@link StopCondition}. * @return A new {@link Builder} instance. * @see StopConditions */ @CheckReturnValue public Builder withAndStopCondition(StopCondition stp) { final StopModelBuilder smb; if (getStopModelBuilder().stopCondition().equals( StopConditions.alwaysFalse())) { smb = StopModelBuilder.create(stp); } else { smb = StopModelBuilder.create(StopConditions.and(getStopModelBuilder() .stopCondition(), stp)); } return create(getScenario(), getEventHandlers(), getNumberOfTicks(), smb, isIgnoreRedundantHandlers()); }
/** * Adds an additional stop condition to the controller in OR fashion. The * first stop condition is defined by {@link Scenario#getStopCondition()}. * @param stp The builder that constructs the {@link StopCondition}. * @return A new {@link Builder} instance. * @see StopConditions */ @CheckReturnValue public Builder withOrStopCondition(StopCondition stp) { final StopModelBuilder smb; if (getStopModelBuilder().stopCondition().equals( StopConditions.alwaysFalse())) { smb = StopModelBuilder.create(stp); } else { smb = StopModelBuilder.create(StopConditions.or(getStopModelBuilder() .stopCondition(), stp)); } return create(getScenario(), getEventHandlers(), getNumberOfTicks(), smb, isIgnoreRedundantHandlers()); }
/** * Add a {@link TimedEventHandler} to the controller that handles * {@link TimedEvent}s of the specified type. * @param type The type of event to handle. * @param handler The handler that handles the event. * @param <T> The type of event to handle. * @return A new {@link Builder} instance. * @throws IllegalArgumentException If an interface class is provided. */ @CheckReturnValue public <T extends TimedEvent> Builder withEventHandler(Class<T> type, TimedEventHandler<T> handler) { checkHandlerType(type); return create( getScenario(), ImmutableMap .<Class<? extends TimedEvent>, TimedEventHandler<?>>builder() .putAll(getEventHandlers()).put(type, handler).build(), getNumberOfTicks(), getStopModelBuilder(), isIgnoreRedundantHandlers()); }
/** * Add a {@link TimedEventHandler} to the controller that handles * {@link TimedEvent}s of the specified type. * @param type The type of event to handle. * @param handler The handler that handles the event. * @param <T> The type of event to handle. * @return A new {@link Builder} instance. * @throws IllegalArgumentException If an interface class is provided. */ @CheckReturnValue public <T extends TimedEvent> Builder withEventHandler(Class<T> type, TimedEventHandler<T> handler) { checkHandlerType(type); return create( getScenario(), ImmutableMap .<Class<? extends TimedEvent>, TimedEventHandler<?>>builder() .putAll(getEventHandlers()).put(type, handler).build(), getNumberOfTicks(), getStopModelBuilder(), isIgnoreRedundantHandlers()); }
/** * Change the behavior of handling redundant handlers. A redundant handler * is a {@link TimedEventHandler} that handles an {@link TimedEvent} type * that does not occur in the specified {@link Scenario}, it is therefore * redundant. By default, adding a redundant {@link TimedEventHandler} * yields a {@link IllegalStateException}. By calling this method with * <code>true</code> this exception can be suppressed. * @param ignore If <code>true</code> redundant handlers are ignored, * otherwise redundant handlers will generate a * {@link IllegalStateException}. * @return A new {@link Builder} instance. */ @CheckReturnValue public Builder withIgnoreRedundantHandlers(boolean ignore) { return create(getScenario(), getEventHandlers(), getNumberOfTicks(), getStopModelBuilder(), ignore); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ScenarioController.Builder) { ScenarioController.Builder that = (ScenarioController.Builder) o; return (this.scenario.equals(that.getScenario())) && (this.eventHandlers.equals(that.getEventHandlers())) && (this.numberOfTicks == that.getNumberOfTicks()) && (this.stopModelBuilder.equals(that.getStopModelBuilder())) && (this.ignoreRedundantHandlers == that.isIgnoreRedundantHandlers()); } return false; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ScenarioController.Builder) { ScenarioController.Builder that = (ScenarioController.Builder) o; return (this.scenario.equals(that.getScenario())) && (this.eventHandlers.equals(that.getEventHandlers())) && (this.numberOfTicks == that.getNumberOfTicks()) && (this.stopModelBuilder.equals(that.getStopModelBuilder())) && (this.ignoreRedundantHandlers == that.isIgnoreRedundantHandlers()); } return false; }
/** * Change the behavior of handling redundant handlers. A redundant handler * is a {@link TimedEventHandler} that handles an {@link TimedEvent} type * that does not occur in the specified {@link Scenario}, it is therefore * redundant. By default, adding a redundant {@link TimedEventHandler} * yields a {@link IllegalStateException}. By calling this method with * <code>true</code> this exception can be suppressed. * @param ignore If <code>true</code> redundant handlers are ignored, * otherwise redundant handlers will generate a * {@link IllegalStateException}. * @return A new {@link Builder} instance. */ @CheckReturnValue public Builder withIgnoreRedundantHandlers(boolean ignore) { return create(getScenario(), getEventHandlers(), getNumberOfTicks(), getStopModelBuilder(), ignore); }