Class Message

java.lang.Object
com.luchersol.core.util.Message

public class Message extends Object
Represents a formatted message with an optional code and arguments.

This class is used for generating messages that can be displayed, logged, or associated with validation errors. Messages can be created from a predefined code (with arguments) or directly from a string.

  • Constructor Details

    • Message

      public Message(String code, String message, Object... args)
      Constructs a new Message with the given code, message template, and arguments.
      Parameters:
      code - the message code (can be null if not applicable)
      message - the message template or literal string
      args - optional arguments to format the message
  • Method Details

    • ofCode

      public static Message ofCode(String code, Object... args)
      Creates a new Message from a code and optional arguments. The text is retrieved from the message service.
      Parameters:
      code - the message code
      args - optional arguments for formatting
      Returns:
      a new Message instance
    • ofMessage

      public static Message ofMessage(String message)
      Creates a new Message from a literal string.
      Parameters:
      message - the literal message
      Returns:
      a new Message instance
    • getCode

      public String getCode()
      Returns the message code.
      Returns:
      the code associated with this message, or null if none
    • getErrorMessage

      public static Message getErrorMessage()
      Returns a standard error message with formatting applied (e.g., color and style).
      Returns:
      a Message instance representing a formatted error
    • getMessage

      public String getMessage()
      Returns the formatted message string.
      Returns:
      the message text
    • negate

      public Message negate()
      Returns a negated version of this message by appending ".__not" to the code and reformatting the message accordingly.
      Returns:
      this Message instance after negation