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

io.annot8.common.implementations.registries.Annot8ComponentRegistry Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
/* Annot8 (annot8.io) - Licensed under Apache-2.0. */
package io.annot8.common.implementations.registries;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import io.annot8.core.components.Annot8Component;
import io.annot8.core.components.Processor;
import io.annot8.core.components.Source;

public class Annot8ComponentRegistry {

  private final Set> classes;

  public Annot8ComponentRegistry(Set> classes) {
    this.classes = Collections.unmodifiableSet(classes);
  }

  public Stream> getSources() {
    return classes
        .stream()
        .filter(Source.class::isAssignableFrom)
        .map(c -> c.asSubclass(Source.class));
  }

  public Stream> getProcessors() {
    return classes
        .stream()
        .filter(Processor.class::isAssignableFrom)
        .map(c -> c.asSubclass(Processor.class));
  }

  public Optional> getProcessor(String klass) {
    return getProcessors().filter(c -> c.getName().equals(klass)).findFirst();
  }

  public Optional> getSource(String klass) {
    return getSources().filter(c -> c.getName().equals(klass)).findFirst();
  }

  public  Optional> getComponent(
      String klass, Class componentType) {
    return classes
        .stream()
        .filter(componentType::isAssignableFrom)
        .filter(c -> c.getName().equals(klass))
        .findFirst()
        .map(c -> c.asSubclass(componentType));
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy