android-calculatorpp-71 Plot problem
This commit is contained in:
parent
39de2cbf8f
commit
3f2cf60d6f
@ -101,7 +101,7 @@ public enum CalculatorEngine {
|
||||
private MathEngine engine = JsclMathEngine.instance;
|
||||
|
||||
@NotNull
|
||||
public final TextProcessor<PreparedExpression, String> preprocessor = new ToJsclTextProcessor();
|
||||
public final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
|
||||
|
||||
@NotNull
|
||||
private final AndroidMathRegistry<IConstant> varsRegistry = new AndroidVarsRegistryImpl(engine.getConstantsRegistry());
|
||||
|
@ -15,12 +15,24 @@ import org.solovyev.common.utils.CollectionsUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class ToJsclTextProcessor implements TextProcessor<PreparedExpression, String> {
|
||||
public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, String> {
|
||||
|
||||
@NotNull
|
||||
private static final Integer MAX_DEPTH = 20;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
private static final TextProcessor<PreparedExpression, String> instance = new ToJsclTextProcessor();
|
||||
|
||||
private ToJsclTextProcessor() {
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static TextProcessor<PreparedExpression, String> getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PreparedExpression process(@NotNull String s) throws CalculatorParseException {
|
||||
return processWithDepth(s, 0, new ArrayList<IConstant>());
|
||||
|
@ -35,6 +35,9 @@ import org.achartengine.tools.ZoomListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.model.CalculatorParseException;
|
||||
import org.solovyev.android.calculator.model.PreparedExpression;
|
||||
import org.solovyev.android.calculator.model.ToJsclTextProcessor;
|
||||
import org.solovyev.common.utils.MutableObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -79,7 +82,8 @@ public class CalculatorPlotActivity extends Activity {
|
||||
final Input input = (Input) extras.getSerializable(INPUT);
|
||||
|
||||
try {
|
||||
this.expression = Expression.valueOf(input.getExpression());
|
||||
final PreparedExpression preparedExpression = ToJsclTextProcessor.getInstance().process(input.getExpression());
|
||||
this.expression = Expression.valueOf(preparedExpression.getExpression());
|
||||
this.variable = new Constant(input.getVariableName());
|
||||
|
||||
String title = extras.getString(ChartFactory.TITLE);
|
||||
@ -100,8 +104,11 @@ public class CalculatorPlotActivity extends Activity {
|
||||
} catch (ArithmeticException e) {
|
||||
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
} catch (CalculatorParseException e) {
|
||||
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void setGraphicalView(@Nullable PlotBoundaries plotBoundaries) {
|
||||
double minValue = plotBoundaries == null ? DEFAULT_MIN_NUMBER : plotBoundaries.xMin;
|
||||
|
@ -26,13 +26,13 @@ public class ToJsclTextProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testSpecialCases() throws CalculatorParseException {
|
||||
final ToJsclTextProcessor preprocessor = new ToJsclTextProcessor();
|
||||
final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
|
||||
Assert.assertEquals( "3^E10", preprocessor.process("3^E10").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
final ToJsclTextProcessor preprocessor = new ToJsclTextProcessor();
|
||||
final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
|
||||
|
||||
Assert.assertEquals( "", preprocessor.process("").toString());
|
||||
Assert.assertEquals( "()", preprocessor.process("[]").toString());
|
||||
@ -113,7 +113,7 @@ public class ToJsclTextProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testDegrees() throws Exception {
|
||||
final ToJsclTextProcessor preprocessor = new ToJsclTextProcessor();
|
||||
final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
|
||||
|
||||
Assert.assertEquals( "", preprocessor.process("").toString());
|
||||
/* try {
|
||||
@ -145,7 +145,7 @@ public class ToJsclTextProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testNumeralBases() throws Exception {
|
||||
final ToJsclTextProcessor processor = new ToJsclTextProcessor();
|
||||
final TextProcessor<PreparedExpression, String> processor = ToJsclTextProcessor.getInstance();
|
||||
|
||||
final NumeralBase defaultNumeralBase = JsclMathEngine.instance.getNumeralBase();
|
||||
try{
|
||||
|
Loading…
Reference in New Issue
Block a user