Record Class Message

java.lang.Object
java.lang.Record
io.micronaut.views.fields.messages.Message
Record Components:
defaultMessage - The default message to use if no code is specified or no localized message found.
code - The i18n code which can be used to fetch a localized message.
variables - The variables to use resolve message placeholders
All Implemented Interfaces:
Comparable<Message>

@Introspected public record Message(@NonNull @NotBlank String defaultMessage, @Nullable String code, @Nullable Object[] variables) extends Record implements Comparable<Message>
Message representation. It features an optional code() to allow localization.
Since:
4.1.0
Author:
Sergio del Amo
  • Constructor Details

    • Message

      public Message(@NonNull @NonNull String defaultMessage, @Nullable @Nullable String code)
    • Message

      public Message(@NonNull @NotBlank @NonNull @NotBlank String defaultMessage, @Nullable @Nullable String code, @Nullable @Nullable Object[] variables)
      Creates an instance of a Message record class.
      Parameters:
      defaultMessage - the value for the defaultMessage record component
      code - the value for the code record component
      variables - the value for the variables record component
  • Method Details

    • equals

      public boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • compareTo

      public int compareTo(Message o)
      Specified by:
      compareTo in interface Comparable<Message>
    • of

      @NonNull public static @NonNull Message of(@NonNull @NonNull String defaultMessage, @Nullable @Nullable String code)
      Parameters:
      defaultMessage - The default message to use if no code is specified or no localized message found
      code - The i18n code which can be used to fetch a localized message.
      Returns:
      A Message instance.
    • of

      @NonNull public static @NonNull Message of(@NonNull @NonNull String defaultMessage, @Nullable @Nullable String code, @Nullable @Nullable Object... variables)
      Parameters:
      defaultMessage - The default message to use if no code is specified or no localized message found
      code - The i18n code which can be used to fetch a localized message.
      variables - The variables to use resolve message placeholders
      Returns:
      A Message instance.
    • of

      @NonNull public static @NonNull Message of(@NonNull @NonNull String defaultMessage)
      Parameters:
      defaultMessage - The default message to use if no code is specified or no localized message found
      Returns:
      A Message instance.
    • of

      @NonNull public static @NonNull Message of(Class<?> type, String name)
      Parameters:
      type - Field Type
      name - Field name
      Returns:
      A Message instance.
    • of

      @NonNull public static @NonNull Message of(@NonNull @NonNull io.micronaut.core.beans.BeanProperty<?,?> beanProperty)
      Parameters:
      beanProperty - A Bean Property
      Returns:
      A Message instance.
    • of

      @NonNull public static @NonNull Message of(@NonNull @NonNull jakarta.validation.ConstraintViolation<?> violation)
      Parameters:
      violation - Constraint Violation
      Returns:
      A Message instance.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • defaultMessage

      @NonNull @NotBlank public @NonNull @NotBlank String defaultMessage()
      Returns the value of the defaultMessage record component.
      Returns:
      the value of the defaultMessage record component
    • code

      @Nullable public @Nullable String code()
      Returns the value of the code record component.
      Returns:
      the value of the code record component
    • variables

      @Nullable public @Nullable Object[] variables()
      Returns the value of the variables record component.
      Returns:
      the value of the variables record component