Record Class Topic

java.lang.Object
java.lang.Record
org.mqtt4j.hato.Topic
Record Components:
name - the topic name

public record Topic(String name) extends Record

A validated MQTT topic name used when publishing a message.

Names are non-empty, contain neither NUL nor the wildcards + and #, and must encode as well-formed UTF-8 in at most 65535 bytes. Names are case-sensitive and preserved exactly: whitespace, empty levels separated by /, and a byte order mark are not removed or normalized.

The validation rules follow MQTT 3.1.1 Plus Errata 01:

  • Constructor Summary

    Constructors
    Constructor
    Description
    Topic(String name)
    Creates a topic after validating its name.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the name record component.
    Returns the topic name unchanged.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Topic

      public Topic(String name)
      Creates a topic after validating its name.
      Parameters:
      name - the topic name
      Throws:
      NullPointerException -
      if `name` is null
      
      IllegalArgumentException -
      if `name` is empty, contains NUL, a wildcard, or an unpaired surrogate, or exceeds
      65535 bytes in UTF-8
      
  • Method Details

    • toString

      public String toString()
      Returns the topic name unchanged.
      Specified by:
      toString in class Record
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final 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.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component