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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theSchemainstance.toString()withAddChild(Schema aChild) Adds the given child to the current children list.withAddChildren(Collection<? extends Schema> aChildren) Adds the given children to the current children list.withAddChildren(Schema... aChildren) Adds the given children to the current children list.withChildren(Collection<? extends Schema> aChildren) Replaces the current children with the given collection.withChildren(Schema... aChildren) Replaces the current children with the given collection.withDescription(String aDescription) withException(Throwable aException) withHash(int aHash) withIdentifier(String aIdentifier) withInstance(Object aInstance) InitializesTYPE,HASH, andIDENTIFIERfrom the given instance if these options are not already set.withProperty(Enum aKey, Object aValue) Adds a custom property to the metadata.withProperty(String aKey, Object aValue) Adds a (custom) property to the schema.withSchema(Schema aSchema) Sets a base schema from which options may be copied when building.withStereotype(String aStereotype) <T> Schema.BuilderwithTerm(org.refcodes.ontology.Concept<T> aKey, T aValue) Adds a customConceptproperty to the builder.Adds a customUnsafeConceptproperty to the builder.
-
Constructor Details
-
Builder
protected Builder()Instantiates a new builder.
-
-
Method Details
-
withProperty
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
Adds a customConceptproperty to the builder.- Type Parameters:
T- the generic type- Parameters:
aKey- TheConceptrepresenting the key by resolving to its name (as ofConcept.getName().aValue- The concept's value.- Returns:
- Returns this builder instance as of the builder pattern.
-
withTerm
Adds a customUnsafeConceptproperty to the builder.- Parameters:
aKey- TheUnsafeConceptrepresenting the key by resolving to its name (as ofEnumTerm.name().aValue- The concept's value.- Returns:
- Returns this builder instance as of the builder pattern.
-
withIdentifier
- Specified by:
withIdentifierin interfaceorg.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<Schema.Builder>
-
withAlias
- Specified by:
withAliasin interfaceorg.refcodes.mixin.AliasAccessor.AliasBuilder<Schema.Builder>
-
withKey
- Specified by:
withKeyin interfaceorg.refcodes.mixin.KeyAccessor.KeyBuilder<String, Schema.Builder>
-
withType
- Specified by:
withTypein interfaceorg.refcodes.mixin.TypeAccessor.TypeBuilder<Class<?>, Schema.Builder>
-
withHash
- Specified by:
withHashin interfaceorg.refcodes.mixin.HashAccessor.HashBuilder<Schema.Builder>
-
withInstance
Initializes
TYPE,HASH, andIDENTIFIERfrom 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@hashform).- Specified by:
withInstancein interfaceorg.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
- Specified by:
withValuein interfaceorg.refcodes.mixin.ValueAccessor.ValueBuilder<Object, Schema.Builder>
-
withStereotype
- Specified by:
withStereotypein interfaceorg.refcodes.mixin.StereotypeAccessor.StereotypeBuilder<String, Schema.Builder>
-
withException
- Specified by:
withExceptionin interfaceorg.refcodes.exception.ExceptionAccessor.ExceptionBuilder<Throwable, Schema.Builder>
-
withDescription
- Specified by:
withDescriptionin interfaceorg.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<Schema.Builder>
-
withChildren
Replaces the current children with the given collection.- Specified by:
withChildrenin interfaceorg.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<Schema[], Schema.Builder>- Parameters:
aChildren- children to set- Returns:
- Returns this builder instance as of the builder pattern.
-
withChildren
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
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
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
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
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
Adds a (custom) property to the schema.- Parameters:
aKey- The key of the propertyaValue- The value of the property- Returns:
- This builder as of the builder pattern
-
build
-
toString
-