use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testNonZeroOffset.
public void testNonZeroOffset() {
String[] words = { "Hello", "World", "this", "is", "a", "test" };
char[] findme = "xthisy".toCharArray();
CharArraySet set = new CharArraySet(10, true);
set.addAll(Arrays.asList(words));
assertTrue(set.contains(findme, 1, 4));
assertTrue(set.contains(new String(findme, 1, 4)));
// test unmodifiable
set = CharArraySet.unmodifiableSet(set);
assertTrue(set.contains(findme, 1, 4));
assertTrue(set.contains(new String(findme, 1, 4)));
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testClear.
public void testClear() {
CharArraySet set = new CharArraySet(10, true);
set.addAll(Arrays.asList(TEST_STOP_WORDS));
assertEquals("Not all words added", TEST_STOP_WORDS.length, set.size());
set.clear();
assertEquals("not empty", 0, set.size());
for (int i = 0; i < TEST_STOP_WORDS.length; i++) assertFalse(set.contains(TEST_STOP_WORDS[i]));
set.addAll(Arrays.asList(TEST_STOP_WORDS));
assertEquals("Not all words added", TEST_STOP_WORDS.length, set.size());
for (int i = 0; i < TEST_STOP_WORDS.length; i++) assertTrue(set.contains(TEST_STOP_WORDS[i]));
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testUnmodifiableSet.
public void testUnmodifiableSet() {
CharArraySet set = new CharArraySet(10, true);
set.addAll(Arrays.asList(TEST_STOP_WORDS));
set.add(Integer.valueOf(1));
final int size = set.size();
set = CharArraySet.unmodifiableSet(set);
assertEquals("Set size changed due to unmodifiableSet call", size, set.size());
for (String stopword : TEST_STOP_WORDS) {
assertTrue(set.contains(stopword));
}
assertTrue(set.contains(Integer.valueOf(1)));
assertTrue(set.contains("1"));
assertTrue(set.contains(new char[] { '1' }));
expectThrows(NullPointerException.class, () -> {
CharArraySet.unmodifiableSet(null);
});
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testToString.
public void testToString() {
CharArraySet set = CharArraySet.copy(Collections.singleton("test"));
assertEquals("[test]", set.toString());
set.add("test2");
assertTrue(set.toString().contains(", "));
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testSingleHighSurrogate.
public void testSingleHighSurrogate() {
String missing = "Term %s is missing in the set";
String falsePos = "Term %s is in the set but shouldn't";
String[] upperArr = new String[] { "ABC�", "ABC�EfG", "�EfG", "�𐐜B" };
String[] lowerArr = new String[] { "abc�", "abc�efg", "�efg", "�𐑄b" };
CharArraySet set = new CharArraySet(Arrays.asList(TEST_STOP_WORDS), true);
for (String upper : upperArr) {
set.add(upper);
}
for (int i = 0; i < upperArr.length; i++) {
assertTrue(String.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
assertTrue(String.format(Locale.ROOT, missing, lowerArr[i]), set.contains(lowerArr[i]));
}
set = new CharArraySet(Arrays.asList(TEST_STOP_WORDS), false);
for (String upper : upperArr) {
set.add(upper);
}
for (int i = 0; i < upperArr.length; i++) {
assertTrue(String.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
assertFalse(String.format(Locale.ROOT, falsePos, upperArr[i]), set.contains(lowerArr[i]));
}
}
Aggregations