- java.lang.Object
-
- net.sourceforge.urin.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 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_DECODER
TheMakingDecoder
used 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 boolean
hasValue()
Returns true ifvalue()
can be called on thisSegment
.static Segment<java.lang.String>
segment(java.lang.String segment)
Factory method for creatingSegment
s.static <T> Segment<T>
segment(T segment, PercentEncodingPartial<T,java.lang.String> percentEncodingPartial)
Factory method for creating non-String
Segment
s.abstract ENCODES
value()
Gets the (non-encoded) value of this segment, if it is a type that has a value, or throwsUnsupportedOperationException
otherwise.
-
-
-
Field Detail
-
STRING_SEGMENT_MAKING_DECODER
public static final MakingDecoder<Segment<java.lang.String>,java.lang.String,java.lang.String> STRING_SEGMENT_MAKING_DECODER
TheMakingDecoder
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 creatingSegment
s.- Parameters:
segment
- anyString
to represent as aSegment
.- Returns:
- a
Segment
representing the givenString
.
-
segment
public static <T> Segment<T> segment(T segment, PercentEncodingPartial<T,java.lang.String> percentEncodingPartial)
Factory method for creating non-String
Segment
s.- Type Parameters:
T
- the type ofObject
theSegment
encodes.- Parameters:
segment
- anyObject
to represent as aSegment
.percentEncodingPartial
- an encoding fromT
toString
.- Returns:
- a
Segment
representing 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 throwsUnsupportedOperationException
otherwise.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.
-
-