Class CMessageBuilder<Builder extends CMessageBuilder<Builder,Message>,Message extends PMessage<Message>>
- java.lang.Object
-
- net.morimekta.providence.PMessageBuilder<Message>
-
- net.morimekta.providence.reflect.contained.CMessageBuilder<Builder,Message>
-
- All Implemented Interfaces:
PMessageOrBuilder<Message>
,PValue<Message>
- Direct Known Subclasses:
CException.Builder
,CStruct.Builder
public abstract class CMessageBuilder<Builder extends CMessageBuilder<Builder,Message>,Message extends PMessage<Message>> extends PMessageBuilder<Message>
Base message builder class for contained messages.
-
-
Constructor Summary
Constructors Constructor Description CMessageBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Builder
addTo(int key, java.lang.Object value)
Adds a value to a set or list container.Builder
clear(int key)
Clear the provided field value.<T> T
get(int key)
boolean
has(int key)
boolean
isModified(int key)
Checks if a specific field is modified on the builder.boolean
isSet(int key)
Checks if a specific field is set on the builder.Builder
merge(Message from)
Merges the provided message into the builder.PMessageBuilder<?>
mutator(int key)
Get the builder for the given message contained in this builder.Builder
set(int key, java.lang.Object value)
Set the provided field value.java.lang.String
toString()
boolean
valid()
Checks if the current set data is enough to make a valid struct.Builder
validate()
Checks if the current set data is enough to make a valid struct.-
Methods inherited from class net.morimekta.providence.PMessageBuilder
addTo, build, clear, isModified, isSet, modifiedFieldNames, modifiedFields, mutator, presentFieldNames, presentFields, set
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.morimekta.providence.PMessageOrBuilder
descriptor, get, has, toBuilder, toMessage
-
-
-
-
Method Detail
-
merge
@Nonnull public Builder merge(@Nonnull Message from)
Description copied from class:PMessageBuilder
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).- Specified by:
merge
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
from
- The message to merge values from.- Returns:
- The builder itself.
-
mutator
@Nonnull public PMessageBuilder<?> mutator(int key)
Description copied from class:PMessageBuilder
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.- Specified by:
mutator
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
key
- The field key.- Returns:
- The field builder.
-
valid
public boolean valid()
Description copied from class:PMessageBuilder
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.- Specified by:
valid
in classPMessageBuilder<Message extends PMessage<Message>>
- Returns:
- True for a valid message.
-
validate
public Builder validate()
Description copied from class:PMessageBuilder
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.- Specified by:
validate
in classPMessageBuilder<Message extends PMessage<Message>>
- Returns:
- The builder itself.
-
set
@Nonnull public Builder set(int key, java.lang.Object value)
Description copied from class:PMessageBuilder
Set the provided field value.- Specified by:
set
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
key
- The key of the field to set.value
- The value to be set.- Returns:
- The message builder.
-
isSet
public boolean isSet(int key)
Description copied from class:PMessageBuilder
Checks if a specific field is set on the builder.- Specified by:
isSet
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
key
- The key of the field to check.- Returns:
- True if the field is set.
-
isModified
public boolean isModified(int key)
Description copied from class:PMessageBuilder
Checks if a specific field is modified on the builder.- Specified by:
isModified
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
key
- The key of the field to check.- Returns:
- True if the field is modified.
-
addTo
@Nonnull public Builder addTo(int key, java.lang.Object value)
Description copied from class:PMessageBuilder
Adds a value to a set or list container.- Specified by:
addTo
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
key
- The key of the container field to add too.value
- The value to add.- Returns:
- The builder itself.
-
clear
@Nonnull public Builder clear(int key)
Description copied from class:PMessageBuilder
Clear the provided field value.- Specified by:
clear
in classPMessageBuilder<Message extends PMessage<Message>>
- Parameters:
key
- The key of the field to clear.- Returns:
- The builder itself.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
has
public boolean has(int key)
- Parameters:
key
- The key of the field.- Returns:
- Whether the field is present.
-
get
public <T> T get(int key)
- Type Parameters:
T
- The return type.- Parameters:
key
- The key of the field.- Returns:
- The value of the field.
-
-