All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.annot8.api.context.Context Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
/* 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