1 package org.opentrafficsim.base.parameters; 2 3 /** 4 * Interface for parameter objects containing the methods for during a simulation. 5 * <p> 6 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 7 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 8 * </p> 9 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a> 10 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a> 11 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a> 12 */ 13 public interface Parameters 14 { 15 16 /** 17 * Set parameter value of given parameter type. 18 * @param parameterType ParameterType<T>; the parameter type. 19 * @param value T; new value for the parameter of type <code>parameterType</code>. 20 * @param <T> Class of value. 21 * @throws ParameterException If the value does not comply with value type constraints. 22 */ 23 // @docs/06-behavior/parameters.md (without throws) 24 <T> void setParameter(ParameterType<T> parameterType, T value) throws ParameterException; 25 26 /** 27 * Set parameter value of given parameter type, store old value to allow a reset. 28 * @param parameterType ParameterType<T>; the parameter type. 29 * @param value T; new value for the parameter of type <code>parameterType</code>. 30 * @param <T> Class of value. 31 * @throws ParameterException If the value does not comply with value type constraints. 32 */ 33 <T> void setParameterResettable(ParameterType<T> parameterType, T value) throws ParameterException; 34 35 /** 36 * Resets the parameter value to the value from before the last set. This goes only a single value back. 37 * @param parameterType ParameterType<?>; the parameter type. 38 * @throws ParameterException If the parameter was never set. 39 */ 40 void resetParameter(ParameterType<?> parameterType) throws ParameterException; 41 42 /** 43 * Get parameter of given type. 44 * @param parameterType ParameterType<T>; the parameter type. 45 * @param <T> Class of value. 46 * @return T; parameter of the requested type if it exists 47 * @throws ParameterException If the parameter was never set. 48 */ 49 // @docs/06-behavior/parameters.md (without throws) 50 <T> T getParameter(ParameterType<T> parameterType) throws ParameterException; 51 52 /** 53 * Returns a parameter value, or {@code null} if not present. This can be used to prevent frequent calls to both 54 * {@code contains()} and {@code getParameter()} in performance critical code. 55 * @param parameterType ParameterType<T>; parameter type 56 * @param <T> type of parameter value 57 * @return parameter value, or {@code null} if not present 58 */ 59 <T> T getParameterOrNull(ParameterType<T> parameterType); 60 61 /** 62 * Indicate whether the given parameter type has been set. 63 * @param parameterType ParameterType<?>; the parameter type to check 64 * @return boolean; true if <code>parameterType</code> has been set; false if <code>parameterType</code> has not been set 65 */ 66 boolean contains(ParameterType<?> parameterType); 67 68 /** 69 * Sets the parameters of this set in the given set. 70 * @param parameters Parameters; parameters to set the values in 71 */ 72 void setAllIn(Parameters parameters); 73 74 }