SpeedLimitType.java

  1. package org.opentrafficsim.road.network.speed;

  2. import java.io.Serializable;

  3. import org.djutils.exceptions.Throw;
  4. import org.opentrafficsim.base.Identifiable;
  5. import org.opentrafficsim.base.Type;

  6. /**
  7.  * Defines the type of a speed limit, resulting in different behavior.
  8.  * <p>
  9.  * Copyright (c) 2013-2023 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/license.html">OpenTrafficSim License</a>.
  11.  * </p>
  12.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  13.  * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
  14.  * @param <T> Class of speed info that is linked to the speed limit type.
  15.  */
  16. public class SpeedLimitType<T> implements Serializable, Identifiable, Type<SpeedLimitType<T>>
  17. {

  18.     /** */
  19.     private static final long serialVersionUID = 20160501L;

  20.     /** Id of this speed limit type. */
  21.     private final String id;

  22.     /** Class of the info related to this speed limit type. */
  23.     private final Class<T> infoClass;

  24.     /**
  25.      * Constructor.
  26.      * @param id String; id of this speed limit type, which must be unique
  27.      * @param infoClass Class&lt;T&gt;; class of the info related to this speed limit type
  28.      * @throws NullPointerException if id or info class is null
  29.      */
  30.     public SpeedLimitType(final String id, final Class<T> infoClass)
  31.     {
  32.         Throw.whenNull(id, "Id may not be null.");
  33.         Throw.whenNull(infoClass, "Info class may not be null.");
  34.         this.id = id;
  35.         this.infoClass = infoClass;
  36.     }

  37.     /**
  38.      * Returns the id.
  39.      * @return the id
  40.      */
  41.     @Override
  42.     public final String getId()
  43.     {
  44.         return this.id;
  45.     }

  46.     /**
  47.      * Returns the class of the info related to this speed limit type.
  48.      * @return class of the info related to this speed limit type
  49.      */
  50.     public final Class<T> getInfoClass()
  51.     {
  52.         return this.infoClass;
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public final int hashCode()
  57.     {
  58.         final int prime = 31;
  59.         int result = 1;
  60.         result = prime * result + this.id.hashCode();
  61.         result = prime * result + this.infoClass.hashCode();
  62.         return result;
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public final boolean equals(final Object obj)
  67.     {
  68.         if (this == obj)
  69.         {
  70.             return true;
  71.         }
  72.         if (obj == null)
  73.         {
  74.             return false;
  75.         }
  76.         if (getClass() != obj.getClass())
  77.         {
  78.             return false;
  79.         }
  80.         SpeedLimitType<?> other = (SpeedLimitType<?>) obj;
  81.         if (!this.id.equals(other.id))
  82.         {
  83.             return false;
  84.         }
  85.         if (!this.infoClass.equals(other.infoClass))
  86.         {
  87.             return false;
  88.         }
  89.         return true;
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     @SuppressWarnings("checkstyle:designforextension")
  94.     public String toString()
  95.     {
  96.         return "SpeedLimitType [" + this.id + "]";
  97.     }

  98. }