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-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   */
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      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      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      /** {@inheritDoc} */
76      @Override
77      public int hashCode()
78      {
79          final int prime = 31;
80          int result = 1;
81          result = prime * result + this.description.hashCode();
82          result = prime * result + this.name.hashCode();
83          result = prime * result + this.objectClass.getName().hashCode();
84          return result;
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      @SuppressWarnings("checkstyle:needbraces")
90      public boolean equals(final Object obj)
91      {
92          if (this == obj)
93              return true;
94          if (obj == null)
95              return false;
96          if (getClass() != obj.getClass())
97              return false;
98          ObjectDescriptororg/djutils/metadata/ObjectDescriptor.html#ObjectDescriptor">ObjectDescriptor other = (ObjectDescriptor) obj;
99          if (!this.description.equals(other.description))
100             return false;
101         if (!this.name.equals(other.name))
102             return false;
103         if (!this.objectClass.equals(other.objectClass))
104             return false;
105         return true;
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     public String toString()
111     {
112         return "ObjectDescriptor [name=" + this.name + ", description=" + this.description + ", objectClass=" + this.objectClass
113                 + "]";
114     }
115 
116 }