Skip to content

switch from ICU ObjectMatcher to Java Predicate #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2022
Merged
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
22 changes: 10 additions & 12 deletions UnicodeJsps/src/main/java/org/unicode/jsp/UnicodeProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import org.unicode.cldr.util.props.UnicodeLabel;

import com.ibm.icu.dev.util.CollectionUtilities;
import com.ibm.icu.dev.util.CollectionUtilities.InverseMatcher;
import com.ibm.icu.dev.util.CollectionUtilities.ObjectMatcher;
import com.ibm.icu.dev.util.UnicodeMap;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.text.SymbolTable;
Expand Down Expand Up @@ -307,7 +306,7 @@ public UnicodeSet getSet(PatternMatcher matcher, UnicodeSet result) {
for (UnicodeSetIterator usi = getStuffToTest(uniformUnassigned); usi.next();) { // int i = 0; i <= 0x10FFFF; ++i
int i = usi.codepoint;
String value = getValue(i);
if (value != null && matcher.matches(value)) {
if (value != null && matcher.test(value)) {
result.add(i);
}
}
Expand All @@ -323,8 +322,8 @@ public UnicodeSet getSet(PatternMatcher matcher, UnicodeSet result) {
while (it2.hasNext()) {
String value2 = (String) it2.next();
// System.out.println("Values:" + value2);
if (matcher.matches(value2)
|| matcher.matches(toSkeleton(value2))) {
if (matcher.test(value2)
|| matcher.test(toSkeleton(value2))) {
um.keySet(value, result);
continue main;
}
Expand Down Expand Up @@ -1087,21 +1086,20 @@ public Map getMap() {
}
}

public interface PatternMatcher extends ObjectMatcher {
public interface PatternMatcher extends Predicate<String> {
public PatternMatcher set(String pattern);
}

public static class InversePatternMatcher extends InverseMatcher implements
PatternMatcher {
public static class InversePatternMatcher implements PatternMatcher {
PatternMatcher other;

public PatternMatcher set(PatternMatcher toInverse) {
other = toInverse;
return this;
}

public boolean matches(Object value) {
return !other.matches(value);
public boolean test(String value) {
return !other.test(value);
}

public PatternMatcher set(String pattern) {
Expand All @@ -1120,7 +1118,7 @@ public SimpleMatcher(String pattern, Comparator comparator) {
this.pattern = pattern;
}

public boolean matches(Object value) {
public boolean test(String value) {
if (comparator == null)
return pattern.equals(value);
return comparator.compare(pattern, value) == 0;
Expand All @@ -1140,7 +1138,7 @@ public UnicodeProperty.PatternMatcher set(String pattern) {
return this;
}
UFormat foo;
public boolean matches(Object value) {
public boolean test(String value) {
matcher.reset(value.toString());
return matcher.find();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public boolean applyPropertyAlias(String propertyName,
if (propertyValue.length() != 0) {
if (prop == null) {
propertyValue = propertyValue.trim();
} else if (prop.isTrimable()) {
} else if (prop.isTrimmable()) {
propertyValue = propertyValue.trim();
} else {
int debug = 0;
Expand Down Expand Up @@ -237,7 +237,7 @@ private boolean applyPropertyAlias0(UnicodeProperty prop,
set = new UnicodeSet();
List<String> values = prop.getAvailableValues();
for (String value : values) {
if (patternMatcher.matches(value)) {
if (patternMatcher.test(value)) {
for (String other : values) {
if (other.compareTo(value) <= 0) {
set.addAll(prop.getSet(other));
Expand Down Expand Up @@ -284,7 +284,7 @@ public ComparisonMatcher(String pattern, Relation comparator) {
this.pattern = pattern;
}

public boolean matches(Object value) {
public boolean test(String value) {
int comp = comparator.compare(pattern, value.toString());
switch (relation) {
case less: return comp < 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public UnicodeSet getSet(PatternMatcher matcher, UnicodeSet result) {
if (propEnum == UProperty.GENERAL_CATEGORY) {
for (String multiprop : SPECIAL_GC.keySet()) {
R2<String, UnicodeSet> value = SPECIAL_GC.get(multiprop);
if (matcher.matches(multiprop) || matcher.matches(value.get0())) {
if (matcher.test(multiprop) || matcher.test(value.get0())) {
result.addAll(value.get1());
}
}
Expand Down
4 changes: 2 additions & 2 deletions unicodetools/src/main/java/org/unicode/jsp/MySymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public boolean applyPropertyAlias0(String propertyName,
set = new UnicodeSet();
List<String> values = prop.getAvailableValues();
for (String value : values) {
if (patternMatcher.matches(value)) {
if (patternMatcher.test(value)) {
for (String other : values) {
if (other.compareTo(value) <= 0) {
set.addAll(prop.getSet(other));
Expand Down Expand Up @@ -171,7 +171,7 @@ public ComparisonMatcher(String pattern, Relation comparator) {
}

@Override
public boolean matches(Object value) {
public boolean test(String value) {
int comp = comparator.compare(pattern, value.toString());
switch (relation) {
case less: return comp < 0;
Expand Down
Loading