Record Class InvalidMessage
java.lang.Object
java.lang.Record
com.winterhavenmc.library.messagebuilder.model.message.InvalidMessage
- Record Components:
reason
- the reason this message is considered invalid
- All Implemented Interfaces:
Message
A fallback
Message
implementation representing an invalid or unrenderable message.
This is returned by the system when a message cannot be composed — for example,
due to a null
recipient or missing configuration.
Calling send()
on an InvalidMessage
results in a no-op.
The reason for failure is stored in the reason
field for debugging
or logging purposes.
This class is typically returned by:
Message.empty()
- Internal pipeline safeguards during failed message composition
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionInvalidMessage
(String reason) Creates an instance of aInvalidMessage
record class. -
Method Summary
Modifier and TypeMethodDescriptionstatic InvalidMessage
empty()
Returns a reusableInvalidMessage
instance representing an empty message caused by anull
recipient passed to thecompose()
method.final boolean
Indicates whether some other object is "equal to" this one.Returns theRecordKey
identifying the message template used in composition.Returns theMacroObjectMap
of macro values bound to this message.Returns theRecipient.Sendable
to whom the message will be sent.final int
hashCode()
Returns a hash code value for this object.reason()
Returns the value of thereason
record component.void
send()
Sends the composed message to the resolved recipient, if valid.setMacro
(int quantity, K macro, V value) Associates a macro key with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.setMacro
(K macro, Duration duration, ChronoUnit lowerBound) Associates a duration with the given macro key, using a defined precision.setMacro
(K macro, V value) Associates a macro key with a value for later substitution during message rendering.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
InvalidMessage
Creates an instance of aInvalidMessage
record class.- Parameters:
reason
- the value for thereason
record component
-
-
Method Details
-
empty
Returns a reusableInvalidMessage
instance representing an empty message caused by anull
recipient passed to thecompose()
method.- Returns:
- a shared instance of an
InvalidMessage
with a standard failure reason
-
setMacro
Description copied from interface:Message
Associates a macro key with a value for later substitution during message rendering. -
setMacro
Description copied from interface:Message
Associates a macro key with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts. -
setMacro
Description copied from interface:Message
Associates a duration with the given macro key, using a defined precision.- Specified by:
setMacro
in interfaceMessage
- Type Parameters:
K
- the enum type of the macro- Parameters:
macro
- the macro keyduration
- theDuration
to be formatted and resolvedlowerBound
- theChronoUnit
to control formatting granularity- Returns:
- the same
Message
instance, for fluent chaining
-
send
public void send()Description copied from interface:Message
Sends the composed message to the resolved recipient, if valid.No-op if the message is invalid or the recipient is missing or unsupported.
-
getMessageKey
Description copied from interface:Message
Returns theRecordKey
identifying the message template used in composition.- Specified by:
getMessageKey
in interfaceMessage
- Returns:
- the message key
-
getRecipient
Description copied from interface:Message
Returns theRecipient.Sendable
to whom the message will be sent.- Specified by:
getRecipient
in interfaceMessage
- Returns:
- the message recipient
-
getObjectMap
Description copied from interface:Message
Returns theMacroObjectMap
of macro values bound to this message.- Specified by:
getObjectMap
in interfaceMessage
- Returns:
- the macro object map
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
reason
Returns the value of thereason
record component.- Returns:
- the value of the
reason
record component
-