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-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 7 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>. 8 * <p> 9 * @version $Revision$, $LastChangedDate$, by $Author$, initial version 19 jan. 2018 <br> 10 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 11 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 12 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a> 13 */ 14 public interface Parameters 15 { 16 17 /** 18 * Set parameter value of given parameter type. 19 * @param parameterType AbstractParameterType<T>; the parameter type. 20 * @param value T; new value for the parameter of type <code>parameterType</code>. 21 * @param <T> Class of value. 22 * @throws ParameterException If the value does not comply with value type constraints. 23 */ 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 AbstractParameterType<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 AbstractParameterType<T>; 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 AbstractParameterType<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 <T> T getParameter(ParameterType<T> parameterType) throws ParameterException; 50 51 /** 52 * Returns a parameter value, or {@code null} if not present. This can be used to prevent frequent calls to both 53 * {@code contains()} and {@code getParameter()} in performance critical code. 54 * @param parameterType ParameterType<T>; parameter type 55 * @param <T> type of parameter value 56 * @return parameter value, or {@code null} if not present 57 */ 58 <T> T getParameterOrNull(ParameterType<T> parameterType); 59 60 /** 61 * Indicate whether the given parameter type has been set. 62 * @param parameterType AbstractParameterType<T>; the parameter type to check 63 * @return boolean; true if <code>parameterType</code> has been set; false if <code>parameterType</code> has not been set 64 */ 65 boolean contains(ParameterType<?> parameterType); 66 67 /** 68 * Sets the parameters of this set in the given set. 69 * @param parameters Parameters; parameters to set the values in 70 */ 71 void setAllIn(Parameters parameters); 72 73 }