Skip to content

Commit

Permalink
Remove usage of java assert.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstyura committed Sep 12, 2024
1 parent 81d7e02 commit ad6ba40
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,25 @@ public final class Tags implements Iterable<Tag> {
* @param length the number of valid tags in the {@code sortedSet}
*/
private Tags(Tag[] sortedSet, int length) {
assert isSortedSet(sortedSet, length) : "bug on caller side: construction invariant violated";
this.sortedSet = sortedSet;
this.length = length;
}

private static boolean isSortedSet(Tag[] sortedSet, int length) {
if (length > sortedSet.length) {
/**
* Checks if the first {@code length} elements of the {@code tags} array
* form an ordered set of tags.
*
* @param tags an array of tags.
* @param length the number of items to check.
* @return {@code true} if the first {@code length} items of {@code tags}
* form an ordered set; otherwise {@code false}.
*/
private static boolean isSortedSet(Tag[] tags, int length) {
if (length > tags.length) {
return false;
}
for (int i = 0; i < length - 1; i++) {
int cmp = sortedSet[i].compareTo(sortedSet[i + 1]);
int cmp = tags[i].compareTo(tags[i + 1]);
if (cmp >= 0) {
return false;
}
Expand Down

0 comments on commit ad6ba40

Please sign in to comment.