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.
9    * <br><br>
10   * Copyright (c) 2020-2020 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>.
14   * <br>
15   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
18   * @param <T> the value type
19   */
20  public class SimpleDataColumn<T> implements DataColumn<T>, Serializable
21  {
22      /** */
23      private static final long serialVersionUID = 20200229L;
24      
25      /** the column id, preferably without spaces or symbols. */
26      private final String id;
27      
28      /** the column description. */
29      private final String description;
30  
31      /** the value type. */
32      private final Class<T> valueType;
33      
34      /**
35       * Construct a simple, single valued column.
36       * @param id String; the column id, preferably without spaces or symbols
37       * @param description String; the column description
38       * @param valueType Class&lt;T&gt;; the value type
39       */
40      public SimpleDataColumn(final String id, final String description, final Class<T> valueType)
41      {
42          Throw.whenNull(id, "id cannot be null");
43          Throw.when(id.length() == 0, IllegalArgumentException.class, "id cannot be empty");
44          Throw.whenNull(description, "description cannot be null");
45          Throw.whenNull(valueType, "valueType cannot be null");
46          this.id = id;
47          this.description = description;
48          this.valueType = valueType;
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public final String getId()
54      {
55          return this.id;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public final String getDescription()
61      {
62          return this.description;
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public Class<T> getValueType()
68      {
69          return this.valueType;
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public String toString()
75      {
76          return "SimpleDataColumn [id=" + this.id + ", description=" + this.description + ", valueType=" + this.valueType + "]";
77      }
78  
79  }
80