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 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              { result.add(original[i]); }
43          }
44          return result.toArray(new Property[0]);
45      }
46  
47      @Override
48      public String[] getPropertyNames(final Object arg0)
49      {
50          Property[] properties = this.getProperties(arg0);
51          String[] result = new String[properties.length];
52          for (int i = 0; i < properties.length; i++)
53          {
54              result[i] = properties[i].getName();
55          }
56          return result;
57      }
58  
59      @Override
60      public Property getProperty(final Object arg0, final String arg1)
61      {
62          Property[] properties = this.getProperties(arg0);
63          for (int i = 0; i < properties.length; i++)
64          {
65              if (properties[i].getName().equals(arg1))
66              { return properties[i]; }
67          }
68          return null;
69      }
70  
71      /**
72       * Method suppress.
73       * @param type the type of the class
74       * @return boolean whether to supress
75       */
76      protected boolean suppress(final Class<?> type)
77      {
78          if (type.equals(Class.class))
79          { return true; }
80          return false;
81      }
82  
83      /**
84       * Method suppress.
85       * @param propertyName the propertyName
86       * @return whether to supress
87       */
88      protected abstract boolean suppress(final String propertyName);
89  }