Package net.morimekta.providence
Class PMessageBuilder<Message extends PMessage<Message>>
- java.lang.Object
-
- net.morimekta.providence.PMessageBuilder<Message>
-
- All Implemented Interfaces:
PMessageOrBuilder<Message>
,PValue<Message>
- Direct Known Subclasses:
PApplicationException._Builder
public abstract class PMessageBuilder<Message extends PMessage<Message>> extends java.lang.Object implements PMessageOrBuilder<Message>
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<Message>
addTo(int key, java.lang.Object value)
Adds a value to a set or list container.PMessageBuilder<Message>
addTo(PField<Message> field, java.lang.Object value)
Checks if a specific field is set on the builder.abstract Message
build()
abstract PMessageBuilder<Message>
clear(int key)
Clear the provided field value.PMessageBuilder<Message>
clear(PField<Message> field)
Clear the provided field value.abstract boolean
isModified(int key)
Checks if a specific field is modified on the builder.boolean
isModified(PField<Message> 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(PField<Message> field)
Checks if a specific field is set on the builder.abstract PMessageBuilder<Message>
merge(Message from)
Merges the provided message into the builder.java.util.Collection<PField<Message>>
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(PField<Message> field)
Get the builder for the given message contained in this builder.java.util.Collection<PField>
presentFields()
Get a Collection of F with fields set on the builder.abstract PMessageBuilder<Message>
set(int key, java.lang.Object value)
Set the provided field value.PMessageBuilder<Message>
set(PField<Message> 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 PMessageBuilder<Message>
validate()
Checks if the current set data is enough to make a valid struct.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.morimekta.providence.PMessageOrBuilder
descriptor, get, get, has, has, toBuilder, toMessage
-
-
-
-
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 PMessageBuilder<Message> 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.- Returns:
- The builder itself.
- Throws:
java.lang.IllegalStateException
- When the builder will not generate a valid message model object.
-
set
@Nonnull public abstract PMessageBuilder<Message> 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<Message> set(@Nonnull PField<Message> field, java.lang.Object value)
Set the provided field value.- Parameters:
field
- The field to set.value
- The value to be set.- Returns:
- The builder itself.
-
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 PField<Message> 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<PField> 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 PField<Message> 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<PField<Message>> modifiedFields()
Get a Collection of F with fields Modified since creation of the builder.- Returns:
- Collection of F
-
addTo
@Nonnull public abstract PMessageBuilder<Message> 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 builder itself.
- Throws:
java.lang.IllegalArgumentException
- if the field is not a list or set.
-
addTo
@Nonnull public PMessageBuilder<Message> addTo(@Nonnull PField<Message> 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:
- The builder itself.
-
clear
@Nonnull public abstract PMessageBuilder<Message> clear(int key)
Clear the provided field value.- Parameters:
key
- The key of the field to clear.- Returns:
- The builder itself.
-
clear
@Nonnull public PMessageBuilder<Message> clear(@Nonnull PField<Message> field)
Clear the provided field value.- Parameters:
field
- The field to clear.- Returns:
- The builder itself.
-
merge
@Nonnull public abstract PMessageBuilder<Message> merge(@Nonnull Message 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 builder itself.
-
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 PField<Message> 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.
-
build
@Nonnull public abstract Message build()
-
-