public interface Segment
Pattern
.Modifier and Type | Method and Description |
---|---|
String |
getElement(int index)
Returns i-th element in the segment's definition (1st element being represented by
0 ). |
int |
getElementLength(int index)
Returns length (in characters) of the i-th element in the segment's definition (1st element being represented by
0 ). |
int |
length()
The length of the segment - amount of elements in the segment's definition.
|
static Segment |
literal(String... elements)
Creates a segment with the given elements.
|
int |
parse(String versionId,
int index)
Parses the given version ID from the given index and returns which element (represented by the index) was
matched.
|
static Segment |
range(int start,
int end)
Creates a segment from the given range.
|
static Segment |
range(int start,
int end,
int step)
Creates a segment from the given range.
|
static Segment |
range(int start,
int end,
int step,
int fill)
Creates a segment from the given range.
|
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 element 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 element (= integer) in the range be. If an element in the range
has fewer digits than defined by the parameter, additional zeros (0
) are appended in front of the
number to fulfill the requirement. It must, however, be guaranteed that no number from the range has more digits
than defined by the parameter. Set to non-positive (<= 0
) integer 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
, meaning the same for start
, but not for end
, which can be negative,fill > 0
, no element must in it's base representation have more digits than defined by the parameter.IllegalArgumentException
is thrown.start
- starting boundary (inclusive) of the range, also the 1st element in the rangeend
- ending boundary (exclusive) of the rangestep
- difference between each 2 elements in the range (step needed to make 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 element called step
. To get i-th element of the range, we can use this formula:
start + step*i
Filling is disabled.
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
, meaning the same for start
, but not for end
, which can be negative.IllegalArgumentException
is thrown.start
- starting boundary (inclusive) of the range, also the 1st element in the rangeend
- ending boundary (exclusive) of the rangestep
- difference between each 2 elements in the range (step needed to make 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. Step is equal
to 1
if start < end
, -1
otherwise. Filling is disabled.
Please mind following:
start
cannot be equal to end
,>= 0
, meaning the same for start
, but not for end
, which can be negative.IllegalArgumentException
is thrown.start
- starting boundary (inclusive) of the range, also the 1st 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 matches the start of the ID, returns -1
. This might be the case if the
ID is malformed, or if the individual parts overlapping each other.
versionId
- the version ID to parseindex
- the index in the ID from which to parseString 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.