Package org.eclipse.emf.common.util
Class SegmentSequence
java.lang.Object
org.eclipse.emf.common.util.SegmentSequence
- All Implemented Interfaces:
CharSequence
A memory efficient structure to store a sequence of delimited string segments.
A segment sequence can only be created through one the create methods.
Pooling ensures that
== can be used instead of Object.equals(Object) to test for equality,
i.e., at most one instance can exist for any given delimiter and sequence of segments.
The hash code implementation ensures that the hash code of a segment sequence is identical to the hash code of it's string representation.
In addition, the delimiter and the segments use string and string array pooling.
Null segments are not permitted.- Since:
- 2.9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for creating acomposed stringor aSegmentSequence.Builder.toSegmentSequence().protected static classA cached pool of weakly referenced segment sequences.protected static classA specialized pool for caching string arrays. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringThe delimiter for this instance.protected final intThe cached hash code for this instance.protected static final SegmentSequence.SegmentSequencePoolThe cached pool for the segment sequence instances.protected final String[]The segments for this instance.protected static final SegmentSequence.StringArrayPoolThe cached pool for string arrays.protected WeakReference<String> The cached value fortoString(). -
Method Summary
Modifier and TypeMethodDescriptionReturns an instance with the additional segment or segments, if the given segment contains '/'.append(SegmentSequence segmentSequence) Returns an instance with the given additional segments.charcharAt(int index) Returns the specified character in thestringrepresentation of the sequence.static SegmentSequenceReturns the empty segment sequence for the given delimiter.static SegmentSequenceReturns the segment sequence for the value, splitting it into segments as appropriate, ornullif the value is null.static SegmentSequenceReturns the segment sequence for the given segments, splitting individual segments as necessary, i.e., if they contain the delimiter character, or omitting empty segments in the case of the empty delimiter.protected static SegmentSequenceReturns the delimiter of the segment sequence.Returns the first segment of the segment sequence, ornullif there are no segments.inthashCode()Although there is an override of hash code, there is no override ofObject.equals(Object)because the static methods for creation guarantee that there is at most one instance created for each unique segment sequence.Returns the last segment of the segment sequence, ornullif there are no segments.intlength()Returns the number of characters in thestringrepresentation.protected booleanReturns true if the delimiter is the same as this segment sequence's delimiter and thestring representationof this segment sequence is equal to the given string.static SegmentSequence.BuildernewBuilder(String delimiter) Creates a new builder for the given delimiter.static SegmentSequence.BuildernewBuilder(String delimiter, int capacity) Creates a new builder for the given delimiter with the given capacity of strings before the buffer needs to grow.segment(int index) Returns the segment at the given index of the segment sequence.intReturns the number of segments in the segment sequence.String[]segments()Returns the segments of this segment sequence.Returns a read-only list view of the segments.protected static String[]Splits individual segments as necessary, i.e., if they contain the delimiter character, or omits empty segments in the case of the empty delimiter.String[]subSegments(int start) Returns the segments from the given start.String[]subSegments(int start, int end) Returns the segments from the given start and before the given end.subSegmentsList(int start) Returns a read-only list view of the segments from the given start.subSegmentsList(int start, int end) Returns a read-only list view of the segments from the given start and before the given end.subSequence(int start, int end) Returns the requested subsequence in the representation of the sequence.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
POOL
The cached pool for the segment sequence instances. -
STRING_ARRAY_POOL
The cached pool for string arrays. -
hashCode
protected final int hashCodeThe cached hash code for this instance. -
delimiter
The delimiter for this instance. -
segments
The segments for this instance. -
toString
The cached value fortoString().
-
-
Method Details
-
append
Returns an instance with the given additional segments. If this segment sequence'sdelimiteris different from that of the argument, the segments of the argument will be split if they contain the delimiter. -
append
Returns an instance with the additional segment or segments, if the given segment contains '/'. -
append
-
length
public int length()Returns the number of characters in thestringrepresentation.- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) Returns the specified character in thestringrepresentation of the sequence.- Specified by:
charAtin interfaceCharSequence
-
subSequence
Returns the requested subsequence in the representation of the sequence.- Specified by:
subSequencein interfaceCharSequence
-
toString
Returns the string representation for this sequence, i.e., the concatenation of thedelimiter-separatedsegments.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
delimiter
Returns the delimiter of the segment sequence. -
segments
Returns the segments of this segment sequence. -
subSegments
Returns the segments from the given start. -
subSegments
Returns the segments from the given start and before the given end. -
segmentsList
Returns a read-only list view of the segments. -
subSegmentsList
Returns a read-only list view of the segments from the given start. -
subSegmentsList
Returns a read-only list view of the segments from the given start and before the given end. -
segmentCount
public int segmentCount()Returns the number of segments in the segment sequence. -
segment
Returns the segment at the given index of the segment sequence. -
lastSegment
Returns the last segment of the segment sequence, ornullif there are no segments. -
firstSegment
Returns the first segment of the segment sequence, ornullif there are no segments. -
hashCode
public int hashCode()Although there is an override of hash code, there is no override ofObject.equals(Object)because the static methods for creation guarantee that there is at most one instance created for each unique segment sequence. -
matches
Returns true if the delimiter is the same as this segment sequence's delimiter and thestring representationof this segment sequence is equal to the given string. -
create
Returns the segment sequence for the value, splitting it into segments as appropriate, ornullif the value is null. -
create
Returns the empty segment sequence for the given delimiter. -
create
Returns the segment sequence for the given segments, splitting individual segments as necessary, i.e., if they contain the delimiter character, or omitting empty segments in the case of the empty delimiter.- Throws:
NullPointerException- if the segments itself or any individual segment among the segments isnull.
-
create
-
split
Splits individual segments as necessary, i.e., if they contain the delimiter character, or omits empty segments in the case of the empty delimiter. If no segment contains the delimiter, or in the case of the empty delimiter, no segments are empty, the original argument is returned.- Throws:
NullPointerException- if the segments itself or any individual segments among the segments isnull.
-
newBuilder
Creates a new builder for the given delimiter. The delimiter may be the empty string.- Throws:
NullPointerException- if the delimiter is null.
-
newBuilder
Creates a new builder for the given delimiter with the given capacity of strings before the buffer needs to grow. The delimiter may be the empty string.- Throws:
NullPointerException- if the delimiter is null.
-