-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new type RingRange represents token ranges
- Loading branch information
Showing
10 changed files
with
126 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.spotify.reaper.service; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class RingRange { | ||
private final BigInteger start; | ||
private final BigInteger end; | ||
|
||
public RingRange(BigInteger start, BigInteger end) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public BigInteger getStart() { | ||
return start; | ||
} | ||
|
||
public BigInteger getEnd() { | ||
return end; | ||
} | ||
|
||
public BigInteger span(BigInteger ringSize) { | ||
if (SegmentGenerator.greaterThanOrEqual(start, end)) { | ||
return end.subtract(start).add(ringSize); | ||
} else { | ||
return end.subtract(start); | ||
} | ||
} | ||
|
||
public boolean encloses(RingRange other) { | ||
// TODO: unit test for this | ||
if (SegmentGenerator.lowerThanOrEqual(start, end)) { | ||
return SegmentGenerator.greaterThanOrEqual(other.start, start) && | ||
SegmentGenerator.lowerThanOrEqual(other.end, end); | ||
} else if (SegmentGenerator.lowerThanOrEqual(other.start, other.end)) { | ||
return SegmentGenerator.greaterThanOrEqual(other.start, start) || | ||
SegmentGenerator.lowerThanOrEqual(other.end, end); | ||
} else { | ||
return SegmentGenerator.greaterThanOrEqual(other.start, start) && | ||
SegmentGenerator.lowerThanOrEqual(other.end, end); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("(%s,%s]", start.toString(), end.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.