java.lang.Object
org.moeaframework.analysis.store.schema.Schema

public class Schema extends Object
A schema that defines the structure of a DataStore, specifically detailing the required fields, their types, and order. This is useful for validation, ensuring the data being stored contains all required information.

If no fields are defined, this instead operates in schemaless mode, wherein such validations are skipped and the structure is inferred from the reference only. Fields are sorted according to their natural order.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Schema(Field<?>... fields)
    Constructs a schema with the given fields.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    get(int index)
    Returns the field at the given index.
    get(String name)
    Returns the field with the given name.
    Returns all fields defined by this schema in their designated order.
    int
     
    boolean
    Returns true if schemaless or has no defined fields; false otherwise
    static Schema
    of(Field<?>... fields)
    Constructs a schema with the given fields.
    List<org.apache.commons.lang3.tuple.Pair<Field<?>,String>>
    resolve(Reference reference)
    Resolves the given reference according to this schema.
    static Schema
    Constructs a schema without any defined fields (i.e., schemaless).
    int
    Returns the number of fields defined by this schema.
     
    void
    Updates the manifest with information about this schema.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Schema

      protected Schema(Field<?>... fields)
      Constructs a schema with the given fields.
      Parameters:
      fields - the fields, which if empty operates in schemaless mode
  • Method Details

    • size

      public int size()
      Returns the number of fields defined by this schema.
      Returns:
      the number of fields
    • get

      public Field<?> get(int index)
      Returns the field at the given index.
      Parameters:
      index - the index
      Returns:
      the field at the given index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • get

      public Field<?> get(String name)
      Returns the field with the given name.
      Parameters:
      name - the field name
      Returns:
      the field with the given name
      Throws:
      IllegalArgumentException - if no such field exists
    • getFields

      public List<Field<?>> getFields()
      Returns all fields defined by this schema in their designated order.
      Returns:
      the fields
    • resolve

      public List<org.apache.commons.lang3.tuple.Pair<Field<?>,String>> resolve(Reference reference)
      Resolves the given reference according to this schema. This process validates that all required fields are defined and orders them per the schema.
      Parameters:
      reference - the data reference
      Returns:
      the resolved fields and values according to this schema
      Throws:
      IllegalArgumentException - if the reference did not satisfy the requirements of this schema
    • isSchemaless

      public boolean isSchemaless()
      Returns true if schemaless or has no defined fields; false otherwise
      Returns:
      true if schemaless; false otherwise
    • updateManifest

      public void updateManifest(Manifest manifest)
      Updates the manifest with information about this schema.
      Parameters:
      manifest - the manifest
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • of

      @SafeVarargs public static Schema of(Field<?>... fields)
      Constructs a schema with the given fields.
      Parameters:
      fields - the fields
      Returns:
      the schema
    • schemaless

      public static Schema schemaless()
      Constructs a schema without any defined fields (i.e., schemaless).
      Returns:
      the schema