You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2016/02/29 09:54:33 UTC
lucene-solr git commit: LUCENE-7053: Move comparator to better place
in code; generalize to use CharSequence instead of String
Repository: lucene-solr
Updated Branches:
refs/heads/master f48d23cd1 -> 8ffa436f0
LUCENE-7053: Move comparator to better place in code; generalize to use CharSequence instead of String
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8ffa436f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8ffa436f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8ffa436f
Branch: refs/heads/master
Commit: 8ffa436f00d24cb45af49160739f71b3654349ce
Parents: f48d23c
Author: Uwe Schindler <us...@apache.org>
Authored: Mon Feb 29 09:54:22 2016 +0100
Committer: Uwe Schindler <us...@apache.org>
Committed: Mon Feb 29 09:54:22 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/lucene/util/TestUtil.java | 40 ++++++++++----------
1 file changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8ffa436f/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
index 15580d8..e969b4c 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
@@ -117,6 +117,26 @@ public final class TestUtil {
}
/**
+ * A comparator that compares UTF-16 strings / char sequences according to Unicode
+ * code point order. This can be used to verify {@link BytesRef} order.
+ * <p>
+ * <b>Warning:</b> This comparator is rather inefficient, because
+ * it converts the strings to a {@code int[]} array on each invocation.
+ * */
+ public static final Comparator<CharSequence> STRING_CODEPOINT_COMPARATOR = (a, b) -> {
+ final int[] aCodePoints = a.codePoints().toArray();
+ final int[] bCodePoints = b.codePoints().toArray();
+ for(int i = 0, c = Math.min(aCodePoints.length, bCodePoints.length); i < c; i++) {
+ if (aCodePoints[i] < bCodePoints[i]) {
+ return -1;
+ } else if (aCodePoints[i] > bCodePoints[i]) {
+ return 1;
+ }
+ }
+ return aCodePoints.length - bCodePoints.length;
+ };
+
+ /**
* Convenience method unzipping zipName into destDir. You must pass it a clean destDir.
*
* Closes the given InputStream after extracting!
@@ -771,26 +791,6 @@ public final class TestUtil {
0x2A6DF, 0x2B73F, 0x2FA1F, 0xE007F, 0xE01EF, 0xFFFFF, 0x10FFFF
};
- /**
- * A comparator that compares strings according to Unicode code point order.
- * This can be used to verify {@link BytesRef} order.
- * <p>
- * <b>Warning:</b> This comparator is rather inefficient, because
- * it converts the strings to a {@code int[]} array on each invocation.
- * */
- public static final Comparator<String> STRING_CODEPOINT_COMPARATOR = (a, b) -> {
- final int[] aCodePoints = a.codePoints().toArray();
- final int[] bCodePoints = b.codePoints().toArray();
- for(int i = 0, c = Math.min(aCodePoints.length, bCodePoints.length); i < c; i++) {
- if (aCodePoints[i] < bCodePoints[i]) {
- return -1;
- } else if (aCodePoints[i] > bCodePoints[i]) {
- return 1;
- }
- }
- return aCodePoints.length - bCodePoints.length;
- };
-
/** Returns random string of length between 0-20 codepoints, all codepoints within the same unicode block. */
public static String randomRealisticUnicodeString(Random r) {
return randomRealisticUnicodeString(r, 20);