View Javadoc
1   package nl.tudelft.simulation.introspection;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * The AbstractSupressIntrospector.
8    * <p>
9    * Copyright (c) 2002-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
10   * for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL
11   * project is distributed under a three-clause BSD-style license, which can be found at
12   * <a href="https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>.
13   * </p>
14   * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a>
15   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16   * @author Niels Lang.
17   * @since 1.5
18   */
19  public abstract class AbstractSuppressIntrospector implements Introspector
20  {
21      /** the parent introspector. */
22      protected Introspector parent;
23  
24      /**
25       * Constructor for AbstractSuppressIntrospector.
26       * @param parent Introspector; the parent introspector
27       */
28      public AbstractSuppressIntrospector(final Introspector parent)
29      {
30          super();
31          this.parent = parent;
32      }
33  
34      @Override
35      public Property[] getProperties(final Object arg0)
36      {
37          Property[] original = this.parent.getProperties(arg0);
38          List<Property> result = new ArrayList<Property>();
39          for (int i = 0; i < original.length; i++)
40          {
41              if (!this.suppress(original[i].getType()) && !this.suppress(original[i].getName()))
42              {
43                  result.add(original[i]);
44              }
45          }
46          return result.toArray(new Property[0]);
47      }
48  
49      @Override
50      public String[] getPropertyNames(final Object arg0)
51      {
52          Property[] properties = this.getProperties(arg0);
53          String[] result = new String[properties.length];
54          for (int i = 0; i < properties.length; i++)
55          {
56              result[i] = properties[i].getName();
57          }
58          return result;
59      }
60  
61      @Override
62      public Property getProperty(final Object arg0, final String arg1)
63      {
64          Property[] properties = this.getProperties(arg0);
65          for (int i = 0; i < properties.length; i++)
66          {
67              if (properties[i].getName().equals(arg1))
68              {
69                  return properties[i];
70              }
71          }
72          return null;
73      }
74  
75      /**
76       * Method suppress.
77       * @param type Class&lt;?&gt;; the type of the class
78       * @return boolean whether to supress
79       */
80      protected boolean suppress(final Class<?> type)
81      {
82          if (type.equals(Class.class))
83          {
84              return true;
85          }
86          return false;
87      }
88  
89      /**
90       * Method suppress.
91       * @param propertyName String; the propertyName
92       * @return whether to supress
93       */
94      protected abstract boolean suppress(final String propertyName);
95  }