From f767f10795ead29923ddafb6e4ca1f40a83415e1 Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 27 Jan 2016 17:09:33 +0100 Subject: [PATCH] VarsRegistry->VariablesRegistry --- .../android/calculator/CalculatorImpl.java | 10 ++++----- .../android/calculator/CalculatorUtils.java | 2 +- .../solovyev/android/calculator/Engine.java | 14 ++++++------- .../calculator/ToJsclTextProcessor.java | 4 ++-- ...rsRegistry.java => VariablesRegistry.java} | 14 +++++++------ .../function/EditFunctionFragment.java | 4 ++-- .../android/calculator/math/MathType.java | 2 +- .../math/edit/MathEntityRemover.java | 2 +- .../math/edit/VarEditDialogFragment.java | 2 +- .../calculator/math/edit/VarEditorSaver.java | 4 ++-- .../calculator/math/edit/VarsFragment.java | 2 +- .../calculator/CalculatorTestUtils.java | 21 +++++++++++++------ .../FromJsclSimplifyTextProcessorTest.java | 8 +++---- .../calculator/model/AndroidEngineTest.java | 2 +- .../calculator/model/EvaluateTest.java | 14 ++++++------- 15 files changed, 58 insertions(+), 47 deletions(-) rename app/src/main/java/org/solovyev/android/calculator/{VarsRegistry.java => VariablesRegistry.java} (94%) diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java index da4a6273..33d61932 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java @@ -472,15 +472,15 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { if (TextUtils.isEmpty(text)) { return; } - final EntitiesRegistry varsRegistry = Locator.getInstance().getEngine().getVarsRegistry(); - final IConstant ansVar = varsRegistry.get(VarsRegistry.ANS); + final EntitiesRegistry varsRegistry = Locator.getInstance().getEngine().getVariablesRegistry(); + final IConstant ansVar = varsRegistry.get(VariablesRegistry.ANS); final Var.Builder builder = ansVar != null ? new Var.Builder(ansVar) : new Var.Builder(); - builder.setName(VarsRegistry.ANS); + builder.setName(VariablesRegistry.ANS); builder.setValue(text); builder.setDescription(CalculatorMessages.getBundle().getString(CalculatorMessages.ans_description)); - VarsRegistry.saveVariable(varsRegistry, builder, ansVar, this, false); + VariablesRegistry.saveVariable(varsRegistry, builder, ansVar, this, false); } @Subscribe @@ -498,7 +498,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { switch (calculatorEventType) { case constant_changed: final IConstant newConstant = ((Change) data).getNewValue(); - if (!newConstant.getName().equals(VarsRegistry.ANS)) { + if (!newConstant.getName().equals(VariablesRegistry.ANS)) { evaluate(); } break; diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java index 26e6c6a5..e3f05498 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java @@ -54,7 +54,7 @@ public final class CalculatorUtils { final Set notSystemConstants = new HashSet(); for (Constant constant : expression.getConstants()) { - IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(constant.getName()); + IConstant var = Locator.getInstance().getEngine().getVariablesRegistry().get(constant.getName()); if (var != null && !var.isSystem() && !var.isDefined()) { notSystemConstants.add(constant); } diff --git a/app/src/main/java/org/solovyev/android/calculator/Engine.java b/app/src/main/java/org/solovyev/android/calculator/Engine.java index 34fede7c..e0e5d052 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Engine.java +++ b/app/src/main/java/org/solovyev/android/calculator/Engine.java @@ -54,7 +54,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene @Nonnull private final MathEngine mathEngine; @Nonnull - private final VarsRegistry varsRegistry; + private final VariablesRegistry variablesRegistry; @Nonnull private final EntitiesRegistry operatorsRegistry; @@ -71,9 +71,9 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene @Nonnull private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue(); - public Engine(@Nonnull MathEngine mathEngine, @Nonnull VarsRegistry varsRegistry, @Nonnull FunctionsRegistry functionsRegistry, @Nonnull EntitiesRegistry operatorsRegistry, @Nonnull EntitiesRegistry postfixFunctionsRegistry) { + public Engine(@Nonnull MathEngine mathEngine, @Nonnull VariablesRegistry variablesRegistry, @Nonnull FunctionsRegistry functionsRegistry, @Nonnull EntitiesRegistry operatorsRegistry, @Nonnull EntitiesRegistry postfixFunctionsRegistry) { this.mathEngine = mathEngine; - this.varsRegistry = varsRegistry; + this.variablesRegistry = variablesRegistry; this.functionsRegistry = functionsRegistry; this.operatorsRegistry = operatorsRegistry; this.postfixFunctionsRegistry = postfixFunctionsRegistry; @@ -86,7 +86,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene this.mathEngine.setRoundResult(true); this.mathEngine.setUseGroupingSeparator(true); - this.varsRegistry = new VarsRegistry(mathEngine.getConstantsRegistry(), new EntityDao<>("org.solovyev.android.calculator.CalculatorModel_vars", Vars.class, preferences)); + this.variablesRegistry = new VariablesRegistry(mathEngine.getConstantsRegistry(), new EntityDao<>("org.solovyev.android.calculator.CalculatorModel_vars", Vars.class, preferences)); this.operatorsRegistry = new OperatorsRegistry(mathEngine.getOperatorsRegistry()); this.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine.getPostfixFunctionsRegistry()); } @@ -106,8 +106,8 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene } @Nonnull - public VarsRegistry getVarsRegistry() { - return varsRegistry; + public VariablesRegistry getVariablesRegistry() { + return variablesRegistry; } @Nonnull @@ -169,7 +169,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene } private void initAsync() { - init(varsRegistry); + init(variablesRegistry); init(functionsRegistry); init(operatorsRegistry); init(postfixFunctionsRegistry); diff --git a/app/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java b/app/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java index efd2b277..bd1a2551 100644 --- a/app/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java +++ b/app/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java @@ -114,9 +114,9 @@ public class ToJsclTextProcessor implements TextProcessor { +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import jscl.math.function.IConstant; + +public class VariablesRegistry extends BaseEntitiesRegistry { @Nonnull public static final String ANS = "ans"; @@ -52,8 +54,8 @@ public class VarsRegistry extends BaseEntitiesRegistry { substitutes.put("NaN", "nan"); } - public VarsRegistry(@Nonnull MathRegistry mathRegistry, - @Nonnull EntityDao entityDao) { + public VariablesRegistry(@Nonnull MathRegistry mathRegistry, + @Nonnull EntityDao entityDao) { super(mathRegistry, "c_var_description_", entityDao); } diff --git a/app/src/main/java/org/solovyev/android/calculator/function/EditFunctionFragment.java b/app/src/main/java/org/solovyev/android/calculator/function/EditFunctionFragment.java index 72e0a189..97f75de3 100644 --- a/app/src/main/java/org/solovyev/android/calculator/function/EditFunctionFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/function/EditFunctionFragment.java @@ -60,7 +60,7 @@ import org.solovyev.android.calculator.KeyboardWindow; import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.ParseException; import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.VarsRegistry; +import org.solovyev.android.calculator.VariablesRegistry; import org.solovyev.android.calculator.math.edit.FunctionsActivity; import org.solovyev.android.calculator.math.edit.VarEditorSaver; import org.solovyev.android.calculator.view.EditTextCompat; @@ -91,7 +91,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC private static final int MENU_CATEGORY = Menu.FIRST + 2; @NonNull - private final VarsRegistry constantsRegistry = Locator.getInstance().getEngine().getVarsRegistry(); + private final VariablesRegistry constantsRegistry = Locator.getInstance().getEngine().getVariablesRegistry(); @NonNull private final KeyboardWindow keyboardWindow = new KeyboardWindow(); @NonNull 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 d54dd243..d756d7e6 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 @@ -170,7 +170,7 @@ public enum MathType { @Nonnull @Override public List getTokens() { - return Locator.getInstance().getEngine().getVarsRegistry().getNames(); + return Locator.getInstance().getEngine().getVariablesRegistry().getNames(); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/MathEntityRemover.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/MathEntityRemover.java index 3872e0ea..cd18e3d6 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/MathEntityRemover.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/MathEntityRemover.java @@ -91,7 +91,7 @@ public class MathEntityRemover implements View.OnClickList @Nullable DialogInterface.OnClickListener callbackOnCancel, @Nonnull Context context, @Nonnull Object source) { - return new MathEntityRemover(constant, callbackOnCancel, false, Locator.getInstance().getEngine().getVarsRegistry(), context, source, Params.newConstantInstance()); + return new MathEntityRemover(constant, callbackOnCancel, false, Locator.getInstance().getEngine().getVariablesRegistry(), context, source, Params.newConstantInstance()); } /* diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditDialogFragment.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditDialogFragment.java index 6d15f61e..93323c73 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditDialogFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditDialogFragment.java @@ -163,7 +163,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE } }); - root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver(varBuilder, constant, root, Locator.getInstance().getEngine().getVarsRegistry(), this)); + root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver(varBuilder, constant, root, Locator.getInstance().getEngine().getVariablesRegistry(), this)); if (constant == null) { // CREATE MODE diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditorSaver.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditorSaver.java index b0c5935a..b53855de 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditorSaver.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/VarEditorSaver.java @@ -28,7 +28,7 @@ import android.widget.EditText; import org.solovyev.android.calculator.EntitiesRegistry; import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.VarsRegistry; +import org.solovyev.android.calculator.VariablesRegistry; import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.model.MathEntityBuilder; import org.solovyev.common.math.MathEntity; @@ -145,7 +145,7 @@ public class VarEditorSaver implements View.OnClickListene if (error != null) { Locator.getInstance().getNotifier().showMessage(error, MessageType.error); } else { - VarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true); + VariablesRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true); } } } diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/VarsFragment.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/VarsFragment.java index eefad260..0a978a54 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/VarsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/VarsFragment.java @@ -45,7 +45,7 @@ public class VarsFragment extends BaseEntitiesFragmentimplements Calc public static final String CREATE_VAR_EXTRA_STRING = "create_var"; @NonNull - private final EntitiesRegistry registry = Locator.getInstance().getEngine().getVarsRegistry(); + private final EntitiesRegistry registry = Locator.getInstance().getEngine().getVariablesRegistry(); public VarsFragment() { super(CalculatorFragmentType.variables); diff --git a/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index 4f54dd70..45742eca 100644 --- a/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -23,8 +23,9 @@ package org.solovyev.android.calculator; import android.content.Context; + import com.squareup.otto.Bus; -import jscl.JsclMathEngine; + import org.junit.Assert; import org.mockito.Mockito; import org.robolectric.fakes.RoboSharedPreferences; @@ -33,9 +34,12 @@ import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.model.EntityDao; import org.solovyev.android.calculator.plot.CalculatorPlotter; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.text.DecimalFormatSymbols; import java.util.HashMap; import java.util.Map; @@ -43,6 +47,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import jscl.JsclMathEngine; + /** * User: serso * Date: 10/7/12 @@ -94,12 +103,12 @@ public class CalculatorTestUtils { final JsclMathEngine jsclEngine = JsclMathEngine.getInstance(); - final VarsRegistry varsRegistry = new VarsRegistry(jsclEngine.getConstantsRegistry(), entityDao); + final VariablesRegistry variablesRegistry = new VariablesRegistry(jsclEngine.getConstantsRegistry(), entityDao); final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine); final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry()); final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry()); - return new Engine(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry); + return new Engine(jsclEngine, variablesRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry); } public static void assertEval(@Nonnull String expected, @Nonnull String expression) { diff --git a/app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java b/app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java index 3406dcfc..1f042286 100644 --- a/app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java @@ -57,15 +57,15 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest { //Assert.assertEquals("e", tp.process("2.718281828459045")); //Assert.assertEquals("tee", tp.process("t2.718281828459045*2.718281828459045")); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t2.718281828459045", "2")); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t2.718281828459045", "2")); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null)); //Assert.assertEquals("t2.718281828459045e", tp.process("t2.718281828459045*2.718281828459045")); //Assert.assertEquals("ee", tp.process("2.718281828459045*2.718281828459045")); Assert.assertEquals("t×", tp.process("t*")); Assert.assertEquals("×t", tp.process("*t")); Assert.assertEquals("t2", tp.process("t*2")); Assert.assertEquals("2t", tp.process("2*t")); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null)); Assert.assertEquals("t×", tp.process("t*")); Assert.assertEquals("×t", tp.process("*t")); @@ -78,7 +78,7 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest { Assert.assertEquals("t^[2×2t]", tp.process("t^[2*2*t]")); Assert.assertEquals("2t^2[2t]", tp.process("2*t^2[2*t]")); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k", (String) null)); Assert.assertEquals("(t+2k)[k+2t]", tp.process("(t+2*k)*[k+2*t]")); Assert.assertEquals("(te+2k)e[k+2te]", tp.process("(t*e+2*k)*e*[k+2*t*e]")); diff --git a/app/src/test/java/org/solovyev/android/calculator/model/AndroidEngineTest.java b/app/src/test/java/org/solovyev/android/calculator/model/AndroidEngineTest.java index f08fb6f8..eb35a264 100644 --- a/app/src/test/java/org/solovyev/android/calculator/model/AndroidEngineTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/model/AndroidEngineTest.java @@ -139,7 +139,7 @@ public class AndroidEngineTest extends AbstractCalculatorTest { cm.setAngleUnits(defaultAngleUnit); } - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("si", 5d)); CalculatorTestUtils.assertEval("5", cm.evaluate("si")); CalculatorTestUtils.assertError("sin"); diff --git a/app/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java b/app/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java index bdc550d0..36271e5e 100644 --- a/app/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java @@ -116,7 +116,7 @@ public class EvaluateTest extends AbstractCalculatorTest { CalculatorTestUtils.assertError("(-1)i!"); CalculatorTestUtils.assertEval("24i", "4!i"); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("si", 5d)); try { cm.setAngleUnits(AngleUnit.rad); @@ -130,14 +130,14 @@ public class EvaluateTest extends AbstractCalculatorTest { cm.setAngleUnits(defaultAngleUnit); } - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("s", 1d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("s", 1d)); CalculatorTestUtils.assertEval("5", cm.evaluate("si")); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", 3.5d)); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k1", 4d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k", 3.5d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k1", 4d)); CalculatorTestUtils.assertEval("4", "k11"); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null)); CalculatorTestUtils.assertEval("11t", "t11"); CalculatorTestUtils.assertEval("11et", "t11e"); CalculatorTestUtils.assertEval("∞", "∞"); @@ -183,10 +183,10 @@ public class EvaluateTest extends AbstractCalculatorTest { cm.setTimeout(3000); }*/ - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null)); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)"); - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", "2")); + Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", "2")); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify); CalculatorTestUtils.assertEval("4", "∂(t^2,t)");