Package net.morimekta.providence
Class PMessageBuilder<T extends PMessage<T,F>,F extends PField>
- java.lang.Object
-
- net.morimekta.providence.PMessageBuilder<T,F>
-
- All Implemented Interfaces:
PBuilder<T>
- Direct Known Subclasses:
Any._Builder
,Empty._Builder
,PApplicationException._Builder
public abstract class PMessageBuilder<T extends PMessage<T,F>,F extends PField> extends java.lang.Object implements PBuilder<T>
Base class for message builders.
-
-
Constructor Summary
Constructors Constructor Description PMessageBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract PMessageBuilder<T,F>
addTo(int key, java.lang.Object value)
Adds a value to a set or list container.PMessageBuilder<T,F>
addTo(F field, java.lang.Object value)
Checks if a specific field is set on the builder.abstract PMessageBuilder<T,F>
clear(int key)
Clear the provided field value.PMessageBuilder<T,F>
clear(F field)
Clear the provided field value.abstract PMessageDescriptor<T,F>
descriptor()
Get the descriptor for the message being built.abstract boolean
isModified(int key)
Checks if a specific field is modified on the builder.boolean
isModified(F field)
Checks if a specific field is modified on the builder.abstract boolean
isSet(int key)
Checks if a specific field is set on the builder.boolean
isSet(F field)
Checks if a specific field is set on the builder.abstract PMessageBuilder<T,F>
merge(T from)
Merges the provided message into the builder.java.util.Collection<F>
modifiedFields()
Get a Collection of F with fields Modified since creation of the builder.abstract PMessageBuilder
mutator(int key)
Get the builder for the given message contained in this builder.PMessageBuilder
mutator(F field)
Get the builder for the given message contained in this builder.java.util.Collection<F>
presentFields()
Get a Collection of F with fields set on the builder.abstract PMessageBuilder<T,F>
set(int key, java.lang.Object value)
Set the provided field value.PMessageBuilder<T,F>
set(F field, java.lang.Object value)
Set the provided field value.abstract boolean
valid()
Checks if the current set data is enough to make a valid struct.abstract void
validate()
Checks if the current set data is enough to make a valid struct.
-
-
-
Method Detail
-
valid
public abstract boolean valid()
Checks if the current set data is enough to make a valid struct. It will check for all required fields, and if any are missing it will return false.- Returns:
- True for a valid message.
-
validate
public abstract void validate() throws java.lang.IllegalStateException
Checks if the current set data is enough to make a valid struct. It will check for all required fields, and if any are missing it will throw anIllegalStateException
with an appropriate error message.- Throws:
java.lang.IllegalStateException
- When the builder will not generate a valid message model object.
-
set
@Nonnull public abstract PMessageBuilder<T,F> set(int key, java.lang.Object value)
Set the provided field value.- Parameters:
key
- The key of the field to set.value
- The value to be set.- Returns:
- The message builder.
-
set
@Nonnull public PMessageBuilder<T,F> set(@Nonnull F field, java.lang.Object value)
Set the provided field value.- Parameters:
field
- The field to set.value
- The value to be set.- Returns:
- True if the field is set.
-
isSet
public abstract boolean isSet(int key)
Checks if a specific field is set on the builder.- Parameters:
key
- The key of the field to check.- Returns:
- True if the field is set.
-
isSet
public boolean isSet(@Nonnull F field)
Checks if a specific field is set on the builder.- Parameters:
field
- The field to check.- Returns:
- True if the field is set.
-
presentFields
@Nonnull public java.util.Collection<F> presentFields()
Get a Collection of F with fields set on the builder. A.k.a is present. Unusual naming because it avoids conflict with generated methods.- Returns:
- Collection of F
-
isModified
public abstract boolean isModified(int key)
Checks if a specific field is modified on the builder.- Parameters:
key
- The key of the field to check.- Returns:
- True if the field is modified.
-
isModified
public boolean isModified(@Nonnull F field)
Checks if a specific field is modified on the builder.- Parameters:
field
- The field to check.- Returns:
- True if the field is modified.
-
modifiedFields
@Nonnull public java.util.Collection<F> modifiedFields()
Get a Collection of F with fields Modified since creation of the builder.- Returns:
- Collection of F
-
addTo
@Nonnull public abstract PMessageBuilder<T,F> addTo(int key, java.lang.Object value)
Adds a value to a set or list container.- Parameters:
key
- The key of the container field to add too.value
- The value to add.- Returns:
- The message builder.
- Throws:
java.lang.IllegalArgumentException
- if the field is not a list or set.
-
addTo
@Nonnull public PMessageBuilder<T,F> addTo(@Nonnull F field, java.lang.Object value)
Checks if a specific field is set on the builder.- Parameters:
field
- The container field to add too.value
- The value to add.- Returns:
- True if the field is set.
-
clear
@Nonnull public abstract PMessageBuilder<T,F> clear(int key)
Clear the provided field value.- Parameters:
key
- The key of the field to clear.- Returns:
- The message builder.
-
clear
@Nonnull public PMessageBuilder<T,F> clear(@Nonnull F field)
Clear the provided field value.- Parameters:
field
- The field to clear.- Returns:
- The message builder.
-
merge
@Nonnull public abstract PMessageBuilder<T,F> merge(@Nonnull T from)
Merges the provided message into the builder. Contained messages should in turn be merged and not replaced wholesale. Sets are unioned (addAll) and maps will overwrite / replace on a per-key basis (putAll).- Parameters:
from
- The message to merge values from.- Returns:
- The message builder.
-
mutator
@Nonnull public abstract PMessageBuilder mutator(int key)
Get the builder for the given message contained in this builder. If the sub-builder does not exist, create, either from existing instance or from scratch.- Parameters:
key
- The field key.- Returns:
- The field builder.
- Throws:
java.lang.IllegalArgumentException
- if field is not a message field.
-
mutator
@Nonnull public PMessageBuilder mutator(@Nonnull F field)
Get the builder for the given message contained in this builder. If the sub-builder does not exist, create, either from existing instance or from scratch.- Parameters:
field
- The field to mutate.- Returns:
- The field builder.
- Throws:
java.lang.IllegalArgumentException
- if field is not a message field.
-
descriptor
@Nonnull public abstract PMessageDescriptor<T,F> descriptor()
Get the descriptor for the message being built.- Returns:
- The struct descriptor.
-
-