Class Schema.Builder

java.lang.Object
org.refcodes.schema.Schema.Builder
All Implemented Interfaces:
org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<Throwable, Schema.Builder>, org.refcodes.mixin.AliasAccessor.AliasBuilder<Schema.Builder>, org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<Schema[], Schema.Builder>, org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<Schema.Builder>, org.refcodes.mixin.HashAccessor.HashBuilder<Schema.Builder>, org.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<Schema.Builder>, org.refcodes.mixin.InstanceAccessor.InstanceBuilder<Object, Schema.Builder>, org.refcodes.mixin.KeyAccessor.KeyBuilder<String, Schema.Builder>, org.refcodes.mixin.StereotypeAccessor.StereotypeBuilder<String, Schema.Builder>, org.refcodes.mixin.TypeAccessor.TypeBuilder<Class<?>, Schema.Builder>, org.refcodes.mixin.ValueAccessor.ValueBuilder<Object, Schema.Builder>
Enclosing class:
Schema

public static class Schema.Builder extends Object implements org.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<Schema.Builder>, org.refcodes.mixin.AliasAccessor.AliasBuilder<Schema.Builder>, org.refcodes.mixin.KeyAccessor.KeyBuilder<String, Schema.Builder>, org.refcodes.mixin.TypeAccessor.TypeBuilder<Class<?>, Schema.Builder>, org.refcodes.mixin.HashAccessor.HashBuilder<Schema.Builder>, org.refcodes.mixin.ValueAccessor.ValueBuilder<Object, Schema.Builder>, org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<Schema.Builder>, org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<Schema[], Schema.Builder>, org.refcodes.mixin.InstanceAccessor.InstanceBuilder<Object, Schema.Builder>, org.refcodes.mixin.StereotypeAccessor.StereotypeBuilder<String, Schema.Builder>, org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<Throwable, Schema.Builder>
Builder for creating Schema instances.

The builder collects common schema metadata (identifier, alias, key, type, hash, description, stereotype, exception, value), custom options, and optional children.

  • Constructor Details

    • Builder

      protected Builder()
      Instantiates a new builder.
  • Method Details

    • withProperty

      public Schema.Builder withProperty(Enum aKey, Object aValue)
      Adds a custom property to the metadata.

      By default, the key is derived from Enum.name() and normalized into a namespace-like representation using lowercase characters and dot separators (e.g. DOCUMENT_ARRAY_INDEX -> document.array.index).

      Parameters:
      aKey - The enumeration representing the key by resolving to its normalized name.
      aValue - the property value.
      Returns:
      Returns this builder instance as of the builder pattern.
    • withTerm

      public <T> Schema.Builder withTerm(org.refcodes.ontology.Concept<T> aKey, T aValue)
      Adds a custom Concept property to the builder.
      Type Parameters:
      T - the generic type
      Parameters:
      aKey - The Concept representing the key by resolving to its name (as of Concept.getName().
      aValue - The concept's value.
      Returns:
      Returns this builder instance as of the builder pattern.
    • withTerm

      public Schema.Builder withTerm(org.refcodes.ontology.UnsafeConcept aKey, Object aValue)
      Adds a custom UnsafeConcept property to the builder.
      Parameters:
      aKey - The UnsafeConcept representing the key by resolving to its name (as of EnumTerm.name().
      aValue - The concept's value.
      Returns:
      Returns this builder instance as of the builder pattern.
    • withIdentifier

      public Schema.Builder withIdentifier(String aIdentifier)
      Specified by:
      withIdentifier in interface org.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<Schema.Builder>
    • withAlias

      public Schema.Builder withAlias(String aAlias)
      Specified by:
      withAlias in interface org.refcodes.mixin.AliasAccessor.AliasBuilder<Schema.Builder>
    • withKey

      public Schema.Builder withKey(String aKey)
      Specified by:
      withKey in interface org.refcodes.mixin.KeyAccessor.KeyBuilder<String, Schema.Builder>
    • withType

      public Schema.Builder withType(Class aType)
      Specified by:
      withType in interface org.refcodes.mixin.TypeAccessor.TypeBuilder<Class<?>, Schema.Builder>
    • withHash

      public Schema.Builder withHash(int aHash)
      Specified by:
      withHash in interface org.refcodes.mixin.HashAccessor.HashBuilder<Schema.Builder>
    • withInstance

      public Schema.Builder withInstance(Object aInstance)

      Initializes TYPE, HASH, and IDENTIFIER from the given instance if these options are not already set.

      The identifier is derived from the instance's type simple name and the identity hash code (UML-like Type@hash form).

      Specified by:
      withInstance in interface org.refcodes.mixin.InstanceAccessor.InstanceBuilder<Object, Schema.Builder>
      Parameters:
      aInstance - the instance from which to derive type/hash/identifier
      Returns:
      Returns this builder instance as of the builder pattern.
    • withValue

      public Schema.Builder withValue(Object aValue)
      Specified by:
      withValue in interface org.refcodes.mixin.ValueAccessor.ValueBuilder<Object, Schema.Builder>
    • withStereotype

      public Schema.Builder withStereotype(String aStereotype)
      Specified by:
      withStereotype in interface org.refcodes.mixin.StereotypeAccessor.StereotypeBuilder<String, Schema.Builder>
    • withException

      public Schema.Builder withException(Throwable aException)
      Specified by:
      withException in interface org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<Throwable, Schema.Builder>
    • withDescription

      public Schema.Builder withDescription(String aDescription)
      Specified by:
      withDescription in interface org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<Schema.Builder>
    • withChildren

      public Schema.Builder withChildren(Schema... aChildren)
      Replaces the current children with the given collection.
      Specified by:
      withChildren in interface org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<Schema[], Schema.Builder>
      Parameters:
      aChildren - children to set
      Returns:
      Returns this builder instance as of the builder pattern.
    • withChildren

      public Schema.Builder withChildren(Collection<? extends Schema> aChildren)
      Replaces the current children with the given collection.
      Parameters:
      aChildren - The children to set.
      Returns:
      Returns this builder instance as of the builder pattern.
    • withAddChild

      public Schema.Builder withAddChild(Schema aChild)
      Adds the given child to the current children list.
      Parameters:
      aChild - The child to add.
      Returns:
      his builder instance as of the builder pattern.
    • withAddChildren

      public Schema.Builder withAddChildren(Schema... aChildren)
      Adds the given children to the current children list.
      Parameters:
      aChildren - The children to add.
      Returns:
      Returns this builder instance as of the builder pattern.
    • withAddChildren

      public Schema.Builder withAddChildren(Collection<? extends Schema> aChildren)
      Adds the given children to the current children list.
      Parameters:
      aChildren - children to add
      Returns:
      Returns this builder instance as of the builder pattern.
    • withSchema

      public Schema.Builder withSchema(Schema aSchema)

      Sets a base schema from which options may be copied when building.

      This is useful to extend an existing schema while overriding only selected options.

      Parameters:
      aSchema - the base schema to copy from
      Returns:
      Returns this builder instance as of the builder pattern.
    • withProperty

      public Schema.Builder withProperty(String aKey, Object aValue)
      Adds a (custom) property to the schema.
      Parameters:
      aKey - The key of the property
      aValue - The value of the property
      Returns:
      This builder as of the builder pattern
    • build

      public Schema build()
      Builds the Schema instance.
      Returns:
      The constructed Schema instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object