Package com.jsgalactic.axiom.http
Record Class EntityTag
java.lang.Object
java.lang.Record
com.jsgalactic.axiom.http.EntityTag
- Record Components:
weak- whether the tag carries theW/prefixopaqueTag- the characters between the quotes, never empty
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 -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theopaqueTagrecord component.Parses one entity tag.booleanstrongMatches(EntityTag other) Compares two tags with the strong rule: neither may be weak and the opaque values must be identical.toString()Returns a string representation of this record class.booleanweak()Returns the value of theweakrecord component.booleanweakMatches(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.
-
Constructor Details
-
EntityTag
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
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
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
weak
public boolean weak()Returns the value of theweakrecord component.- Returns:
- the value of the
weakrecord component
-
opaqueTag
Returns the value of theopaqueTagrecord component.- Returns:
- the value of the
opaqueTagrecord component
-