View Javadoc
1   package org.opentrafficsim.core.egtf.typed;
2   
3   import org.djunits.unit.DurationUnit;
4   import org.djunits.unit.LengthUnit;
5   import org.djunits.value.StorageType;
6   import org.djunits.value.vdouble.vector.DurationVector;
7   import org.djunits.value.vdouble.vector.LengthVector;
8   import org.djutils.exceptions.Try;
9   import org.opentrafficsim.core.egtf.Filter;
10  import org.opentrafficsim.core.egtf.Quantity;
11  
12  /**
13   * Typed version of a kernel.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 27 okt. 2018 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  public class TypedFilter implements Filter
24  {
25  
26      /** Filter. */
27      private final Filter filter;
28  
29      /**
30       * Constructor.
31       * @param filter Filter; wrapped filter
32       */
33      TypedFilter(final Filter filter)
34      {
35          this.filter = filter;
36      }
37  
38      /** {@inheritDoc} */
39      @Override
40      public double[] getLocation()
41      {
42          return this.filter.getLocation();
43      }
44  
45      /**
46       * Returns the grid location.
47       * @return LengthVector; grid location
48       */
49      public LengthVector getLocationVector()
50      {
51          return Try.assign(() -> new LengthVector(getLocation(), LengthUnit.SI, StorageType.DENSE),
52                  "Exception while creating LengthVector");
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public double[] getTime()
58      {
59          return this.filter.getTime();
60      }
61  
62      /**
63       * Returns the grid time.
64       * @return DurationVector; grid time
65       */
66      public DurationVector getTimeVector()
67      {
68          return Try.assign(() -> new DurationVector(getTime(), DurationUnit.SI, StorageType.DENSE),
69                  "Exception while creating DurationVector");
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public double[][] getSI(final Quantity<?, ?> quantity)
75      {
76          return this.filter.getSI(quantity);
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public <K> K get(final Quantity<?, K> quantity)
82      {
83          return this.filter.get(quantity);
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public String toString()
89      {
90          return "TypedFilter [filter=" + this.filter + "]";
91      }
92  
93  }