Class ResourceRequest<T extends Resource>

java.lang.Object
org.jdrupes.builder.api.ResourceRequest<T>
Type Parameters:
T - the generic type

public class ResourceRequest<T extends Resource> extends Object

Represents a request for Resources of a specified type. The specified type provides two kinds of type information:

  1. The type of the Resources that are actually provided.
  2. The type of the "context" in which the Resources are to be provided.

As an example, consider requests for a compile time and a runtime classpath. In both cases, the actually provided Resources are of type "classpath element". However, depending on the kind of classpath, a ResourceProvider may deliver different collections of instances of "classpath elements". So instead of requesting "classpath element",

Not all requested resource types require context information. For example, a request for Cleanliness usually refers to all resources that a Generator has created and does not depend on a context. However, in order to keep the API simple, the context is always required.

  • Constructor Details

  • Method Details

    • requestFor

      public static <C extends Resources<T>, T extends Resource> ResourceRequest<T> requestFor(Class<C> container, Class<T> requested)
      Creates a request for a resource of the given type, in the given container type. The recommended usage pattern is to import this method statically.
      Type Parameters:
      C - the generic type
      T - the generic type
      Parameters:
      container - the container
      requested - the requested
      Returns:
      the resource request
    • requestFor

      public static <T extends Resource> ResourceRequest<T> requestFor(Class<T> requested)
      Creates a request for a resource of the given type in a container of type Resources. The recommended usage pattern is to import this method statically.
      Type Parameters:
      T - the generic type
      Parameters:
      requested - the requested
      Returns:
      the resource request
    • requestFor

      public static <T extends Resource> ResourceRequest<T> requestFor(ResourceType<? extends Resources<T>> type)
      Slightly briefer alternative to invoking the constructor.
      Type Parameters:
      T - the generic type
      Parameters:
      type - the type
      Returns:
      the resource request
    • widened

      public <R extends Resources<T>> ResourceRequest<T> widened(Class<? extends Resources> type)
      Create a widened resource request by replacing the requested top-level type with the given super type, thus widening the request.
      Type Parameters:
      R - the generic type
      Parameters:
      type - the desired super type. This should actually be declared as Class <R>, but there is no way to specify a parameterized type as actual parameter.
      Returns:
      the new resource request
    • type

      public ResourceType<? extends Resources<T>> type()
      Return the requested type.
      Returns:
      the resource type
    • accepts

      public boolean accepts(ResourceType<?> other)
      Checks if this request accepts a resource of the given type. Short for type().isAssignableFrom(other).
      Parameters:
      other - the other
      Returns:
      true, if successful
    • collects

      public boolean collects(ResourceType<?> type)
      Checks if the requested type is a container type and if the contained type of the container type is assignable from the given type.
      Parameters:
      type - the type to check
      Returns:
      true, if successful
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object