View Javadoc
1   package org.djutils.metadata;
2   
3   import java.io.Serializable;
4   
5   import org.djutils.exceptions.Throw;
6   
7   /**
8    * ObjectDescriptor: wrapper for name, description and class of one object. <br>
9    * <br>
10   * Copyright (c) 2020-2024 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   */
17  public class ObjectDescriptor implements Serializable
18  {
19      /** ... */
20      private static final long serialVersionUID = 20200417L;
21  
22      /** Name. */
23      private final String name;
24  
25      /** Description. */
26      private final String description;
27  
28      /** Class. */
29      private final Class<?> objectClass;
30  
31      /**
32       * Construct a new FieldDescription object.
33       * @param name String; name of the object
34       * @param description String; description of the object
35       * @param objectClass Class&lt;?&gt;; class of the object
36       */
37      public ObjectDescriptor(final String name, final String description, final Class<?> objectClass)
38      {
39          Throw.whenNull(name, "name may not be null");
40          Throw.when(name.length() == 0, IllegalArgumentException.class, "empty name is not allowed");
41          Throw.whenNull(description, "description may not be null");
42          Throw.whenNull(objectClass, "objectClass may not be null");
43          this.name = name;
44          this.description = description;
45          this.objectClass = objectClass;
46      }
47  
48      /**
49       * Retrieve the name of the object.
50       * @return String; description of the object
51       */
52      public String getName()
53      {
54          return this.name;
55      }
56  
57      /**
58       * Retrieve the description of the object.
59       * @return String; description of the object
60       */
61      public String getDescription()
62      {
63          return this.description;
64      }
65  
66      /**
67       * Retrieve the Class of the object.
68       * @return String; class name of the object
69       */
70      public Class<?> getObjectClass()
71      {
72          return this.objectClass;
73      }
74  
75      @Override
76      public int hashCode()
77      {
78          final int prime = 31;
79          int result = 1;
80          result = prime * result + this.description.hashCode();
81          result = prime * result + this.name.hashCode();
82          result = prime * result + this.objectClass.getName().hashCode();
83          return result;
84      }
85  
86      @Override
87      @SuppressWarnings("checkstyle:needbraces")
88      public boolean equals(final Object obj)
89      {
90          if (this == obj)
91              return true;
92          if (obj == null)
93              return false;
94          if (getClass() != obj.getClass())
95              return false;
96          ObjectDescriptor other = (ObjectDescriptor) obj;
97          if (!this.description.equals(other.description))
98              return false;
99          if (!this.name.equals(other.name))
100             return false;
101         if (!this.objectClass.equals(other.objectClass))
102             return false;
103         return true;
104     }
105 
106     @Override
107     public String toString()
108     {
109         return "ObjectDescriptor [name=" + this.name + ", description=" + this.description + ", objectClass=" + this.objectClass
110                 + "]";
111     }
112 
113 }