From 72654932f207c0ae2e1f63e8df04d393568dcde1 Mon Sep 17 00:00:00 2001 From: serso Date: Fri, 8 Jan 2016 16:35:27 +0100 Subject: [PATCH] Let's not allocate iterate but use good old for loop --- .../solovyev/android/calculator/math/MathType.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/math/MathType.java b/app/src/main/java/org/solovyev/android/calculator/math/MathType.java index 1b769211..6525e487 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/MathType.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/MathType.java @@ -280,7 +280,7 @@ public enum MathType { final StartsWithFinder startsWithFinder = new StartsWithFinder(text, i); for (MathType mathType : getMathTypesByPriority()) { - final String s = Collections.find(mathType.getTokens(), startsWithFinder); + final String s = find(mathType.getTokens(), startsWithFinder); if (s != null) { if (s.length() == 1) { if (hexMode || JsclMathEngine.getInstance().getNumeralBase() == NumeralBase.hex) { @@ -297,6 +297,17 @@ public enum MathType { return new Result(MathType.text, text.substring(i)); } + @Nullable + private static String find(@Nonnull List list, @Nonnull JPredicate predicate) { + for (int i = 0; i < list.size(); i++) { + final String token = list.get(i); + if(predicate.apply(token)) { + return token; + } + } + return null; + } + @Nonnull private static List getMathTypesByPriority() { if (mathTypesByPriority == null) {