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-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://djutils.org/docs/current/djutils/licenses.html">DJUTILS 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   */
15  public abstract class AbstractDataTable implements DataTable
16  {
17  
18      /** Id. */
19      private final String id;
20  
21      /** Description. */
22      private final String description;
23  
24      /** Columns. */
25      private final ImmutableList<DataColumn<?>> columns;
26  
27      /**
28       * Constructor for the data table using an ImmutableCollection for the columns.
29       * @param id String; id
30       * @param description String; description
31       * @param columns ImmutableList&lt;DataColumn&lt;?&gt;&gt;; columns
32       * @throws NullPointerException when id, description or columns is null
33       * @throws IllegalArgumentException when id is empty or there are zero columns
34       */
35      public AbstractDataTable(final String id, final String description, final ImmutableList<DataColumn<?>> columns)
36      {
37          Throw.whenNull(id, "Id may not be null.");
38          Throw.whenNull(description, "Description may not be null.");
39          Throw.whenNull(columns, "Columns may not be null.");
40          Throw.when(id.length() == 0, IllegalArgumentException.class, "id cannot be empty");
41          Throw.when(columns.size() == 0, IllegalArgumentException.class, "there should be at least one column");
42          this.id = id;
43          this.description = description;
44          this.columns = columns;
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public ImmutableList<DataColumn<?>> getColumns()
50      {
51          return this.columns;
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public String getId()
57      {
58          return this.id;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public String getDescription()
64      {
65          return this.description;
66      }
67  
68  }