View Javadoc
1   package org.opentrafficsim.core.egtf;
2   
3   import java.util.Arrays;
4   import java.util.Map;
5   
6   /**
7    * Class containing processed output data.
8    * <p>
9    * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
11   * <p>
12   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 24 okt. 2018 <br>
13   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
14   */
15  public class FilterDouble implements Filter
16  {
17  
18      /** Grid locations of output data. */
19      private final double[] location;
20  
21      /** Grid times of output data. */
22      private final double[] time;
23  
24      /** Map of all filtered data. */
25      private final Map<Quantity<?, ?>, double[][]> map;
26  
27      /**
28       * Constructor.
29       * @param location double[]; grid locations of output data
30       * @param time double[]; grid times of output data
31       * @param map Map&lt;Quantity&lt;?, ?&gt;, double[][]&gt;; filtered data
32       */
33      protected FilterDouble(final double[] location, final double[] time, final Map<Quantity<?, ?>, double[][]> map)
34      {
35          this.location = location;
36          this.time = time;
37          this.map = map;
38      }
39  
40      /** {@inheritDoc} */
41      @Override
42      public double[] getLocation()
43      {
44          return this.location;
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public double[] getTime()
50      {
51          return this.time;
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public double[][] getSI(final Quantity<?, ?> quantity)
57      {
58          return this.map.get(quantity);
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public <K> K get(final Quantity<?, K> quantity)
64      {
65          if (!this.map.containsKey(quantity))
66          {
67              throw new IllegalStateException(String.format("Filter does not contain data for quantity %s", quantity.getName()));
68          }
69          return quantity.convert(this.map.get(quantity));
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public String toString()
75      {
76          return "Filter [location=" + Arrays.toString(this.location) + ", time=" + Arrays.toString(this.time) + "]";
77      }
78  
79  }