View Javadoc

    1   /*
    2    * @(#)TimeUnit.java Feb 1, 2003
    3    *
    4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
    5    * the Netherlands All rights reserved.
    6    *
    7    * This software is proprietary information of Delft University of Technology
    8    * The code is published under the General Public License
    9    */
    10  package nl.tudelft.simulation.dsol.experiment;
    11
    12  import java.rmi.RemoteException;
    13
    14  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
    15
    16  /***
    17   * The TimeUnitInterface defines the simulator time units. <br>
    18   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
    19   * University of Technology </a>, the Netherlands. <br>
    20   * See for project information <a
    21   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
    22   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
    23   * License (GPL) </a>, no warranty <br>
    24   *
    25   * @version 2.0 21.09.2003 <br>
    26   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
    27   *         Jacobs </a>, <a
    28   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
    29   *         Verbraeck </a>
    30   */
    31  public class TimeUnit implements TimeUnitInterface
    32  {
    33
    34  	/***
    35  	 * value represents the value relative to the number of miliseconds
    36  	 *
    37  	 * @uml.property name="value"
    38  	 */
    39  	private long value;
    40
    41
    42  	/*** name represents the name of the time unit */
    43  	private String name;
    44
    45  	/***
    46  	 * Method Speed.
    47  	 *
    48  	 * @param value represents the number of miliseconds
    49  	 * @param name The name that will show up in reports and animation
    50  	 */
    51  	public TimeUnit(final long value, final String name)
    52  	{
    53  		super();
    54  		this.value = value;
    55  		this.name = name;
    56  	}
    57
    58  	/***
    59  	 * @see nl.tudelft.simulation.dsol.experiment.TimeUnitInterface#getValue()
    60  	 *
    61  	 * @uml.property name="value"
    62  	 */
    63  	public long getValue()
    64  	{
    65  		return this.value;
    66  	}
    67
    68  	/***
    69  	 * @see java.lang.Object#toString()
    70  	 */
    71  	public String toString()
    72  	{
    73  		return this.name;
    74  	}
    75
    76  	/***
    77  	 * converts amount units to the units of the simulator
    78  	 *
    79  	 * @param amount the amount to convert
    80  	 * @param units the units of the amount
    81  	 * @param simulator the simulator
    82  	 * @return double the amount in simulator units
    83  	 * @throws RemoteException on network exception
    84  	 */
    85  	public static double convert(final double amount,
    86  			final TimeUnitInterface units, final SimulatorInterface simulator)
    87  			throws RemoteException
    88  	{
    89  		return TimeUnit.convert(amount, units, simulator.getReplication()
    90  				.getRunControl().getTreatment().getTimeUnit());
    91  	}
    92
    93  	/***
    94  	 * converts amount units to the target units
    95  	 *
    96  	 * @param amount the amount to convert
    97  	 * @param units the units of the amount
    98  	 * @param targetUnits the units to convert to
    99  	 * @return double the amount in simulator units
    100 	 */
    101 	public static double convert(final double amount,
    102 			final TimeUnitInterface units, final TimeUnitInterface targetUnits)
    103 	{
    104 		double fraction = (double) targetUnits.getValue()
    105 				/ (double) units.getValue();
    106 		return amount / fraction;
    107 	}
    108 }