Class ResourceRequest<T extends Resource>
java.lang.Object
org.jdrupes.builder.api.ResourceRequest<T>
- Type Parameters:
T- the generic type
Represents a request for Resources of a specified type.
The specified type provides two kinds of type information:
- The type of the
Resources that are actually provided. - 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 Summary
ConstructorsConstructorDescriptionResourceRequest(ResourceType<? extends Resources<T>> type) Instantiates a new resource request without any restriction. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccepts(ResourceType<?> other) Checks if this request accepts a resource of the given type.booleancollects(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.booleaninthashCode()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.static <T extends Resource>
ResourceRequest<T> requestFor(Class<T> requested) Creates a request for a resource of the given type in a container of typeResources.static <T extends Resource>
ResourceRequest<T> requestFor(ResourceType<? extends Resources<T>> type) Slightly briefer alternative to invoking the constructor.toString()ResourceType<? extends Resources<T>> type()Return the requested type.<R extends Resources<T>>
ResourceRequest<T> Create a widened resource request by replacing the requested top-level type with the given super type, thus widening the request.
-
Constructor Details
-
ResourceRequest
Instantiates a new resource request without any restriction.- Parameters:
type- the requested type
-
-
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 typeT- the generic type- Parameters:
container- the containerrequested- the requested- Returns:
- the resource request
-
requestFor
Creates a request for a resource of the given type in a container of typeResources. 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
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 asClass <R>, but there is no way to specify a parameterized type as actual parameter.- Returns:
- the new resource request
-
type
Return the requested type.- Returns:
- the resource type
-
accepts
Checks if this request accepts a resource of the given type. Short fortype().isAssignableFrom(other).- Parameters:
other- the other- Returns:
- true, if successful
-
collects
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
-
equals
-
toString
-