Class MessageBuilder

java.lang.Object
org.refcodes.textual.MessageBuilder
All Implemented Interfaces:
org.refcodes.mixin.ArgumentsAccessor<Object>, org.refcodes.mixin.ArgumentsAccessor.ArgumentsBuilder<Object,MessageBuilder>, org.refcodes.mixin.ArgumentsAccessor.ArgumentsMutator<Object>, org.refcodes.mixin.ArgumentsAccessor.ArgumentsProperty<Object>, org.refcodes.mixin.MessageAccessor, org.refcodes.mixin.MessageAccessor.MessageBuilder<MessageBuilder>, org.refcodes.mixin.MessageAccessor.MessageMutator, org.refcodes.mixin.MessageAccessor.MessageProperty

public class MessageBuilder extends Object implements org.refcodes.mixin.MessageAccessor.MessageProperty, org.refcodes.mixin.MessageAccessor.MessageBuilder<MessageBuilder>, org.refcodes.mixin.ArgumentsAccessor.ArgumentsProperty<Object>, org.refcodes.mixin.ArgumentsAccessor.ArgumentsBuilder<Object,MessageBuilder>
Wraps MessageFormat.format(String, Object...) to prevent failing when message cannot be formatted. Also expands any arrays passed inside the arguments to a comma separated String of the array's elements as of Arrays.toString(Object[]) without the square braces: In case such an expanded array's length is 0, then the according placeholder (such as "{0}", "{1}" and "{2}" and so on) is preserved in the resulting String!
  • Constructor Details

    • MessageBuilder

      public MessageBuilder()
  • Method Details

    • getMessage

      public String getMessage()
      Specified by:
      getMessage in interface org.refcodes.mixin.MessageAccessor
    • setMessage

      public void setMessage(String aMessage)
      Specified by:
      setMessage in interface org.refcodes.mixin.MessageAccessor.MessageMutator
    • getArguments

      public Object[] getArguments()
      Specified by:
      getArguments in interface org.refcodes.mixin.ArgumentsAccessor<Object>
    • setArguments

      public void setArguments(Object[] aArguments)
      Specified by:
      setArguments in interface org.refcodes.mixin.ArgumentsAccessor.ArgumentsMutator<Object>
    • withArguments

      public MessageBuilder withArguments(Object[] aArguments)
      Specified by:
      withArguments in interface org.refcodes.mixin.ArgumentsAccessor.ArgumentsBuilder<Object,MessageBuilder>
    • withMessage

      public MessageBuilder withMessage(String aMessage)
      Specified by:
      withMessage in interface org.refcodes.mixin.MessageAccessor.MessageBuilder<MessageBuilder>
    • toMessage

      public String toMessage()
      Wraps MessageFormat.format(String, Object...) to prevent failing when message cannot be formatted. Also expands any arrays passed inside the arguments to a comma separated String of the array's elements as of Arrays.toString(Object[]) without the square braces: In case such an expanded array's length is 0, then the according placeholder (such as "{0}", "{1}" and "{2}" and so on) is preserved in the resulting String!
      Returns:
      The substituted message.
    • toString

      public String toString()
      Calls toMessage() and returns its result. The according String.
      Overrides:
      toString in class Object
      Returns:
      the string
    • asMessage

      public static String asMessage(String aMessage, Object... aArguments)
      Wraps MessageFormat.format(String, Object...) to prevent failing when message cannot be formatted. Also expands any arrays passed inside the arguments to a comma separated String of the array's elements as of Arrays.toString(Object[]) without the square braces: In case such an expanded array's length is 0, then the according placeholder (such as "{0}", "{1}" and "{2}" and so on) is preserved in the resulting String!
      Parameters:
      aMessage - The message to be formatted by substituting the placeholder ("{0}", "{1}" and "{2}" and so on) with the according arguemtns's elements.
      aArguments - the arguments The arguments which are used for substitution.
      Returns:
      The substituted message.