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

io.annot8.common.implementations.registries.SimpleContentBuilderFactoryRegistry 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.HashMap;
import java.util.Map;
import java.util.Optional;

import io.annot8.common.implementations.factories.ContentBuilderFactory;
import io.annot8.core.data.Content;

public class SimpleContentBuilderFactoryRegistry implements ContentBuilderFactoryRegistry {

  private final Map>, ContentBuilderFactory> builders =
      new HashMap<>();

  public , I extends C> void register(
      Class contentClass, ContentBuilderFactory contentBuilderFactory) {
    builders.put(contentClass, contentBuilderFactory);
  }

  @Override
  public > Optional> get(
      Class contentClass) {
    // This cast to C is correct, due to the way that the content is registered, we know that it
    // tallies.
    // TODO: Slightly unsure about cast to D, I think it's correct in our case
    ContentBuilderFactory contentBuilderFactory =
        (ContentBuilderFactory) builders.get(contentClass);
    return Optional.ofNullable(contentBuilderFactory);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy