Record Class EntityTag

java.lang.Object
java.lang.Record
com.jsgalactic.axiom.http.EntityTag
Record Components:
weak - whether the tag carries the W/ prefix
opaqueTag - the characters between the quotes, never empty

public record EntityTag(boolean weak, String opaqueTag) extends Record
An HTTP entity tag, the validator carried by ETag, If-Match, If-None-Match and If-Range (RFC 9110 section 8.8.3).

Parsing is strict: a tag is an optional W/ prefix followed by a double-quoted opaque value containing only the characters HTTP allows there. Whitespace, embedded quotes, control characters and characters beyond Latin-1 are rejected. A wildcard * is not an entity tag; it is handled by the condition that receives it.

Equality compares both the weakness flag and the opaque value. Use strongMatches(EntityTag) and weakMatches(EntityTag) for the two comparison rules HTTP defines: strong comparison requires both tags to be strong, weak comparison ignores the prefix.

  • Constructor Summary

    Constructors
    Constructor
    Description
    EntityTag(boolean weak, String opaqueTag)
    Validates the opaque value.
  • 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 opaqueTag record component.
    parse(String value)
    Parses one entity tag.
    boolean
    Compares two tags with the strong rule: neither may be weak and the opaque values must be identical.
    Returns a string representation of this record class.
    boolean
    Returns the value of the weak record component.
    boolean
    Compares two tags with the weak rule: only the opaque values must be identical, so a weak tag can match a strong one.

    Methods inherited from class java.lang.Object

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

    • EntityTag

      public EntityTag(boolean weak, String opaqueTag)
      Validates the opaque value.
      Throws:
      IllegalArgumentException - if the opaque value is empty or contains a character that HTTP does not allow in it
  • Method Details

    • parse

      public static Optional<EntityTag> parse(String value)
      Parses one entity tag. A list of tags, a wildcard, or surrounding whitespace is not one tag and yields empty.
      Parameters:
      value - the header value, or null
      Returns:
      the tag, or empty when the value is not exactly one well-formed tag
    • strongMatches

      public boolean strongMatches(EntityTag other)
      Compares two tags with the strong rule: neither may be weak and the opaque values must be identical.
      Parameters:
      other - the tag to compare with
      Returns:
      whether they match strongly
    • weakMatches

      public boolean weakMatches(EntityTag other)
      Compares two tags with the weak rule: only the opaque values must be identical, so a weak tag can match a strong one.
      Parameters:
      other - the tag to compare with
      Returns:
      whether they match weakly
    • toString

      public 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
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • weak

      public boolean weak()
      Returns the value of the weak record component.
      Returns:
      the value of the weak record component
    • opaqueTag

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