Class StructuredFieldBareItem

java.lang.Object
org.apache.hc.core5.http.structured.StructuredFieldBareItem

@Contract(threading=IMMUTABLE) public final class StructuredFieldBareItem extends Object
Immutable Structured Field bare Item.
Since:
5.5
  • Field Details

  • Constructor Details

  • Method Details

    • ofInteger

      public static StructuredFieldBareItem ofInteger(long value)
      Creates an Integer bare Item.
      Parameters:
      value - the integer value.
      Returns:
      the bare Item.
      Throws:
      IllegalArgumentException - if the value is outside the Structured Field range.
    • ofDecimal

      public static StructuredFieldBareItem ofDecimal(BigDecimal value)
      Creates a Decimal bare Item, applying the Structured Field rounding algorithm.
      Parameters:
      value - the decimal value.
      Returns:
      the bare Item.
      Throws:
      IllegalArgumentException - if the rounded value has more than 12 integer digits.
    • ofString

      public static StructuredFieldBareItem ofString(String value)
      Creates an ASCII String bare Item.
      Parameters:
      value - the printable ASCII value.
      Returns:
      the bare Item.
      Throws:
      IllegalArgumentException - if the value contains a character outside SP through ~.
    • ofToken

      public static StructuredFieldBareItem ofToken(String value)
      Creates a Token bare Item.
      Parameters:
      value - the token value.
      Returns:
      the bare Item.
      Throws:
      IllegalArgumentException - if the value is not an Structured Field token.
    • ofByteSequence

      public static StructuredFieldBareItem ofByteSequence(byte[] value)
      Creates a Byte Sequence bare Item using a defensive copy.
      Parameters:
      value - the byte sequence.
      Returns:
      the bare Item.
    • ofBoolean

      public static StructuredFieldBareItem ofBoolean(boolean value)
      Creates a Boolean bare Item.
      Parameters:
      value - the boolean value.
      Returns:
      the bare Item.
    • ofDate

      public static StructuredFieldBareItem ofDate(long epochSeconds)
      Creates a Date bare Item expressed as seconds since the Unix epoch.
      Parameters:
      epochSeconds - seconds since the Unix epoch.
      Returns:
      the bare Item.
      Throws:
      IllegalArgumentException - if the value is outside the Structured Field Integer range.
    • ofDisplayString

      public static StructuredFieldBareItem ofDisplayString(String value)
      Creates a Unicode Display String bare Item.
      Parameters:
      value - the Unicode value.
      Returns:
      the bare Item.
      Throws:
      IllegalArgumentException - if the value contains an unpaired surrogate.
    • checkInteger

      private static void checkInteger(long value)
    • getType

      public StructuredFieldType getType()
      Returns:
      the bare Item type.
    • getValue

      public Object getValue()
      Returns the value using its Java representation. Byte sequences are defensively copied.
      Returns:
      the value.
    • getLongValue

      public long getLongValue()
      Returns:
      the Integer or Date value.
      Throws:
      IllegalStateException - if this Item is not an Integer or Date.
    • getDecimalValue

      public BigDecimal getDecimalValue()
      Returns:
      the Decimal value.
      Throws:
      IllegalStateException - if this Item is not a Decimal.
    • getTextValue

      public String getTextValue()
      Returns:
      the String, Token, or Display String value.
      Throws:
      IllegalStateException - if this Item is not one of those textual types.
    • getByteSequenceValue

      public byte[] getByteSequenceValue()
      Returns:
      a defensive copy of the Byte Sequence value.
      Throws:
      IllegalStateException - if this Item is not a Byte Sequence.
    • getBooleanValue

      public boolean getBooleanValue()
      Returns:
      the Boolean value.
      Throws:
      IllegalStateException - if this Item is not a Boolean.
    • requireType

      private void requireType(StructuredFieldType... expected)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object