Code reformat

This commit is contained in:
serso 2016-03-04 22:33:10 +01:00
parent 99633e0cae
commit 8d4a16efe6
2 changed files with 23 additions and 24 deletions

View File

@ -107,7 +107,7 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
startsWithFinder.setI(i); startsWithFinder.setOffset(i);
int offset = 0; int offset = 0;
String functionName = Iterables.find(MathType.function.getTokens(engine), startsWithFinder, null); String functionName = Iterables.find(MathType.function.getTokens(engine), startsWithFinder, null);

View File

@ -29,32 +29,31 @@ import javax.annotation.Nullable;
public class StartsWithFinder implements Predicate<String> { public class StartsWithFinder implements Predicate<String> {
private int i; @Nonnull
private final String string;
private int offset;
@Nonnull private StartsWithFinder(@Nonnull String string, int offset) {
private final String targetString; this.string = string;
this.offset = offset;
}
private StartsWithFinder(@Nonnull String targetString, int i) { @Nonnull
this.targetString = targetString; public static StartsWithFinder newFrom(@Nonnull String targetString, int i) {
this.i = i; return new StartsWithFinder(targetString, i);
} }
@Nonnull @Nonnull
public static StartsWithFinder newFrom(@Nonnull String targetString, int i) { public static StartsWithFinder newInstance(@Nonnull String targetString) {
return new StartsWithFinder(targetString, i); return newFrom(targetString, 0);
} }
@Nonnull @Override
public static StartsWithFinder newInstance(@Nonnull String targetString) { public boolean apply(@Nullable String prefix) {
return newFrom(targetString, 0); return prefix != null && string.startsWith(prefix, offset);
} }
@Override public void setOffset(int offset) {
public boolean apply(@Nullable String s) { this.offset = offset;
return s != null && targetString.startsWith(s, i); }
}
public void setI(int i) {
this.i = i;
}
} }