From f75bab4a012e665b1c224502d00a9b2a7b2be523 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Mon, 14 May 2012 14:43:25 +0400 Subject: [PATCH] Fix for I calculations --- calculatorpp/AndroidManifest.xml | 4 ++-- calculatorpp/pom.xml | 8 +++++++- .../android/calculator/CalculatorMenu.java | 4 ++-- .../android/calculator/model/CalculatorEngine.java | 11 ++++++----- .../jscl/FromJsclNumericTextProcessorTest.java | 14 +++++++++++++- pom.xml | 7 ++++++- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/calculatorpp/AndroidManifest.xml b/calculatorpp/AndroidManifest.xml index fc616771..1628f7dc 100644 --- a/calculatorpp/AndroidManifest.xml +++ b/calculatorpp/AndroidManifest.xml @@ -1,5 +1,5 @@ - + @@ -8,7 +8,7 @@ - + diff --git a/calculatorpp/pom.xml b/calculatorpp/pom.xml index ae0718d5..475c1954 100644 --- a/calculatorpp/pom.xml +++ b/calculatorpp/pom.xml @@ -64,7 +64,7 @@ org.solovyev jscl - 0.0.1 + 0.0.2 xercesImpl @@ -121,6 +121,12 @@ + + com.google.guava + guava + 11.0.2 + + com.intellij annotations diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java index c79df031..d4f2b32e 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java @@ -6,14 +6,14 @@ import android.util.Log; import android.view.MenuItem; import org.jetbrains.annotations.NotNull; import org.solovyev.android.calculator.view.NumeralBaseConverterDialog; -import org.solovyev.android.menu.ActivityMenuItem; +import org.solovyev.android.menu.IdentifiableMenuItem; /** * User: serso * Date: 4/23/12 * Time: 2:25 PM */ -enum CalculatorMenu implements ActivityMenuItem { +enum CalculatorMenu implements IdentifiableMenuItem { settings(R.id.main_menu_item_settings){ @Override diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java index 7f3af56b..b2302d1b 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java @@ -114,7 +114,7 @@ public enum CalculatorEngine { private final AndroidMathRegistry postfixFunctionsRegistry = new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry()); - @NotNull + @Nullable private ThreadKiller threadKiller = new AndroidThreadKiller(); // calculation thread timeout in seconds, after timeout thread would be interrupted @@ -256,9 +256,10 @@ public enum CalculatorEngine { final Thread calculationThreadLocal = calculationThread.getObject(); if (calculationThreadLocal != null) { - // todo serso: interrupt doesn't stop the thread but it MUST be killed - threadKiller.killThread(calculationThreadLocal); - //calculationThreadLocal.stop(); + if (threadKiller != null) { + threadKiller.killThread(calculationThreadLocal); + } + //calculationThreadLocal.stop(); } if (parseExceptionObject != null || evalExceptionObject != null) { @@ -396,7 +397,7 @@ public enum CalculatorEngine { } // for tests only - void setThreadKiller(@NotNull ThreadKiller threadKiller) { + void setThreadKiller(@Nullable ThreadKiller threadKiller) { this.threadKiller = threadKiller; } diff --git a/calculatorpp/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java b/calculatorpp/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java index c3c1d9e0..c0483701 100644 --- a/calculatorpp/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java +++ b/calculatorpp/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java @@ -6,6 +6,8 @@ package org.solovyev.android.calculator.jscl; +import jscl.AngleUnit; +import jscl.JsclMathEngine; import jscl.math.Expression; import jscl.math.Generic; import org.junit.Assert; @@ -29,9 +31,19 @@ public class FromJsclNumericTextProcessorTest { public void testCreateResultForComplexNumber() throws Exception { final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor(); + final JsclMathEngine me = JsclMathEngine.instance; + final AngleUnit defaultAngleUnits = me.getAngleUnits(); + Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric())); Assert.assertEquals("1.22133+1.2i", cm.process(Expression.valueOf("1.22133232+1.2*i").numeric())); - Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric())); + Assert.assertEquals("1.22133+0i", cm.process(Expression.valueOf("1.22133232+0.000000001*i").numeric())); + try { + me.setAngleUnits(AngleUnit.rad); + Assert.assertEquals("1-0i", cm.process(Expression.valueOf("-(e^(i*π))").numeric())); + } finally { + me.setAngleUnits(defaultAngleUnits); + } + Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric())); Assert.assertEquals("i", cm.process(Expression.valueOf("i").numeric())); Generic numeric = Expression.valueOf("e^(Π*i)+1").numeric(); junit.framework.Assert.assertEquals("0i", cm.process(numeric)); diff --git a/pom.xml b/pom.xml index 6318b869..a98cad66 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,6 @@ UTF-8 - /home/ssolovyev/projects/org.solovyev/misc/lib/android-sdk-linux_x86 @@ -56,6 +55,12 @@ 2.3.1 + + com.google.guava + guava + 11.0.2 + +