From 6a0b667c32fef128db20b3e5b4d96d233bcce13b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 24 Sep 2017 12:58:33 -0700 Subject: [PATCH] Replace some recent android API features with backwards compatible ones. --- core/src/main/java/org/nwapw/abacus/lexing/Lexer.java | 9 ++++++--- .../nwapw/abacus/parsing/standard/LexerTokenizer.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java b/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java index 292c1b9..0a7fea0 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java @@ -79,10 +79,10 @@ public class Lexer { index++; } - matches.sort((a, b) -> compare.compare(a.getType(), b.getType())); if (compare != null) { - matches.sort(Comparator.comparingInt(a -> a.getContent().length())); + Collections.sort(matches, (a, b) -> compare.compare(a.getType(), b.getType())); } + Collections.sort(matches, (o1, o2) -> o1.getContent().length() - o2.getContent().length()); return matches.isEmpty() ? null : matches.get(matches.size() - 1); } @@ -136,7 +136,10 @@ public class Lexer { @Override public int hashCode() { - return Objects.hash(name, id); + return Arrays.hashCode(new Object[] { + this.name, + this.id + }); } @Override diff --git a/core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java b/core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java index 028089a..4291cd0 100644 --- a/core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java +++ b/core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java @@ -20,7 +20,7 @@ public class LexerTokenizer implements Tokenizer>, PluginListen /** * Comparator used to sort the tokens produced by the lexer. */ - protected static final Comparator TOKEN_SORTER = Comparator.comparingInt(e -> e.priority); + protected static final Comparator TOKEN_SORTER = (o1, o2) -> o1.priority - o2.priority; /** * The lexer instance used to turn strings into matches.