Class ResourceType<T extends Resource>
java.lang.Object
org.jdrupes.builder.api.ResourceType<T>
- Type Parameters:
T- the resource type
A special kind of type token for representing a resource type.
The method rawType() returns the type as Class. If this class
if derived from Resources, containedType() returns the
ResourceType of the contained elements.
Beware of automatic inference of type arguments. The inferred type arguments will usually be super classes of what you expect.
An alternative to using an anonymous class to create a type token
is to statically import the resourceType methods. Using these
typically also results in clear code that is sometimes easier to read.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ResourceType<Cleanliness> Used to request cleanup.static final ResourceType<FileResource> The resource type forFileResource.static final ResourceType<Resources<IOResource>> The resource type forResources[IOResource].static final ResourceType<IOResource> The resource type forIOResource.static final ResourceType<ResourceFile> The resource type forResourceFile. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiates a new resource type, using the information from a derived class.ResourceType(Class<? extends Resource> type, ResourceType<?> containedType) Initializes a new resource type. -
Method Summary
Modifier and TypeMethodDescriptionResourceType<?> Return the contained type ornull, if the resource is not a container.booleangetAllInterfaces(Class<?> clazz) Gets all interfaces that the given class implements, including the class itself.inthashCode()booleanisAssignableFrom(ResourceType<?> other) Checks if this is assignable from the other resource type.rawType()Return the type.static <C extends Resources<?>, T extends Resource>
ResourceType<C> resourceType(Class<C> type, Class<T> containedType) Creates a new resource type from the given container type and contained type.static <T extends Resource>
ResourceType<T> resourceType(Class<T> type) Creates a new resource type from the given type.toString()<R extends Resource>
ResourceType<R> Returns a newResourceTypewith the type (this.type()) widened to the given type.
-
Field Details
-
CleanlinessType
Used to request cleanup. -
ResourceFileType
The resource type forResourceFile. -
FileResourceType
The resource type forFileResource. -
IOResourceType
The resource type forIOResource. -
IOResourcesType
The resource type forResources[IOResource].
-
-
Constructor Details
-
ResourceType
Initializes a new resource type.- Parameters:
type- the typecontainedType- the contained type
-
ResourceType
protected ResourceType()Instantiates a new resource type, using the information from a derived class.
-
-
Method Details
-
resourceType
public static <C extends Resources<?>, T extends Resource> ResourceType<C> resourceType(Class<C> type, Class<T> containedType) Creates a new resource type from the given container type and contained type. The common usage pattern is to import this method statically.- Type Parameters:
C- the generic typeT- the generic type- Parameters:
type- the typecontainedType- the contained type- Returns:
- the resource type
-
resourceType
Creates a new resource type from the given type. The common usage pattern is to import this method statically.- Type Parameters:
T- the generic type- Parameters:
type- the type- Returns:
- the resource type
-
getAllInterfaces
Gets all interfaces that the given class implements, including the class itself.- Parameters:
clazz- the clazz- Returns:
- all interfaces
-
rawType
-
containedType
Return the contained type ornull, if the resource is not a container.- Returns:
- the type
-
isAssignableFrom
Checks if this is assignable from the other resource type.- Parameters:
other- the other- Returns:
- true, if is assignable from
-
widened
Returns a newResourceTypewith the type (this.type()) widened to the given type. While this method may be invoked for anyResourceType, it is intended to be used for containers (ResourceType<Resources<?>>) only.- Type Parameters:
R- the new raw 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 type
-
hashCode
-
equals
-
toString
-