View Javadoc
1   package org.djunits.demo.examples;
2   
3   import org.djunits.unit.AccelerationUnit;
4   import org.djunits.unit.DimensionlessUnit;
5   import org.djunits.unit.DirectionUnit;
6   import org.djunits.unit.DurationUnit;
7   import org.djunits.unit.SpeedUnit;
8   import org.djunits.value.StorageType;
9   import org.djunits.value.ValueException;
10  import org.djunits.value.vdouble.scalar.Dimensionless;
11  import org.djunits.value.vdouble.scalar.Duration;
12  import org.djunits.value.vdouble.scalar.Speed;
13  import org.djunits.value.vdouble.vector.DimensionlessVector;
14  import org.djunits.value.vdouble.vector.DurationVector;
15  import org.djunits.value.vdouble.vector.SpeedVector;
16  import org.djunits.value.vfloat.scalar.FloatAcceleration;
17  import org.djunits.value.vfloat.scalar.FloatDirection;
18  import org.djunits.value.vfloat.vector.FloatAccelerationVector;
19  import org.djunits.value.vfloat.vector.FloatDirectionVector;
20  
21  /**
22   * Tests for min and max.
23   * <p>
24   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * </p>
27   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
28   * initial version May 28, 2016 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
32   */
33  public final class MinAndMax
34  {
35      /** Utility constructor. */
36      private MinAndMax()
37      {
38          //
39      }
40  
41      /**
42       * @param args the arguments for the main program, not used
43       * @throws ValueException on vector error
44       */
45      public static void main(final String[] args) throws ValueException
46      {
47          Speed s1 = new Speed(10.0, SpeedUnit.METER_PER_SECOND);
48          Speed s2 = new Speed(12.0, SpeedUnit.METER_PER_SECOND);
49          Speed s3 = new Speed(8.0, SpeedUnit.METER_PER_SECOND);
50          Speed s4 = new Speed(16.0, SpeedUnit.METER_PER_SECOND);
51          SpeedVector sv = new SpeedVector(new Speed[] { s1, s2, s3, s4 }, StorageType.DENSE);
52          System.out.println("min of " + s1 + " and " + s2 + " = " + Speed.min(s1, s2));
53          System.out.println("max of " + s1 + " and " + s2 + " = " + Speed.max(s1, s2));
54          System.out.println("min of " + sv + " = " + Speed.min(s1, s2, s3, s4));
55          System.out.println("max of " + sv + " = " + Speed.max(s1, s2, s3, s4));
56          System.out.println();
57  
58          FloatAcceleration fa1 = new FloatAcceleration(10.0, AccelerationUnit.METER_PER_SECOND_2);
59          FloatAcceleration fa2 = new FloatAcceleration(12.0, AccelerationUnit.METER_PER_SECOND_2);
60          FloatAcceleration fa3 = new FloatAcceleration(8.0, AccelerationUnit.METER_PER_SECOND_2);
61          FloatAcceleration fa4 = new FloatAcceleration(16.0, AccelerationUnit.METER_PER_SECOND_2);
62          FloatAccelerationVector fav =
63                  new FloatAccelerationVector(new FloatAcceleration[] { fa1, fa2, fa3, fa4 }, StorageType.DENSE);
64          System.out.println("min of " + fa1 + " and " + fa2 + " = " + FloatAcceleration.min(fa1, fa2));
65          System.out.println("max of " + fa1 + " and " + fa2 + " = " + FloatAcceleration.max(fa1, fa2));
66          System.out.println("min of " + fav + " = " + FloatAcceleration.min(fa1, fa2, fa3, fa4));
67          System.out.println("max of " + fav + " = " + FloatAcceleration.max(fa1, fa2, fa3, fa4));
68          System.out.println();
69  
70          Duration t1 = new Duration(10.0, DurationUnit.MINUTE);
71          Duration t2 = new Duration(12.0, DurationUnit.MINUTE);
72          Duration t3 = new Duration(8.0, DurationUnit.MINUTE);
73          Duration t4 = new Duration(16.0, DurationUnit.MINUTE);
74          DurationVector tv = new DurationVector(new Duration[] { t1, t2, t3, t4 }, StorageType.DENSE);
75          System.out.println("min of " + t1 + " and " + t2 + " = " + Duration.min(t1, t2));
76          System.out.println("max of " + t1 + " and " + t2 + " = " + Duration.max(t1, t2));
77          System.out.println("min of " + tv + " = " + Duration.min(t1, t2, t3, t4));
78          System.out.println("max of " + tv + " = " + Duration.max(t1, t2, t3, t4));
79          System.out.println();
80  
81          FloatDirection fd1 = new FloatDirection(10.0, DirectionUnit.NORTH_DEGREE);
82          FloatDirection fd2 = new FloatDirection(12.0, DirectionUnit.NORTH_DEGREE);
83          FloatDirection fd3 = new FloatDirection(8.0, DirectionUnit.NORTH_DEGREE);
84          FloatDirection fd4 = new FloatDirection(16.0, DirectionUnit.NORTH_DEGREE);
85          FloatDirectionVector fdv =
86                  new FloatDirectionVector(new FloatDirection[] { fd1, fd2, fd3, fd4 }, StorageType.DENSE);
87          System.out.println("min of " + fd1 + " and " + fd2 + " = " + FloatDirection.min(fd1, fd2));
88          System.out.println("max of " + fd1 + " and " + fd2 + " = " + FloatDirection.max(fd1, fd2));
89          System.out.println("min of " + fdv + " = " + FloatDirection.min(fd1, fd2, fd3, fd4));
90          System.out.println("max of " + fdv + " = " + FloatDirection.max(fd1, fd2, fd3, fd4));
91          System.out.println();
92  
93          Dimensionless d1 = new Dimensionless(10.0, DimensionlessUnit.SI);
94          Dimensionless d2 = new Dimensionless(12.0, DimensionlessUnit.SI);
95          Dimensionless d3 = new Dimensionless(8.0, DimensionlessUnit.SI);
96          Dimensionless d4 = new Dimensionless(16.0, DimensionlessUnit.SI);
97          DimensionlessVector dv = new DimensionlessVector(new Dimensionless[] { d1, d2, d3, d4 }, StorageType.DENSE);
98          System.out.println("min of " + d1 + " and " + d2 + " = " + Dimensionless.min(d1, d2));
99          System.out.println("max of " + d1 + " and " + d2 + " = " + Dimensionless.max(d1, d2));
100         System.out.println("min of " + dv + " = " + Dimensionless.min(d1, d2, d3, d4));
101         System.out.println("max of " + dv + " = " + Dimensionless.max(d1, d2, d3, d4));
102         System.out.println();
103 
104     }
105 
106 }