- java.lang.Object
-
- net.sourceforge.urin.Segment<ENCODES>
-
- Type Parameters:
ENCODES- The type of value represented by the segment -Stringin the general case.
public abstract class Segment<ENCODES> extends java.lang.ObjectA segment of a URI's path.Note that the special segments "
." and ".." are obtained via the factory methodsdot()anddotDot()respectively. Passing "." or ".." as an argument to the factory methodsegment(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
-
-
Field Summary
Fields Modifier and Type Field Description static MakingDecoder<Segment<java.lang.String>,java.lang.String,java.lang.String>STRING_SEGMENT_MAKING_DECODERTheMakingDecoderused by standard segments.
-
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 booleanhasValue()Returns true ifvalue()can be called on thisSegment.static Segment<java.lang.String>segment(java.lang.String segment)Factory method for creatingSegments.static <T> Segment<T>segment(T segment, PercentEncodingPartial<T,java.lang.String> percentEncodingPartial)Factory method for creating non-StringSegments.abstract ENCODESvalue()Gets the (non-encoded) value of this segment, if it is a type that has a value, or throwsUnsupportedOperationExceptionotherwise.
-
-
-
Field Detail
-
STRING_SEGMENT_MAKING_DECODER
public static final MakingDecoder<Segment<java.lang.String>,java.lang.String,java.lang.String> STRING_SEGMENT_MAKING_DECODER
TheMakingDecoderused 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 -Stringin 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 -Stringin 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 -Stringin 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 creatingSegments.- Parameters:
segment- anyStringto represent as aSegment.- Returns:
- a
Segmentrepresenting the givenString.
-
segment
public static <T> Segment<T> segment(T segment, PercentEncodingPartial<T,java.lang.String> percentEncodingPartial)
Factory method for creating non-StringSegments.- Type Parameters:
T- the type ofObjecttheSegmentencodes.- Parameters:
segment- anyObjectto represent as aSegment.percentEncodingPartial- an encoding fromTtoString.- Returns:
- a
Segmentrepresenting the givenObject.
-
hasValue
public abstract boolean hasValue()
Returns true ifvalue()can be called on thisSegment. This method returns false for empty,.and..segments.- Returns:
- true if
value()can be called on thisSegment.
-
value
public abstract ENCODES value()
Gets the (non-encoded) value of this segment, if it is a type that has a value, or throwsUnsupportedOperationExceptionotherwise.Dot segments (
.and..) and the empty segment do not have values, and will throwUnsupportedOperationException. This can be tested by equality with the objects returned bydot(),dotDot(), andempty()methods, or by callinghasValue().- Returns:
- the (non-encoded) value of this segment.
- Throws:
java.lang.UnsupportedOperationException- if this is a segment that does not represent a value.
-
-