View Javadoc
1   package org.djutils.data;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.Throw;
6   
7   /**
8    * SimpleColumn implements the Column interface with a single value. <br>
9    * <br>
10   * Copyright (c) 2020-2021 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
11   * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
12   * distributed under a three-clause BSD-style license, which can be found at
13   * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>. <br>
14   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   * @param <T> the value type
18   */
19  public class SimpleDataColumn<T> implements DataColumn<T>, Serializable
20  {
21      /** */
22      private static final long serialVersionUID = 20200229L;
23  
24      /** the column id, preferably without spaces or symbols. */
25      private final String id;
26  
27      /** the column description. */
28      private final String description;
29  
30      /** the value type. */
31      private final Class<T> valueType;
32  
33      /**
34       * Construct a simple, single valued column.
35       * @param id String; the column id, preferably without spaces or symbols
36       * @param description String; the column description
37       * @param valueType Class&lt;T&gt;; the value type
38       */
39      public SimpleDataColumn(final String id, final String description, final Class<T> valueType)
40      {
41          Throw.whenNull(id, "id cannot be null");
42          Throw.when(id.length() == 0, IllegalArgumentException.class, "id cannot be empty");
43          Throw.whenNull(description, "description cannot be null");
44          Throw.whenNull(valueType, "valueType cannot be null");
45          this.id = id;
46          this.description = description;
47          this.valueType = valueType;
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public final String getId()
53      {
54          return this.id;
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public final String getDescription()
60      {
61          return this.description;
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public Class<T> getValueType()
67      {
68          return this.valueType;
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public String toString()
74      {
75          return "SimpleDataColumn [id=" + this.id + ", description=" + this.description + ", valueType=" + this.valueType + "]";
76      }
77  
78  }