public interface Segment
Pattern.
Each segment consists of an ordered sequence of elements, either abstract sequence (range), or sequence of literals.
| Modifier and Type | Method and Description |
|---|---|
String |
getElement(int index)
Returns i-th element in the segment's definition (the first element having index
0). |
int |
getElementLength(int index)
Returns length (in characters) of the i-th element in the segment's definition (the first element having
index
0). |
int |
length()
Returns the length of the segment - amount of elements in the segment's definition.
|
static Segment |
literal(String... elements)
Creates a segment from the given elements.
|
int |
parse(String versionId,
int index)
Parses the given version ID, starting from the provided index and returns the index of element that was matched.
|
static Segment |
range(int start,
int end)
Creates a segment from the given range properties.
|
static Segment |
range(int start,
int end,
int step)
Creates a segment from the given range properties.
|
static Segment |
range(int start,
int end,
int step,
int fill)
Creates a segment from the given range properties.
|
static Segment range(int start, int end, int step, int fill)
The range is defined by start (inclusive) and end (exclusive) boundaries and difference
between each integer called step. To get i-th element of the range, we can use this formula:
start + step*i
Filling defines how long (in digits) must each integer in the range be. If an integer in the range has fewer
digits than defined by the parameter, additional zeros (0) are prepended to fulfill the requirement
(5 -> 005 for fill=3). Set to non-positive (<= 0) value to
disable.
Please mind following:
step must not be equal to 0,start cannot be equal to end,step must be specified accordingly to the boundaries, if start < end it must be positive (and vice-versa),>= 0, which implies the same for start, but not necessarily for end (which may be negative),fill > 0, each integer in the range must have at most fill digits (e.g. no 3 digit integer for fill=2); mathematical notation: 0 <= each range integer <= 10fill - 1.IllegalArgumentException is thrown.start - starting boundary (inclusive) of the range, also the first element in the rangeend - ending boundary (exclusive) of the rangestep - difference between each neighboring elements in the range (value needed to add to get from element
i to i+1)fill - filling parameter (or <= 0 to disable)static Segment range(int start, int end, int step)
The range is defined by start (inclusive) and end (exclusive) boundaries and difference
between each integer called step. To get i-th element of the range, we can use this formula:
start + step*i
Please mind following:
step must not be equal to 0,start cannot be equal to end,step must be specified accordingly to the boundaries, if start < end it must be positive (and vice-versa),>= 0, which implies the same for start, but not necessarily for end (which may be negative),IllegalArgumentException is thrown.start - starting boundary (inclusive) of the range, also the first element in the rangeend - ending boundary (exclusive) of the rangestep - difference between each neighboring elements in the range (value needed to add to get from element
i to i+1)range(int, int, int, int)static Segment range(int start, int end)
The range is defined by start (inclusive) and end (exclusive) boundaries. Difference
between each integer in the range will be 1 if start < end, -1
otherwise.
Please mind following:
step must not be equal to 0,start cannot be equal to end,>= 0, which implies the same for start, but not necessarily for end (which may be negative),IllegalArgumentException is thrown.start - starting boundary (inclusive) of the range, also the first element in the rangeend - ending boundary (exclusive) of the rangerange(int, int, int, int)static Segment literal(String... elements)
elements - the elementsint parse(String versionId, int index)
For LiteralSegment, this is the first element to which String.startsWith(String) returns
true. For RangeSegment, this is the shortest sequence of characters at the start which
represent a number within this range.
If no element in the segment is matched, returns -1. This might be the case if the ID is malformed,
or if the individual segments overlap each other.
versionId - the version ID to parseindex - starting index from which to parse the IDString getElement(int index)
0).
It must apply that 0 <= i < length(), otherwise, an IndexOutOfBoundsException will be
thrown.
index - the indexint getElementLength(int index)
0).
It must apply that 0 <= i < length(), otherwise, an IndexOutOfBoundsException will be
thrown.
index - the indexint length()
Copyright © 2022. All rights reserved.