Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,6 @@ private KeyValues(KeyValue[] sortedSet, int length) {
this.length = length;
}

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

/**
* Constructs a {@code KeyValues} collection from the provided array of key-values.
* @param keyValues an array of {@code KeyValue} objects, possibly unordered and/or
Expand All @@ -92,11 +71,8 @@ private static boolean isSortedSet(KeyValue[] keyValues, int length) {
* key-values.
*/
private static KeyValues toKeyValues(KeyValue[] keyValues) {
int len = keyValues.length;
if (!isSortedSet(keyValues, len)) {
Arrays.sort(keyValues);
len = dedup(keyValues);
}
Arrays.sort(keyValues);
int len = dedup(keyValues);
return new KeyValues(keyValues, len);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,15 @@ private Tags(Tag[] sortedSet, int length) {
this.length = 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 elements to check.
* @return {@code true} if the first {@code length} elements 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 = tags[i].compareTo(tags[i + 1]);
if (cmp >= 0) {
return false;
}
}
return true;
}

/**
* Constructs a {@code Tags} collection from the provided array of tags.
* @param tags an array of {@code Tag} objects, possibly unordered and/or containing
* duplicates.
* @return a {@code Tags} instance with a deduplicated and ordered set of tags.
*/
private static Tags toTags(Tag[] tags) {
int len = tags.length;
if (!isSortedSet(tags, len)) {
Arrays.sort(tags);
len = dedup(tags);
}
Arrays.sort(tags);
int len = dedup(tags);
return new Tags(tags, len);
}

Expand Down