Class ReflectionMap<V>

java.lang.Object
org.apache.juneau.utils.ReflectionMap<V>
Type Parameters:
V - The type of object in this map.
Direct Known Subclasses:
DebugEnablementMap

public class ReflectionMap<V> extends Object
Allows arbitrary objects to be mapped to classes and methods base on class/method name keys.

The valid pattern matches are:

  • Classes:
    • Fully qualified:
      • "com.foo.MyClass"
    • Fully qualified inner class:
      • "com.foo.MyClass$Inner1$Inner2"
    • Simple:
      • "MyClass"
    • Simple inner:
      • "MyClass$Inner1$Inner2"
      • "Inner1$Inner2"
      • "Inner2"
  • Methods:
    • Fully qualified with args:
      • "com.foo.MyClass.myMethod(String,int)"
      • "com.foo.MyClass.myMethod(java.lang.String,int)"
      • "com.foo.MyClass.myMethod()"
    • Fully qualified:
      • "com.foo.MyClass.myMethod"
    • Simple with args:
      • "MyClass.myMethod(String,int)"
      • "MyClass.myMethod(java.lang.String,int)"
      • "MyClass.myMethod()"
    • Simple:
      • "MyClass.myMethod"
    • Simple inner class:
      • "MyClass$Inner1$Inner2.myMethod"
      • "Inner1$Inner2.myMethod"
      • "Inner2.myMethod"
  • Fields:
    • Fully qualified:
      • "com.foo.MyClass.myField"
    • Simple:
      • "MyClass.myField"
    • Simple inner class:
      • "MyClass$Inner1$Inner2.myField"
      • "Inner1$Inner2.myField"
      • "Inner2.myField"
  • Constructors:
    • Fully qualified with args:
      • "com.foo.MyClass(String,int)"
      • "com.foo.MyClass(java.lang.String,int)"
      • "com.foo.MyClass()"
    • Simple with args:
      • "MyClass(String,int)"
      • "MyClass(java.lang.String,int)"
      • "MyClass()"
    • Simple inner class:
      • "MyClass$Inner1$Inner2()"
      • "Inner1$Inner2()"
      • "Inner2()"
  • A comma-delimited list of anything on this list.
See Also:
  • Constructor Details

  • Method Details

    • create

      public static <V> ReflectionMap.Builder<V> create(Class<V> c)
      Static builder creator.
      Type Parameters:
      V - The type of object in this map.
      Parameters:
      c - The type of object in this map.
      Returns:
      A new instance of this object.
    • find

      public Optional<V> find(Class<?> c, Class<? extends V> ofType)
      Finds first value in this map that matches the specified class.
      Parameters:
      c - The class to test for.
      ofType - Only return objects of the specified type.
      Returns:
      The matching object. Never null.
    • find

      public Optional<V> find(Class<?> c)
      Finds first value in this map that matches the specified class.
      Parameters:
      c - The class to test for.
      Returns:
      The matching object. Never null.
    • findAll

      public List<V> findAll(Class<?> c, Class<? extends V> ofType)
      Finds all values in this map that matches the specified class.
      Parameters:
      c - The class to test for.
      ofType - Only return objects of the specified type.
      Returns:
      A modifiable list of matching values. Never null.
    • findAll

      public List<V> findAll(Class<?> c)
      Finds all values in this map that matches the specified class.
      Parameters:
      c - The class to test for.
      Returns:
      A modifiable list of matching values. Never null.
    • appendAll

      public V[] appendAll(Class<?> c, Class<? extends V> ofType, V[] array)
      Finds all values in this map that matches the specified class.
      Parameters:
      c - The class to test for.
      ofType - Only return objects of the specified type.
      array - The array to append values to.
      Returns:
      The same list passed in or a new modifiable list if null.
    • find

      public Optional<V> find(Method m, Class<? extends V> ofType)
      Finds first value in this map that matches the specified method.
      Parameters:
      m - The method to test for.
      ofType - Only return objects of the specified type.
      Returns:
      The matching object. Never null.
    • find

      public Optional<V> find(Method m)
      Finds first value in this map that matches the specified method.
      Parameters:
      m - The method to test for.
      Returns:
      The matching object. Never null.
    • findAll

      public List<V> findAll(Method m, Class<? extends V> ofType)
      Finds all values in this map that matches the specified method.
      Parameters:
      m - The method to test for.
      ofType - Only return objects of the specified type.
      Returns:
      A modifiable list of matching values. Never null.
    • findAll

      public List<V> findAll(Method m)
      Finds all values in this map that matches the specified method.
      Parameters:
      m - The method to test for.
      Returns:
      A modifiable list of matching values. Never null.
    • appendAll

      public V[] appendAll(Method m, Class<? extends V> ofType, V[] array)
      Finds all values in this map that matches the specified method.
      Parameters:
      m - The method to test for.
      ofType - Only return objects of the specified type.
      array - The array to append values to.
      Returns:
      The same list passed in or a new modifiable list if null.
    • find

      public Optional<V> find(Field f, Class<? extends V> ofType)
      Finds first value in this map that matches the specified field.
      Parameters:
      f - The field to test for.
      ofType - Only return objects of the specified type.
      Returns:
      The matching object. Never null.
    • find

      public Optional<V> find(Field f)
      Finds first value in this map that matches the specified field.
      Parameters:
      f - The field to test for.
      Returns:
      The matching object. Never null.
    • findAll

      public List<V> findAll(Field f, Class<? extends V> ofType)
      Finds all values in this map that matches the specified field.
      Parameters:
      f - The field to test for.
      ofType - Only return objects of the specified type.
      Returns:
      A modifiable list of matching values. Never null.
    • findAll

      public List<V> findAll(Field f)
      Finds all values in this map that matches the specified field.
      Parameters:
      f - The field to test for.
      Returns:
      A modifiable list of matching values. Never null.
    • appendAll

      public V[] appendAll(Field f, Class<? extends V> ofType, V[] array)
      Finds all values in this map that matches the specified field.
      Parameters:
      f - The field to test for.
      ofType - Only return objects of the specified type.
      array - The array to append values to.
      Returns:
      The same list passed in or a new modifiable list if null.
    • find

      public Optional<V> find(Constructor<?> c, Class<? extends V> ofType)
      Finds first value in this map that matches the specified constructor.
      Parameters:
      c - The constructor to test for.
      ofType - Only return objects of the specified type.
      Returns:
      The matching object. Never null.
    • find

      public Optional<V> find(Constructor<?> c)
      Finds first value in this map that matches the specified constructor.
      Parameters:
      c - The constructor to test for.
      Returns:
      The matching object. Never null.
    • findAll

      public List<V> findAll(Constructor<?> c, Class<? extends V> ofType)
      Finds all values in this map that matches the specified constructor.
      Parameters:
      c - The constructor to test for.
      ofType - Only return objects of the specified type.
      Returns:
      A modifiable list of matching values. Never null.
    • findAll

      public List<V> findAll(Constructor<?> c)
      Finds all values in this map that matches the specified constructor.
      Parameters:
      c - The constructor to test for.
      Returns:
      A modifiable list of matching values. Never null.
    • appendAll

      public V[] appendAll(Constructor<?> c, Class<? extends V> ofType, V[] array)
      Finds all values in this map that matches the specified constructor.
      Parameters:
      c - The constructor to test for.
      ofType - Only return objects of the specified type.
      array - The array to append values to.
      Returns:
      The same list passed in or a new modifiable list if null.
    • toString

      public String toString()
      Overrides:
      toString in class Object