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

io.annot8.common.implementations.capabilities.SetCapabilities 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.capabilities;

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

import io.annot8.core.capabilities.AnnotationCapability;
import io.annot8.core.capabilities.Capabilities;
import io.annot8.core.capabilities.ContentCapability;
import io.annot8.core.capabilities.GroupCapability;
import io.annot8.core.capabilities.ResourceCapability;

public class SetCapabilities implements Capabilities {

  private final Set processedAnnotations;
  private final Set createdAnnotations;
  private final Set deletedAnnotations;

  private final Set processedGroups;
  private final Set createdGroups;
  private final Set deletedGroups;

  private final Set processedContent;
  private final Set createdContent;
  private final Set deletedContent;

  private final Set usedResources;

  public SetCapabilities(
      Set processedAnnotations,
      Set createdAnnotations,
      Set deletedAnnotations,
      Set processedGroups,
      Set createdGroups,
      Set deletedGroups,
      Set processedContent,
      Set createdContent,
      Set deletedContent,
      Set usedResources) {

    this.processedAnnotations = processedAnnotations;
    this.createdAnnotations = createdAnnotations;
    this.deletedAnnotations = deletedAnnotations;
    this.processedGroups = processedGroups;
    this.createdGroups = createdGroups;
    this.deletedGroups = deletedGroups;
    this.processedContent = processedContent;
    this.createdContent = createdContent;
    this.deletedContent = deletedContent;
    this.usedResources = usedResources;
  }

  @Override
  public Stream getProcessedAnnotations() {
    return processedAnnotations.stream();
  }

  @Override
  public Stream getCreatedAnnotations() {
    return createdAnnotations.stream();
  }

  @Override
  public Stream getDeletedAnnotations() {
    return deletedAnnotations.stream();
  }

  @Override
  public Stream getProcessedGroups() {
    return processedGroups.stream();
  }

  @Override
  public Stream getCreatedGroups() {
    return createdGroups.stream();
  }

  @Override
  public Stream getDeletedGroups() {
    return deletedGroups.stream();
  }

  @Override
  public Stream getCreatedContent() {
    return createdContent.stream();
  }

  @Override
  public Stream getDeletedContent() {
    return deletedContent.stream();
  }

  @Override
  public Stream getProcessedContent() {
    return processedContent.stream();
  }

  @Override
  public Stream getUsedResources() {
    return usedResources.stream();
  }

  public static class Builder implements Capabilities.Builder {

    private final Set processedAnnotations = new HashSet<>();
    private final Set createdAnnotations = new HashSet<>();
    private final Set deletedAnnotations = new HashSet<>();

    private final Set processedGroups = new HashSet<>();
    private final Set createdGroups = new HashSet<>();
    private final Set deletedGroups = new HashSet<>();

    private final Set processedContent = new HashSet<>();
    private final Set createdContent = new HashSet<>();
    private final Set deletedContent = new HashSet<>();

    private final Set usedResources = new HashSet<>();

    @Override
    public Capabilities.Builder processesAnnotation(AnnotationCapability capability) {
      processedAnnotations.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder createsAnnotation(AnnotationCapability capability) {
      createdAnnotations.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder deletesAnnotation(AnnotationCapability capability) {
      deletedAnnotations.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder processesGroup(GroupCapability capability) {
      processedGroups.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder createsGroup(GroupCapability capability) {
      createdGroups.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder deletesGroup(GroupCapability capability) {
      deletedGroups.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder processesContent(ContentCapability capability) {
      processedContent.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder createsContent(ContentCapability capability) {
      createdContent.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder deletesContent(ContentCapability capability) {
      deletedContent.add(capability);
      return this;
    }

    @Override
    public Capabilities.Builder usesResource(ResourceCapability capability) {
      usedResources.add(capability);
      return this;
    }

    @Override
    public Capabilities save() {
      return new SetCapabilities(
          Collections.unmodifiableSet(processedAnnotations),
          Collections.unmodifiableSet(createdAnnotations),
          Collections.unmodifiableSet(deletedAnnotations),
          Collections.unmodifiableSet(processedGroups),
          Collections.unmodifiableSet(createdGroups),
          Collections.unmodifiableSet(deletedGroups),
          Collections.unmodifiableSet(processedContent),
          Collections.unmodifiableSet(createdContent),
          Collections.unmodifiableSet(deletedContent),
          Collections.unmodifiableSet(usedResources));
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy