/** * Returns an array with two {@link Segment segments with a corresponding mask}.<br/><br/> * The first entry contains the original {@code segmentId}, with the newly calculated mask. (Simple left shift, adding a '1' as LSB). * The 2nd entry is a new {@code segmentId} with the same derived mask. * <p> * Callers must ensure that either the two returned Segments are used, or the instance from which they are derived, * but not both. * * @return an array of two {@link Segment}'s. */ public Segment[] split() { if ((mask << 1) < 0) { throw new IllegalArgumentException("Unable to split the given segmentId, as the mask exceeds the max mask size."); } Segment[] segments = new Segment[2]; int newMask = ((mask << 1) + 1); final int newSegment = segmentId + (mask == 0 ? 1 : newMask ^ mask); segments[0] = new Segment(segmentId, newMask); segments[1] = new Segment(newSegment, newMask); return segments; }
/** * Calculates the Segment that represents the merger of this segment with the given {@code other} segment. * * @param other the segment to merge this one with * @return The Segment representing the merged segments */ public Segment mergedWith(Segment other) { Assert.isTrue(this.isMergeableWith(other), () -> "Given Segment cannot be merged with this segment."); return new Segment(Math.min(this.segmentId, other.segmentId), this.mask >>> 1); }
/** * Returns an array with two {@link Segment segments with a corresponding mask}.<br/><br/> * The first entry contains the original {@code segmentId}, with the newly calculated mask. (Simple left shift, adding a '1' as LSB). * The 2nd entry is a new {@code segmentId} with the same derived mask. * <p> * Callers must ensure that either the two returned Segments are used, or the instance from which they are derived, * but not both. * * @return an array of two {@link Segment}'s. */ public Segment[] split() { if ((mask << 1) < 0) { throw new IllegalArgumentException("Unable to split the given segmentId, as the mask exceeds the max mask size."); } Segment[] segments = new Segment[2]; int newMask = ((mask << 1) + 1); final int newSegment = segmentId + (mask == 0 ? 1 : newMask ^ mask); segments[0] = new Segment(segmentId, newMask); segments[1] = new Segment(newSegment, newMask); return segments; }
/** * Returns an array with two {@link Segment segments with a corresponding mask}.<br/><br/> * The first entry contains the original {@code segmentId}, with the newly calculated mask. (Simple left shift, adding a '1' as LSB). * The 2nd entry is a new {@code segmentId} with the same derived mask. * <p> * Callers must ensure that either the two returned Segments are used, or the instance from which they are derived, * but not both. * * @return an array of two {@link Segment}'s. */ public Segment[] split() { if ((mask << 1) < 0) { throw new IllegalArgumentException("Unable to split the given segmentId, as the mask exceeds the max mask size."); } Segment[] segments = new Segment[2]; int newMask = ((mask << 1) + 1); final int newSegment = segmentId + (mask == 0 ? 1 : newMask ^ mask); segments[0] = new Segment(segmentId, newMask); segments[1] = new Segment(newSegment, newMask); return segments; }
/** * Calculates the Segment that represents the merger of this segment with the given {@code other} segment. * * @param other the segment to merge this one with * @return The Segment representing the merged segments */ public Segment mergedWith(Segment other) { Assert.isTrue(this.isMergeableWith(other), () -> "Given Segment cannot be merged with this segment."); return new Segment(Math.min(this.segmentId, other.segmentId), this.mask >>> 1); }
/** * Calculates the Segment that represents the merger of this segment with the given {@code other} segment. * * @param other the segment to merge this one with * @return The Segment representing the merged segments */ public Segment mergedWith(Segment other) { Assert.isTrue(this.isMergeableWith(other), () -> "Given Segment cannot be merged with this segment."); return new Segment(Math.min(this.segmentId, other.segmentId), this.mask >>> 1); }