public class Segment extends Object implements Comparable<Segment>
Modifier and Type | Field and Description |
---|---|
static Segment |
ROOT_SEGMENT
Represents the Segment that matches against all input, but can be split to start processing elements in parallel.
|
Modifier | Constructor and Description |
---|---|
protected |
Segment(int segmentId,
int mask)
Construct a new Segment instance with given
segmentId and mask |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Segment that) |
static Segment |
computeSegment(int segmentId,
int... availableSegmentIds)
Creates a Segment instance for the given
segmentId based on the given availableSegmentsIds . |
static Segment[] |
computeSegments(int... segments)
Compute the
Segment 's from a given list of segmentId's. |
boolean |
equals(Object o) |
int |
getMask()
Getter for the segment mask.
|
int |
getSegmentId()
Getter for the segment identifier.
|
int |
hashCode() |
boolean |
isMergeableWith(Segment other)
Indicates whether this segment can be merged with the given
other segment. |
boolean |
matches(int value)
Returns
true when the mask applied to the given value, matches the segment id. |
boolean |
matches(Object value)
Indicates whether the given
value matches this segment. |
int |
mergeableSegmentId()
Returns the
segmentId of the segment this one can be merged with |
Segment |
mergedWith(Segment other)
Calculates the Segment that represents the merger of this segment with the given
other segment. |
Segment[] |
split()
Returns an array with two
segments with a corresponding mask .The first entry contains the original segmentId , with the newly calculated mask. |
static List<Segment> |
splitBalanced(Segment segment,
int numberOfTimes)
Split a given
Segment n-times in round robin fashion. |
int |
splitSegmentId()
Returns the segmentId of the counterpart of this segment, if this segment were to be split.
|
String |
toString() |
public static final Segment ROOT_SEGMENT
protected Segment(int segmentId, int mask)
segmentId
and mask
segmentId
- The id of the segmentmask
- The mask of the segmentpublic static Segment[] computeSegments(int... segments)
Segment
's from a given list of segmentId's.segments
- The segment id's for which to compute Segments.Segment
public static Segment computeSegment(int segmentId, int... availableSegmentIds)
segmentId
based on the given availableSegmentsIds
.segmentId
- The Id of the segment to returnavailableSegmentIds
- The available segment Ids, to base the mask of the segment onpublic static List<Segment> splitBalanced(Segment segment, int numberOfTimes)
Segment
n-times in round robin fashion.
public Segment mergedWith(Segment other)
other
segment.other
- the segment to merge this one withpublic int mergeableSegmentId()
segmentId
of the segment this one can be merged withsegmentId
of the segment this one can be merged withpublic boolean isMergeableWith(Segment other)
other
segment.
Two segments can be merged when their mask is identical, and the only difference in SegmentID is in the first 1-bit of their mask.
other
- the Segment to verify mergeability fortrue
if the segments can be merged, otherwise false
public int getSegmentId()
public int getMask()
public boolean matches(int value)
true
when the mask applied to the given value, matches the segment id.value
- The value to be tested.true
when matching this segment.public boolean matches(Object value)
value
matches this segment. A value matches when the hashCode of a value,
after applying this segments mask, equals to this segment ID.value
- The value to verify against.true
if the given value matches this segment, otherwise false
public Segment[] split()
segments with a corresponding mask
.segmentId
, with the newly calculated mask. (Simple left shift, adding a '1' as LSB).
The 2nd entry is a new segmentId
with the same derived mask.
Callers must ensure that either the two returned Segments are used, or the instance from which they are derived, but not both.
Segment
's.public int splitSegmentId()
public int compareTo(Segment that)
compareTo
in interface Comparable<Segment>
Copyright © 2010–2024. All rights reserved.