Class Segment<ENCODES>

  • Type Parameters:
    ENCODES - The type of value represented by the segment - String in the general case.

    public abstract class Segment<ENCODES>
    extends java.lang.Object
    A segment of a URI's path.

    Note that the special segments "." and ".." are obtained via the factory methods dot() and dotDot() respectively. Passing "." or ".." as an argument to the factory method segment(String) is not equivalent, as the argument to this method is a literal string, i.e. subject to encoding where necessary.

    Immutable and thread safe.

    See Also:
    RFC 3986 - Path
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static <ENCODES> Segment<ENCODES> dot()
      The segment ".", referring to the current location in the path name hierarchy.
      static <ENCODES> Segment<ENCODES> dotDot()
      The segment "..", referring to the parent location in the path name hierarchy.
      static <ENCODES> Segment<ENCODES> empty()
      An empty segment - one that is encoded as "" in a URI.
      abstract boolean hasValue()
      Returns true if value() can be called on this Segment.
      static Segment<java.lang.String> segment​(java.lang.String segment)
      Factory method for creating Segments.
      static <T> Segment<T> segment​(T segment, PercentEncodingPartial<T,​java.lang.String> percentEncodingPartial)
      Factory method for creating non-String Segments.
      abstract ENCODES value()
      Gets the (non-encoded) value of this segment, if it is a type that has a value, or throws UnsupportedOperationException otherwise.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • STRING_SEGMENT_MAKING_DECODER

        public static final MakingDecoder<Segment<java.lang.String>,​java.lang.String,​java.lang.String> STRING_SEGMENT_MAKING_DECODER
        The MakingDecoder used by standard segments.
    • Method Detail

      • dot

        public static <ENCODES> Segment<ENCODES> dot()
        The segment ".", referring to the current location in the path name hierarchy.
        Type Parameters:
        ENCODES - The type of value represented by the segment - String in the general case.
        Returns:
        The segment ".", referring to the current location in the path name hierarchy
      • dotDot

        public static <ENCODES> Segment<ENCODES> dotDot()
        The segment "..", referring to the parent location in the path name hierarchy.
        Type Parameters:
        ENCODES - The type of value represented by the segment - String in the general case.
        Returns:
        The segment "..", referring to the current location in the path name hierarchy
      • empty

        public static <ENCODES> Segment<ENCODES> empty()
        An empty segment - one that is encoded as "" in a URI.
        Type Parameters:
        ENCODES - The type of value represented by the segment - String in the general case.
        Returns:
        The empty segment - one that is encoded as "" in a URI
      • segment

        public static Segment<java.lang.String> segment​(java.lang.String segment)
        Factory method for creating Segments.
        Parameters:
        segment - any String to represent as a Segment.
        Returns:
        a Segment representing the given String.
      • segment

        public static <T> Segment<T> segment​(T segment,
                                             PercentEncodingPartial<T,​java.lang.String> percentEncodingPartial)
        Factory method for creating non-String Segments.
        Type Parameters:
        T - the type of Object the Segment encodes.
        Parameters:
        segment - any Object to represent as a Segment.
        percentEncodingPartial - an encoding from T to String.
        Returns:
        a Segment representing the given Object.
      • hasValue

        public abstract boolean hasValue()
        Returns true if value() can be called on this Segment. This method returns false for empty, . and .. segments.
        Returns:
        true if value() can be called on this Segment.
      • value

        public abstract ENCODES value()
        Gets the (non-encoded) value of this segment, if it is a type that has a value, or throws UnsupportedOperationException otherwise.

        Dot segments (. and ..) and the empty segment do not have values, and will throw UnsupportedOperationException. This can be tested by equality with the objects returned by dot(), dotDot(), and empty() methods, or by calling hasValue().

        Returns:
        the (non-encoded) value of this segment.
        Throws:
        java.lang.UnsupportedOperationException - if this is a segment that does not represent a value.