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