io.annot8.api.context.Context Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of annot8-api Show documentation
Show all versions of annot8-api Show documentation
Core API interfaces for the Annot8 project
/* Annot8 (annot8.io) - Licensed under Apache-2.0. */
package io.annot8.api.context;
import io.annot8.api.components.Resource;
import java.util.Optional;
import java.util.stream.Stream;
/**
* A context defines additional information and resources for the environment in which the
* components are running.
*/
public interface Context {
/**
* Get all the resources
*
* @return stream of resources
*/
Stream getResources();
/**
* Get all the resources of that class.
*
* @param resourceClass the resource class required
* @param the resource class to return
* @return stream of matching resources
*/
default Stream getResources(Class resourceClass) {
return getResources().filter(resourceClass::isInstance).map(resourceClass::cast);
}
/**
* Get a single resource which matches.
*
* If there are multiple matches the underlying implementation may provide any back.
*
* @param resourceClass the resource class required
* @param the resource class to return
* @return optional of matching resources
*/
default Optional getResource(Class resourceClass) {
return getResources(resourceClass).findAny();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy