1212import java .util .Comparator ;
1313import java .util .HashMap ;
1414import java .util .List ;
15+ import java .util .function .Function ;
1516import org .unicode .props .UnicodeProperty .PatternMatcher ;
1617
1718/**
@@ -201,10 +202,14 @@ public boolean applyPropertyAlias0(
201202 if (isAge ) {
202203 set =
203204 prop .getSet (
204- new ComparisonMatcher (
205- propertyValue ,
205+ new ComparisonMatcher <VersionInfo >(
206+ UnicodePropertySymbolTable .parseVersionInfoOrMax (
207+ propertyValue ),
206208 Relation .geq ,
207- VERSION_STRING_COMPARATOR ));
209+ Comparator .nullsFirst (Comparator .naturalOrder ()),
210+ (s ) ->
211+ UnicodePropertySymbolTable
212+ .parseVersionInfoOrMax (s )));
208213 } else {
209214 set = prop .getSet (propertyValue );
210215 }
@@ -244,20 +249,26 @@ public enum Relation {
244249 greater
245250 }
246251
247- public static class ComparisonMatcher implements PatternMatcher {
252+ public static class ComparisonMatcher < T > implements PatternMatcher {
248253 final Relation relation ;
249- final Comparator <String > comparator ;
250- String pattern ;
254+ final Comparator <T > comparator ;
255+ final Function <String , T > parser ;
256+ T expected ;
251257
252- public ComparisonMatcher (String pattern , Relation relation , Comparator <String > comparator ) {
258+ public ComparisonMatcher (
259+ T expected ,
260+ Relation relation ,
261+ Comparator <T > comparator ,
262+ Function <String , T > parser ) {
253263 this .relation = relation ;
254- this .pattern = pattern ;
264+ this .expected = expected ;
255265 this .comparator = comparator ;
266+ this .parser = parser ;
256267 }
257268
258269 @ Override
259270 public boolean test (String value ) {
260- int comp = comparator .compare (pattern , value );
271+ int comp = comparator .compare (expected , parser . apply ( value ) );
261272 switch (relation ) {
262273 case less :
263274 return comp < 0 ;
@@ -274,47 +285,19 @@ public boolean test(String value) {
274285
275286 @ Override
276287 public PatternMatcher set (String pattern ) {
277- this .pattern = pattern ;
288+ this .expected = parser . apply ( pattern ) ;
278289 return this ;
279290 }
280291 }
281292
282- /**
283- * Special parser for version strings. Anything not parsable is higher than everything
284- * parseable.
285- */
286- public static final Comparator <String > VERSION_STRING_COMPARATOR =
287- new Comparator <String >() {
288-
289- @ Override
290- public int compare (String o1 , String o2 ) {
291- if (o1 == o2 ) {
292- return 0 ;
293- } else if (o1 == null ) {
294- return -1 ;
295- } else if (o2 == null ) {
296- return 1 ;
297- } else {
298- boolean o1Valid = true ;
299- boolean o2Valid = true ;
300- VersionInfo v1 = null ;
301- VersionInfo v2 = null ;
302- try {
303- v1 = VersionInfo .getInstance (o1 );
304- } catch (IllegalArgumentException e ) {
305- o1Valid = false ;
306- }
307- try {
308- v2 = VersionInfo .getInstance (o2 );
309- } catch (IllegalArgumentException e ) {
310- o2Valid = false ;
311- }
312- if (o1Valid && o2Valid ) {
313- return v1 .compareTo (v2 );
314- } else {
315- return o2Valid ? 1 : o1Valid ? -1 : o1 .compareTo (o2 );
316- }
317- }
318- }
319- };
293+ public static VersionInfo parseVersionInfoOrMax (String s ) {
294+ if (s == null ) {
295+ return null ;
296+ }
297+ try {
298+ return VersionInfo .getInstance (s );
299+ } catch (IllegalArgumentException e ) {
300+ return VersionInfo .getInstance (255 , 255 , 255 , 255 );
301+ }
302+ }
320303}
0 commit comments