Interface ClassSource

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ClassSource
Represents an abstract class loader that can only retrieve classes by their canonical name.
  • Method Details

    • fromClassLoader

      static ClassSource fromClassLoader()
      Construct a class source from the default class loader.
      Returns:
      A class source.
    • fromPackage

      static ClassSource fromPackage(String packageName)
      Construct a class source from the default class loader and package.
      Parameters:
      packageName - - the package that is prepended to every lookup.
      Returns:
      A package source.
    • fromClassLoader

      static ClassSource fromClassLoader(ClassLoader loader)
      Construct a class source from the given class loader.
      Parameters:
      loader - - the class loader.
      Returns:
      The corresponding class source.
    • fromMap

      static ClassSource fromMap(Map<String,Class<?>> map)
      Construct a class source from a mapping of canonical names and the corresponding classes. If the map is null, it will be interpreted as an empty map. If the map does not contain a Class with the specified name, or that string maps to NULL explicitly, an empty optional will be returned
      Parameters:
      map - - map of class names and classes.
      Returns:
      The class source.
    • empty

      static ClassSource empty()
      Returns:
      A ClassLoader which will never successfully load a class.
    • append

      static String append(String a, String b)
      Append to canonical names together.
      Parameters:
      a - - the name to the left.
      b - - the name to the right.
      Returns:
      The full canonical name, with a dot seperator.
    • retry

      default ClassSource retry(ClassSource other)
      Retrieve a class source that will retry failed lookups in the given source.
      Parameters:
      other - - the other class source.
      Returns:
      A new class source.
    • usingPackage

      default ClassSource usingPackage(String packageName)
      Retrieve a class source that prepends a specific package name to every lookup.
      Parameters:
      packageName - - the package name to prepend.
      Returns:
      The class source.
    • loadClass

      Optional<Class<?>> loadClass(String canonicalName)
      Retrieve a class by its canonical name
      Parameters:
      canonicalName - The class's canonical name, i.e. java.lang.Object
      Returns:
      Optional that may contain a Class