View Javadoc
1   package org.djutils.metadata;
2   
3   import org.djutils.exceptions.Throw;
4   
5   /**
6    * ObjectDescriptor: wrapper for name, description and class of one object. <br>
7    * <br>
8    * Copyright (c) 2020-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
9    * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
10   * distributed under a three-clause BSD-style license, which can be found at
11   * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>. <br>
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 class ObjectDescriptor
16  {
17      /** Name. */
18      private final String name;
19  
20      /** Description. */
21      private final String description;
22  
23      /** Class. */
24      private final Class<?> objectClass;
25  
26      /**
27       * Construct a new FieldDescription object.
28       * @param name name of the object
29       * @param description description of the object
30       * @param objectClass class of the object
31       */
32      public ObjectDescriptor(final String name, final String description, final Class<?> objectClass)
33      {
34          Throw.whenNull(name, "name may not be null");
35          Throw.when(name.length() == 0, IllegalArgumentException.class, "empty name is not allowed");
36          Throw.whenNull(description, "description may not be null");
37          Throw.whenNull(objectClass, "objectClass may not be null");
38          this.name = name;
39          this.description = description;
40          this.objectClass = objectClass;
41      }
42  
43      /**
44       * Retrieve the name of the object.
45       * @return description of the object
46       */
47      public String getName()
48      {
49          return this.name;
50      }
51  
52      /**
53       * Retrieve the description of the object.
54       * @return description of the object
55       */
56      public String getDescription()
57      {
58          return this.description;
59      }
60  
61      /**
62       * Retrieve the Class of the object.
63       * @return class name of the object
64       */
65      public Class<?> getObjectClass()
66      {
67          return this.objectClass;
68      }
69  
70      @Override
71      public int hashCode()
72      {
73          final int prime = 31;
74          int result = 1;
75          result = prime * result + this.description.hashCode();
76          result = prime * result + this.name.hashCode();
77          result = prime * result + this.objectClass.getName().hashCode();
78          return result;
79      }
80  
81      @Override
82      @SuppressWarnings("checkstyle:needbraces")
83      public boolean equals(final Object obj)
84      {
85          if (this == obj)
86              return true;
87          if (obj == null)
88              return false;
89          if (getClass() != obj.getClass())
90              return false;
91          ObjectDescriptor other = (ObjectDescriptor) obj;
92          if (!this.description.equals(other.description))
93              return false;
94          if (!this.name.equals(other.name))
95              return false;
96          if (!this.objectClass.equals(other.objectClass))
97              return false;
98          return true;
99      }
100 
101     @Override
102     public String toString()
103     {
104         return "ObjectDescriptor [name=" + this.name + ", description=" + this.description + ", objectClass=" + this.objectClass
105                 + "]";
106     }
107 
108 }