/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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); }
/** * 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); }
static Builder create(Scenario scen) { final int ticks = scen.getTimeWindow().end() == Long.MAX_VALUE ? -1 : (int) (scen.getTimeWindow().end() - scen.getTimeWindow().begin()); return create( scen, ImmutableMap.<Class<? extends TimedEvent>, TimedEventHandler<?>>of(), ticks, StopModelBuilder.create(scen.getStopCondition()), false); }
/** * Limits the simulation to the specified number of ticks. * @param ticks The number of ticks run, when negative the number of ticks * is infinite. * @return A new {@link Builder} instance. */ @CheckReturnValue public Builder withNumberOfTicks(int ticks) { return create(getScenario(), getEventHandlers(), ticks, getStopModelBuilder(), isIgnoreRedundantHandlers()); }
/** * Creates a {@link Builder} for {@link ScenarioController}. * @param scenario The scenario to control. * @return A new {@link Builder}. */ public static Builder builder(Scenario scenario) { return Builder.create(scenario); }
/** * Limits the simulation to the specified number of ticks. * @param ticks The number of ticks run, when negative the number of ticks * is infinite. * @return A new {@link Builder} instance. */ @CheckReturnValue public Builder withNumberOfTicks(int ticks) { return create(getScenario(), getEventHandlers(), ticks, getStopModelBuilder(), isIgnoreRedundantHandlers()); }
static Builder create(Scenario scen) { final int ticks = scen.getTimeWindow().end() == Long.MAX_VALUE ? -1 : (int) (scen.getTimeWindow().end() - scen.getTimeWindow().begin()); return create( scen, ImmutableMap.<Class<? extends TimedEvent>, TimedEventHandler<?>>of(), ticks, StopModelBuilder.create(scen.getStopCondition()), false); }
/** * Creates a {@link Builder} for {@link ScenarioController}. * @param scenario The scenario to control. * @return A new {@link Builder}. */ public static Builder builder(Scenario scenario) { return Builder.create(scenario); }