Changes
This commit is contained in:
parent
64f5f0c44a
commit
9f30f3e5c0
@ -43,14 +43,14 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
|
||||
|
||||
for (CalculatorEvent e : calculatorEvents) {
|
||||
for (CalculatorEventListener listener : listeners) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
/*long startTime = System.currentTimeMillis();*/
|
||||
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());
|
||||
long endTime = System.currentTimeMillis();
|
||||
/* long endTime = System.currentTimeMillis();
|
||||
long totalTime = (endTime - startTime);
|
||||
if ( totalTime > 300 ) {
|
||||
logger.debug(TAG + "_" + e.getCalculatorEventData().getEventId(), "Started event: " + e.getCalculatorEventType() + " with data: " + e.getData() + " for: " + listener.getClass().getSimpleName());
|
||||
logger.debug(TAG + "_" + e.getCalculatorEventData().getEventId(), "Total time, ms: " + totalTime);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
public class AbstractCalculatorTest {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger());
|
||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class CalculatorTestUtils {
|
||||
public static final int TIMEOUT = 1;
|
||||
|
||||
public static void staticSetUp() throws Exception {
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger());
|
||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,9 @@ import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||
import org.solovyev.android.view.AutoResizeTextView;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/17/11
|
||||
@ -53,6 +56,9 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
||||
@NotNull
|
||||
private final Handler uiHandler = new Handler();
|
||||
|
||||
@NotNull
|
||||
private final ExecutorService bgExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
/*
|
||||
@ -96,12 +102,7 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
||||
try {
|
||||
viewStateChange = true;
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
final CharSequence text = prepareText(state.getStringResult(), state.isValid());
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = (endTime - startTime);
|
||||
CalculatorLocatorImpl.getInstance().getLogger().debug("CalculatorDisplayView", "Total time, ms: " + totalTime);
|
||||
|
||||
|
||||
AndroidCalculatorDisplayView.this.state = state;
|
||||
if (state.isValid()) {
|
||||
|
@ -32,35 +32,46 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
|
||||
public static class Result implements CharSequence {
|
||||
|
||||
@NotNull
|
||||
private final String string;
|
||||
private final CharSequence charSequence;
|
||||
|
||||
@Nullable
|
||||
private String string;
|
||||
|
||||
private final int offset;
|
||||
|
||||
public Result(@NotNull String string, int offset) {
|
||||
this.string = string;
|
||||
public Result(@NotNull CharSequence charSequence, int offset) {
|
||||
this.charSequence = charSequence;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return string.length();
|
||||
return charSequence.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char charAt(int i) {
|
||||
return string.charAt(i);
|
||||
return charSequence.charAt(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence subSequence(int i, int i1) {
|
||||
return string.subSequence(i, i1);
|
||||
return charSequence.subSequence(i, i1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (string == null) {
|
||||
string = charSequence.toString();
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CharSequence getCharSequence() {
|
||||
return charSequence;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
@ -86,7 +97,7 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
|
||||
@NotNull
|
||||
@Override
|
||||
public Result process(@NotNull String text) throws CalculatorParseException {
|
||||
final String result;
|
||||
final CharSequence result;
|
||||
|
||||
int maxNumberOfOpenGroupSymbols = 0;
|
||||
int numberOfOpenGroupSymbols = 0;
|
||||
@ -158,7 +169,7 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
|
||||
|
||||
final StringBuilder text2 = new StringBuilder(text1.length());
|
||||
|
||||
String s = text1.toString();
|
||||
final CharSequence s = text1;
|
||||
int i = processBracketGroup(text2, s, 0, 0, maxNumberOfOpenGroupSymbols);
|
||||
for (; i < s.length(); i++) {
|
||||
text2.append(s.charAt(i));
|
||||
@ -177,7 +188,7 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
|
||||
private int processHighlightedText(@NotNull StringBuilder result, int i, @NotNull String match, @NotNull String tag, @Nullable Map<String, String> tagAttributes) {
|
||||
result.append("<").append(tag);
|
||||
|
||||
if (tagAttributes != null) {
|
||||
if (tagAttributes != null && !tagAttributes.entrySet().isEmpty()) {
|
||||
for (Map.Entry<String, String> entry : tagAttributes.entrySet()) {
|
||||
// attr1="attr1_value" attr2="attr2_value"
|
||||
result.append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
|
||||
@ -192,14 +203,15 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
|
||||
}
|
||||
}
|
||||
|
||||
private int processBracketGroup(@NotNull StringBuilder result, @NotNull String s, int i, int numberOfOpenings, int maxNumberOfGroups) {
|
||||
private int processBracketGroup(@NotNull StringBuilder result, @NotNull CharSequence s, int i, int numberOfOpenings, int maxNumberOfGroups) {
|
||||
|
||||
result.append("<font color=\"").append(getColor(maxNumberOfGroups, numberOfOpenings)).append("\">");
|
||||
|
||||
for (; i < s.length(); i++) {
|
||||
char ch = s.charAt(i);
|
||||
String strCh = String.valueOf(ch);
|
||||
|
||||
if (MathType.open_group_symbol.getTokens().contains(String.valueOf(ch))) {
|
||||
if (MathType.open_group_symbol.getTokens().contains(strCh)) {
|
||||
result.append(ch);
|
||||
result.append("</font>");
|
||||
i = processBracketGroup(result, s, i + 1, numberOfOpenings + 1, maxNumberOfGroups);
|
||||
@ -207,7 +219,7 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
|
||||
if (i < s.length() && MathType.close_group_symbol.getTokens().contains(String.valueOf(s.charAt(i)))) {
|
||||
result.append(s.charAt(i));
|
||||
}
|
||||
} else if (MathType.close_group_symbol.getTokens().contains(String.valueOf(ch))) {
|
||||
} else if (MathType.close_group_symbol.getTokens().contains(strCh)) {
|
||||
break;
|
||||
} else {
|
||||
result.append(ch);
|
||||
|
@ -13,7 +13,7 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
public class CalculatorTestUtils {
|
||||
|
||||
public static void staticSetUp() throws Exception {
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger());
|
||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.graphics.Color;
|
||||
import jscl.MathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import junit.framework.Assert;
|
||||
@ -138,4 +139,23 @@ public class TextHighlighterTest {
|
||||
me.setNumeralBase(NumeralBase.dec);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTime() throws Exception {
|
||||
final TextProcessor<?, String> textHighlighter = new TextHighlighter(Color.WHITE, false);
|
||||
|
||||
final int count = 1000;
|
||||
final String subExpression = "cos(acos(t8ln(t5t85tln(8ln(5t55tln(5))))))+tln(88cos(tln(t)))+t√(ln(t))";
|
||||
final StringBuilder expression = new StringBuilder(subExpression.length() * count);
|
||||
for ( int i = 0; i < count; i++ ){
|
||||
expression.append(subExpression);
|
||||
expression.append("+");
|
||||
}
|
||||
expression.append(subExpression);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
textHighlighter.process(expression.toString());
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("Total time, ms: " + (endTime - startTime));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user