View Javadoc
1   package nl.tudelft.simulation.introspection;
2   
3   /**
4    * DelegateIntrospection takes care that an intermediate object delegates the introspection to its parent object. <br>
5    * <br>
6    * Copyright (c) 2002-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
7    * for project information <a href="https://simulation.tudelft.nl/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL
8    * project is distributed under a three-clause BSD-style license, which can be found at
9    * <a href="https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>. <br>
10   * @author <a href="https://github.com/averbraeck" target="_blank">Alexander Verbraeck</a>
11   */
12  public interface DelegateIntrospection
13  {
14      /**
15       * Return an intermediate object to which the introspection is delegated.
16       * @return the intermediate object to which the introspection is delegated
17       */
18      Object getParentIntrospectionObject();
19  
20      /**
21       * Check for introspection delegation to allow for the right object to be shown on the screen.
22       * @param introspectedObject the object that is displayed on the screen and might have delegation
23       * @return the toString() of the (delegated) object
24       */
25      static String checkDelegation(final Object introspectedObject)
26      {
27          Object introspected = introspectedObject;
28          while (introspected instanceof DelegateIntrospection)
29          {
30              introspected = ((DelegateIntrospection) introspected).getParentIntrospectionObject();
31          }
32          return introspected.toString();
33      }
34  }