View Javadoc
1   package org.djutils.data;
2   
3   import org.djunits.Throw;
4   import org.djutils.immutablecollections.ImmutableList;
5   
6   /**
7    * Abstract {@code Table} implementation taking care of the columns.
8    * <p>
9    * Copyright (c) 2020-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
13   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
14   * @author <a href="https://www.transport.citg.tudelft.nl">Wouter Schakel</a>
15   */
16  public abstract class AbstractDataTable implements DataTable
17  {
18  
19      /** Id. */
20      private final String id;
21      
22      /** Description. */
23      private final String description;
24      
25      /** Columns. */
26      private final ImmutableList<DataColumn<?>> columns;
27      
28      /**
29       * Constructor for the data table using an ImmutableCollection for the columns.
30       * @param id String; id
31       * @param description String; description
32   * @param columns ImmutableList&lt;DataColumn&lt;?&gt;&gt;; columns
33  
34       * @throws NullPointerException when id, description or columns is null
35       * @throws IllegalArgumentException when id is empty or there are zero columns
36       */
37      public AbstractDataTable(final String id, final String description, final ImmutableList<DataColumn<?>> columns)
38      {
39          Throw.whenNull(id, "Id may not be null.");
40          Throw.whenNull(description, "Description may not be null.");
41          Throw.whenNull(columns, "Columns may not be null.");
42          Throw.when(id.length() == 0, IllegalArgumentException.class, "id cannot be empty");
43          Throw.when(columns.size() == 0, IllegalArgumentException.class, "there should be at least one column");
44          this.id = id;
45          this.description = description;
46          this.columns = columns;
47      }
48      
49      /** {@inheritDoc} */
50      @Override
51      public ImmutableList<DataColumn<?>> getColumns()
52      {
53          return this.columns;
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public String getId()
59      {
60          return this.id;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public String getDescription()
66      {
67          return this.description;
68      }
69      
70  }