Conversation
olim7t
commented
Feb 21, 2017
| return isWrappedAround() | ||
| ? isAfterStart || isBeforeEnd | ||
| : isAfterStart && isBeforeEnd; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Not the most concise but I think clarity is more important.
Contributor
There was a problem hiding this comment.
May I propose another way to do it:
@VisibleForTesting
boolean contains(Token token, boolean isStart) {
if (isEmpty()) {
return false;
}
if (isFull()) {
return true;
}
Token minToken = factory.minToken();
if (token.equals(minToken)) {
return isStart
? start.equals(minToken)
: end.equals(minToken);
}
return isWrappedAround()
? isAfterStart(token, isStart) || isBeforeEnd(token, isStart)
: isAfterStart(token, isStart) && isBeforeEnd(token, isStart);
}
private boolean isFull() {
Token minToken = factory.minToken();
return start.equals(minToken) && end.equals(minToken);
}
private boolean isAfterStart(Token token, boolean isStart) {
Token minToken = factory.minToken();
int c = start.equals(minToken) ? Integer.MIN_VALUE : start.compareTo(token);
return isStart ? c <= 0 : c < 0;
}
private boolean isBeforeEnd(Token token, boolean isStart) {
Token minToken = factory.minToken();
int c = end.equals(minToken) ? Integer.MAX_VALUE : end.compareTo(token);
return isStart ? c > 0 : c >= 0;
}I find it slightly easier to follow.
Contributor
Author
There was a problem hiding this comment.
if (token.equals(minToken)) {
return isStart
? start.equals(minToken)Not necessarily, for example this fails with the test "]2,1] contains the start of ]min,5]".
I need to merge this and merge to the downstream branches, so I'm going to proceed with the current version.
adutra
approved these changes
Feb 22, 2017
| return isWrappedAround() | ||
| ? isAfterStart || isBeforeEnd | ||
| : isAfterStart && isBeforeEnd; | ||
| } |
Contributor
There was a problem hiding this comment.
May I propose another way to do it:
@VisibleForTesting
boolean contains(Token token, boolean isStart) {
if (isEmpty()) {
return false;
}
if (isFull()) {
return true;
}
Token minToken = factory.minToken();
if (token.equals(minToken)) {
return isStart
? start.equals(minToken)
: end.equals(minToken);
}
return isWrappedAround()
? isAfterStart(token, isStart) || isBeforeEnd(token, isStart)
: isAfterStart(token, isStart) && isBeforeEnd(token, isStart);
}
private boolean isFull() {
Token minToken = factory.minToken();
return start.equals(minToken) && end.equals(minToken);
}
private boolean isAfterStart(Token token, boolean isStart) {
Token minToken = factory.minToken();
int c = start.equals(minToken) ? Integer.MIN_VALUE : start.compareTo(token);
return isStart ? c <= 0 : c < 0;
}
private boolean isBeforeEnd(Token token, boolean isStart) {
Token minToken = factory.minToken();
int c = end.equals(minToken) ? Integer.MAX_VALUE : end.compareTo(token);
return isStart ? c > 0 : c >= 0;
}I find it slightly easier to follow.
tolbertam
approved these changes
Feb 22, 2017
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Quick fix for a bug discovered by @adutra in #809.
Targeting to 3.0.x, we'll need to merge downstream if we include it in 3.2.0.