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

io.annot8.api.data.Content 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.data;

import io.annot8.api.helpers.WithDescription;
import io.annot8.api.helpers.WithId;
import io.annot8.api.helpers.WithProperties;
import io.annot8.api.helpers.builders.WithFromBuilder;
import io.annot8.api.helpers.builders.WithIdBuilder;
import io.annot8.api.helpers.builders.WithPropertiesBuilder;
import io.annot8.api.helpers.builders.WithSave;
import io.annot8.api.stores.AnnotationStore;
import java.util.function.Supplier;

/**
 * Base content interface from which all content implementations extend.
 *
 * @param  the type of data held
 */
public interface Content extends WithId, WithProperties, WithDescription {

  /**
   * Get the item which this content relates to.
   *
   * @return item
   */
  Item getItem();

  /**
   * The data associated with this content object
   *
   * @return the data
   */
  D getData();

  /**
   * The class of the data stored in this Content object
   *
   * @return data class
   */
  Class getDataClass();

  /**
   * The top level content interface this object implements
   *
   * @return common content interface
   */
  Class> getContentClass();

  /**
   * The annotation store for this content
   *
   * @return annotation store
   */
  AnnotationStore getAnnotations();

  /** Builder interface to createContent (immutable) Content classes */
  interface Builder, D>
      extends WithPropertiesBuilder>,
          WithFromBuilder, A>,
          WithIdBuilder>,
          WithSave {

    /**
     * Set the description of this content object
     *
     * @param description the content description
     * @return this builder for chaining
     */
    Content.Builder withDescription(final String description);

    /**
     * Set the data for this content object
     *
     * @param data the data
     * @return this builder for chaining
     */
    default Content.Builder withData(final D data) {
      if (data == null) {
        withData((Supplier) null);
      } else {
        withData(() -> data);
      }
      return this;
    }

    /**
     * Set the data for this content object, accessed via a supplier
     *
     * @param data the data
     * @return this builder for chaining
     */
    Content.Builder withData(final Supplier data);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy