View Javadoc
1   package nl.tudelft.simulation.introspection.beans;
2   
3   import java.beans.PropertyDescriptor;
4   
5   /**
6    * Utility class for bean tests.
7    * <p>
8    * Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
9    * for project information <a href="https://simulation.tudelft.nl/" target="_blank"> https://simulation.tudelft.nl</a>. The DSOL
10   * project is distributed under a three-clause BSD-style license, which can be found at
11   * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">
12   * https://https://simulation.tudelft.nl/dsol/docs/latest/license.html</a>.
13   * </p>
14   * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a>
15   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author Niels Lang.
17   * @since 1.5
18   */
19  
20  public class BeanUtils extends Object
21  {
22      /**
23       * resolves whether the bean is null
24       * @param bean Object; A bean instance.
25       * @param pd PropertyDescriptor; A PropertyDescriptor for the property to be examined.
26       * @return True, if the value of the property described by 'pd' for the instance 'bean' is null indeed. Returns false
27       *         otherwise.
28       */
29      public static boolean isNull(final Object bean, final PropertyDescriptor pd)
30      {
31          Object result = null;
32          try
33          {
34              result = pd.getReadMethod().invoke(bean, new Object[0]);
35          }
36          catch (Exception e)
37          {
38              return true;
39          }
40          return (result == null);
41      }
42  }