From 2448f1b3871d9e82bf575f315b3e95caa131e702 Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 27 Jan 2016 17:33:01 +0100 Subject: [PATCH] Variables refactor --- .../android/calculator/AppComponent.java | 2 + .../calculator/BaseEntitiesRegistry.java | 43 ++++- .../CalculatorActivityLauncher.java | 6 +- .../calculator/CalculatorFragmentType.java | 4 +- .../android/calculator/CalculatorImpl.java | 4 +- .../solovyev/android/calculator/Engine.java | 28 ++-- .../android/calculator/FunctionsRegistry.java | 72 ++++---- .../android/calculator/VariablesRegistry.java | 95 ++++++++--- .../math/edit/VarEditDialogFragment.java | 8 +- .../calculator/math/edit/VarEditorSaver.java | 2 +- ...rsFragment.java => VariablesFragment.java} | 47 +++++- .../android/calculator/model/OldFunction.java | 155 +----------------- .../calculator/model/OldFunctions.java | 6 +- .../model/{Var.java => OldVar.java} | 28 ++-- .../android/calculator/model/OldVars.java | 64 ++++++++ .../android/calculator/model/Vars.java | 50 ------ .../calculator/variables/CppVariable.java | 15 ++ .../calculator/CalculatorTestUtils.java | 2 +- .../FromJsclSimplifyTextProcessorTest.java | 10 +- .../calculator/model/AndroidEngineTest.java | 2 +- .../calculator/model/EvaluateTest.java | 14 +- .../calculator/model/OldFunctionsTest.java | 40 +---- .../model/{VarTest.java => OldVarTest.java} | 10 +- 23 files changed, 324 insertions(+), 383 deletions(-) rename app/src/main/java/org/solovyev/android/calculator/math/edit/{VarsFragment.java => VariablesFragment.java} (86%) rename app/src/main/java/org/solovyev/android/calculator/model/{Var.java => OldVar.java} (92%) create mode 100644 app/src/main/java/org/solovyev/android/calculator/model/OldVars.java delete mode 100644 app/src/main/java/org/solovyev/android/calculator/model/Vars.java create mode 100644 app/src/main/java/org/solovyev/android/calculator/variables/CppVariable.java rename app/src/test/java/org/solovyev/android/calculator/model/{VarTest.java => OldVarTest.java} (88%) diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java index 8881d3c3..40b5caea 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -4,6 +4,7 @@ import org.solovyev.android.calculator.function.EditFunctionFragment; import org.solovyev.android.calculator.history.BaseHistoryFragment; import org.solovyev.android.calculator.history.EditHistoryFragment; import org.solovyev.android.calculator.math.edit.FunctionsFragment; +import org.solovyev.android.calculator.math.edit.VariablesFragment; import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; import javax.inject.Singleton; @@ -22,4 +23,5 @@ public interface AppComponent { void inject(EditFunctionFragment fragment); void inject(EditHistoryFragment fragment); void inject(FunctionsFragment fragment); + void inject(VariablesFragment fragment); } diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseEntitiesRegistry.java b/app/src/main/java/org/solovyev/android/calculator/BaseEntitiesRegistry.java index 12ead3dd..a55c4b38 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseEntitiesRegistry.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseEntitiesRegistry.java @@ -22,33 +22,48 @@ package org.solovyev.android.calculator; +import android.app.Application; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Resources; +import android.os.Handler; + +import com.squareup.otto.Bus; + import org.solovyev.android.Check; import org.solovyev.android.calculator.model.EntityDao; import org.solovyev.common.JBuilder; import org.solovyev.common.math.MathEntity; import org.solovyev.common.math.MathRegistry; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; + public abstract class BaseEntitiesRegistry implements EntitiesRegistry { - @Nonnull - private final MathRegistry mathRegistry; - - @Nonnull - private final String prefix; - @Nullable protected final EntityDao

entityDao; - @Nonnull protected final Object lock = this; + @Nonnull + private final MathRegistry mathRegistry; + @Nonnull + private final String prefix; + @Inject + Handler handler; + @Inject + SharedPreferences preferences; + @Inject + Application application; + @Inject + Bus bus; + @Inject + ErrorReporter errorReporter; // synchronized on lock private boolean initialized; @@ -192,6 +207,16 @@ public abstract class BaseEntitiesRegistry builder) { + try { + return add(builder); + } catch (Exception e) { + errorReporter.onException(e); + } + return null; + } + @Override public void remove(@Nonnull T var) { mathRegistry.remove(var); diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java index c7b165b3..5d03b056 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java @@ -43,7 +43,7 @@ import org.solovyev.android.calculator.math.edit.FunctionsActivity; import org.solovyev.android.calculator.math.edit.OperatorsActivity; import org.solovyev.android.calculator.math.edit.CalculatorVarsActivity; import org.solovyev.android.calculator.math.edit.VarEditDialogFragment; -import org.solovyev.android.calculator.math.edit.VarsFragment; +import org.solovyev.android.calculator.math.edit.VariablesFragment; import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.plot.CalculatorPlotActivity; import org.solovyev.android.calculator.plot.CalculatorPlotter; @@ -144,12 +144,12 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener if (viewState.valid) { final String varValue = viewState.text; if (!Strings.isEmpty(varValue)) { - if (VarsFragment.isValidValue(varValue)) { + if (VariablesFragment.isValidValue(varValue)) { if (context instanceof AppCompatActivity) { VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((AppCompatActivity) context).getSupportFragmentManager()); } else { final Intent intent = new Intent(context, CalculatorVarsActivity.class); - intent.putExtra(VarsFragment.CREATE_VAR_EXTRA_STRING, varValue); + intent.putExtra(VariablesFragment.CREATE_VAR_EXTRA_STRING, varValue); Activities.addIntentFlags(intent, false, context); context.startActivity(intent); } diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java index 248fd3be..18a6650c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java @@ -30,7 +30,7 @@ import org.solovyev.android.calculator.history.RecentHistoryFragment; import org.solovyev.android.calculator.history.SavedHistoryFragment; import org.solovyev.android.calculator.math.edit.FunctionsFragment; import org.solovyev.android.calculator.math.edit.OperatorsFragment; -import org.solovyev.android.calculator.math.edit.VarsFragment; +import org.solovyev.android.calculator.math.edit.VariablesFragment; import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment; import org.solovyev.android.calculator.plot.CalculatorPlotFragment; import org.solovyev.android.calculator.plot.CalculatorPlotFunctionSettingsActivity; @@ -52,7 +52,7 @@ public enum CalculatorFragmentType { //keyboard(CalculatorHistoryFragment.class, "history", R.layout.fragment_history, R.string.c_history), history(RecentHistoryFragment.class, R.layout.fragment_history, R.string.cpp_history_tab_recent), saved_history(SavedHistoryFragment.class, R.layout.fragment_history, R.string.cpp_history_tab_saved), - variables(VarsFragment.class, R.layout.vars_fragment, R.string.c_vars), + variables(VariablesFragment.class, R.layout.vars_fragment, R.string.c_vars), functions(FunctionsFragment.class, R.layout.fragment_entities, R.string.c_functions), operators(OperatorsFragment.class, R.layout.fragment_entities, R.string.c_operators), plotter(CalculatorPlotFragment.class, R.layout.cpp_plotter_fragment, R.string.c_graph), 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 33d61932..43c44611 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java @@ -35,7 +35,7 @@ import jscl.math.function.IConstant; import jscl.math.operator.Operator; import jscl.text.ParseInterruptedException; import org.solovyev.android.calculator.jscl.JsclOperation; -import org.solovyev.android.calculator.model.Var; +import org.solovyev.android.calculator.model.OldVar; import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.common.msg.ListMessageRegistry; import org.solovyev.common.msg.Message; @@ -475,7 +475,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { 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(); + final OldVar.Builder builder = ansVar != null ? new OldVar.Builder(ansVar) : new OldVar.Builder(); builder.setName(VariablesRegistry.ANS); builder.setValue(text); builder.setDescription(CalculatorMessages.getBundle().getString(CalculatorMessages.ans_description)); 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 e0e5d052..cb45e4a4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Engine.java +++ b/app/src/main/java/org/solovyev/android/calculator/Engine.java @@ -23,15 +23,10 @@ package org.solovyev.android.calculator; import android.content.SharedPreferences; + import com.squareup.otto.Bus; -import jscl.AngleUnit; -import jscl.JsclMathEngine; -import jscl.MathEngine; -import jscl.NumeralBase; -import jscl.math.operator.Operator; + import org.solovyev.android.Check; -import org.solovyev.android.calculator.model.EntityDao; -import org.solovyev.android.calculator.model.Vars; import org.solovyev.android.prefs.BooleanPreference; import org.solovyev.android.prefs.IntegerPreference; import org.solovyev.android.prefs.Preference; @@ -40,22 +35,26 @@ import org.solovyev.common.text.EnumMapper; import org.solovyev.common.text.NumberMapper; import org.solovyev.common.text.Strings; -import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Singleton; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.Executor; +import javax.annotation.Nonnull; +import javax.inject.Inject; +import javax.inject.Singleton; + +import jscl.AngleUnit; +import jscl.JsclMathEngine; +import jscl.MathEngine; +import jscl.NumeralBase; +import jscl.math.operator.Operator; + @Singleton public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener { @Nonnull private final MathEngine mathEngine; - @Nonnull - private final VariablesRegistry variablesRegistry; - @Nonnull private final EntitiesRegistry operatorsRegistry; @Nonnull @@ -68,6 +67,8 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene ErrorReporter errorReporter; @Inject FunctionsRegistry functionsRegistry; + @Inject + VariablesRegistry variablesRegistry; @Nonnull private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue(); @@ -86,7 +87,6 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene this.mathEngine.setRoundResult(true); this.mathEngine.setUseGroupingSeparator(true); - 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()); } diff --git a/app/src/main/java/org/solovyev/android/calculator/FunctionsRegistry.java b/app/src/main/java/org/solovyev/android/calculator/FunctionsRegistry.java index e01be6f8..379f346a 100644 --- a/app/src/main/java/org/solovyev/android/calculator/FunctionsRegistry.java +++ b/app/src/main/java/org/solovyev/android/calculator/FunctionsRegistry.java @@ -22,14 +22,8 @@ package org.solovyev.android.calculator; -import android.app.Application; -import android.content.SharedPreferences; -import android.os.Handler; import android.support.annotation.NonNull; -import com.squareup.otto.Bus; -import jscl.JsclMathEngine; -import jscl.math.function.CustomFunction; -import jscl.math.function.Function; + import org.json.JSONArray; import org.json.JSONException; import org.simpleframework.xml.Serializer; @@ -43,15 +37,25 @@ import org.solovyev.android.io.FileSaver; import org.solovyev.common.JBuilder; import org.solovyev.common.text.Strings; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executor; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.Executor; + +import jscl.JsclMathEngine; +import jscl.math.function.CustomFunction; +import jscl.math.function.Function; import static android.text.TextUtils.isEmpty; @@ -73,17 +77,7 @@ public class FunctionsRegistry extends BaseEntitiesRegistry builder) { - try { - // todo serso: currently JSCL might produce function's body which can't be loaded afterwards. F.e. f(x) = 3 * 6 - // might be simpliffied to f(x) = 18 × 10 ^ 0 and × is not supported by JSCL - return add(builder); - } catch (Exception e) { - errorReporter.onException(e); - } - return null; - } - @NonNull private List loadFunctions() { try { diff --git a/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java b/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java index 6a879979..68d9af9c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java +++ b/app/src/main/java/org/solovyev/android/calculator/VariablesRegistry.java @@ -22,23 +22,38 @@ package org.solovyev.android.calculator; -import org.solovyev.android.calculator.model.EntityDao; +import android.support.annotation.NonNull; + +import org.simpleframework.xml.Serializer; +import org.simpleframework.xml.core.Persister; +import org.solovyev.android.Check; +import org.solovyev.android.calculator.json.Json; import org.solovyev.android.calculator.model.MathEntityBuilder; -import org.solovyev.android.calculator.model.Var; -import org.solovyev.android.calculator.model.Vars; +import org.solovyev.android.calculator.model.OldFunctions; +import org.solovyev.android.calculator.model.OldVar; +import org.solovyev.android.calculator.model.OldVars; +import org.solovyev.android.calculator.variables.CppVariable; +import org.solovyev.android.io.FileSaver; import org.solovyev.common.JBuilder; import org.solovyev.common.math.MathEntity; -import org.solovyev.common.math.MathRegistry; +import java.io.File; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.inject.Inject; +import javax.inject.Singleton; +import jscl.JsclMathEngine; import jscl.math.function.IConstant; -public class VariablesRegistry extends BaseEntitiesRegistry { +import static android.text.TextUtils.isEmpty; + +@Singleton +public class VariablesRegistry extends BaseEntitiesRegistry { @Nonnull public static final String ANS = "ans"; @@ -54,9 +69,9 @@ public class VariablesRegistry extends BaseEntitiesRegistry { substitutes.put("NaN", "nan"); } - public VariablesRegistry(@Nonnull MathRegistry mathRegistry, - @Nonnull EntityDao entityDao) { - super(mathRegistry, "c_var_description_", entityDao); + @Inject + public VariablesRegistry(@Nonnull JsclMathEngine mathEngine) { + super(mathEngine.getConstantsRegistry(), "c_var_description_", null); } public static void saveVariable(@Nonnull EntitiesRegistry registry, @@ -82,41 +97,69 @@ public class VariablesRegistry extends BaseEntitiesRegistry { return substitutes; } - public synchronized void init() { - super.init(); + public void init() { + Check.isNotMainThread(); - tryToAddAuxVar("x"); - tryToAddAuxVar("y"); - tryToAddAuxVar("t"); - tryToAddAuxVar("j"); + try { + //migrateOldVariables(); + + addSafely("x"); + addSafely("y"); + addSafely("t"); + addSafely("j"); + } finally { + setInitialized(); + } } + private void migrateOldVariables() { + final String xml = preferences.getString(OldVars.PREFS_KEY, null); + if (isEmpty(xml)) { + return; + } + try { + final Serializer serializer = new Persister(); + final OldVars oldVariables = serializer.read(OldVars.class, xml); + if (oldVariables != null) { + List variables = OldVars.toCppVariables(oldVariables); + FileSaver.save(getVariablesFile(), Json.toJson(variables).toString()); + } + preferences.edit().remove(OldFunctions.PREFS_KEY).apply(); + } catch (Exception e) { + errorReporter.onException(e); + } + } - @Nonnull - @Override - protected JBuilder createBuilder(@Nonnull Var entity) { - return new Var.Builder(entity); + @NonNull + private File getVariablesFile() { + return new File(application.getFilesDir(), "variables.json"); } @Nonnull @Override - protected PersistedEntitiesContainer createPersistenceContainer() { - return new Vars(); + protected JBuilder createBuilder(@Nonnull OldVar entity) { + return new OldVar.Builder(entity); } - private void tryToAddAuxVar(@Nonnull String name) { + @Nonnull + @Override + protected PersistedEntitiesContainer createPersistenceContainer() { + return new OldVars(); + } + + private void addSafely(@Nonnull String name) { if (!contains(name)) { - add(new Var.Builder(name, (String) null)); + addSafely(new OldVar.Builder(name, (String) null)); } } @Nonnull @Override - protected Var transform(@Nonnull IConstant entity) { - if (entity instanceof Var) { - return (Var) entity; + protected OldVar transform(@Nonnull IConstant entity) { + if (entity instanceof OldVar) { + return (OldVar) entity; } else { - return new Var.Builder(entity).create(); + return new OldVar.Builder(entity).create(); } } 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 93323c73..a8b0036b 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 @@ -45,7 +45,7 @@ import org.solovyev.android.calculator.CalculatorEventListener; import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.model.Var; +import org.solovyev.android.calculator.model.OldVar; import org.solovyev.common.text.Strings; import java.util.Arrays; @@ -148,12 +148,12 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE final EditText editDescription = (EditText) root.findViewById(R.id.var_edit_description); editDescription.setText(input.getDescription()); - final Var.Builder varBuilder; + final OldVar.Builder varBuilder; final IConstant constant = input.getConstant(); if (constant != null) { - varBuilder = new Var.Builder(constant); + varBuilder = new OldVar.Builder(constant); } else { - varBuilder = new Var.Builder(); + varBuilder = new OldVar.Builder(); } root.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() { 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 b53855de..be260b5a 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 @@ -121,7 +121,7 @@ public class VarEditorSaver implements View.OnClickListene error = null; } else { // value is not empty => must be a number - boolean valid = VarsFragment.isValidValue(value); + boolean valid = VariablesFragment.isValidValue(value); if (valid) { varBuilder.setName(name); 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/VariablesFragment.java similarity index 86% rename from app/src/main/java/org/solovyev/android/calculator/math/edit/VarsFragment.java rename to app/src/main/java/org/solovyev/android/calculator/math/edit/VariablesFragment.java index 0a978a54..592bb9f4 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/VariablesFragment.java @@ -28,26 +28,51 @@ import android.support.v4.app.FragmentActivity; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; + import com.melnykov.fab.FloatingActionButton; -import jscl.math.function.IConstant; -import org.solovyev.android.calculator.*; +import com.squareup.otto.Bus; + +import org.solovyev.android.calculator.AppComponent; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.CalculatorEventData; +import org.solovyev.android.calculator.CalculatorEventListener; +import org.solovyev.android.calculator.CalculatorEventType; +import org.solovyev.android.calculator.CalculatorFragmentType; +import org.solovyev.android.calculator.Category; +import org.solovyev.android.calculator.Change; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.Locator; +import org.solovyev.android.calculator.PreparedExpression; +import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.ToJsclTextProcessor; +import org.solovyev.android.calculator.VariablesRegistry; import org.solovyev.android.calculator.math.MathType; import org.solovyev.common.JPredicate; import org.solovyev.common.collections.Collections; import org.solovyev.common.text.Strings; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -public class VarsFragment extends BaseEntitiesFragmentimplements CalculatorEventListener { +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; + +import jscl.math.function.IConstant; + +public class VariablesFragment extends BaseEntitiesFragment implements CalculatorEventListener { public static final String CREATE_VAR_EXTRA_STRING = "create_var"; - @NonNull - private final EntitiesRegistry registry = Locator.getInstance().getEngine().getVariablesRegistry(); + @Inject + VariablesRegistry registry; + @Inject + Calculator calculator; + @Inject + Keyboard keyboard; + @Inject + Bus bus; - public VarsFragment() { + public VariablesFragment() { super(CalculatorFragmentType.variables); } @@ -79,6 +104,12 @@ public class VarsFragment extends BaseEntitiesFragmentimplements Calc setHasOptionsMenu(true); } + @Override + protected void inject(@Nonnull AppComponent component) { + super.inject(component); + component.inject(this); + } + @Override public void onViewCreated(View root, Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); diff --git a/app/src/main/java/org/solovyev/android/calculator/model/OldFunction.java b/app/src/main/java/org/solovyev/android/calculator/model/OldFunction.java index 6a8e1376..64f62d13 100644 --- a/app/src/main/java/org/solovyev/android/calculator/model/OldFunction.java +++ b/app/src/main/java/org/solovyev/android/calculator/model/OldFunction.java @@ -22,26 +22,21 @@ package org.solovyev.android.calculator.model; -import jscl.math.function.IFunction; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; import org.simpleframework.xml.Transient; -import org.solovyev.android.calculator.ParseException; -import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.PersistedEntity; import org.solovyev.common.math.MathEntity; -import org.solovyev.common.msg.Message; -import org.solovyev.common.msg.MessageLevel; import org.solovyev.common.text.Strings; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Locale; + +import javax.annotation.Nonnull; + +import jscl.math.function.IFunction; @Root(name = "function") public class OldFunction implements IFunction, PersistedEntity, Serializable { @@ -50,11 +45,9 @@ public class OldFunction implements IFunction, PersistedEntity, Serializable { private Integer id; @Element - @Nonnull private String name; @Element(name = "body") - @Nonnull private String content; @ElementList(type = String.class) @@ -71,10 +64,6 @@ public class OldFunction implements IFunction, PersistedEntity, Serializable { public OldFunction() { } - public OldFunction(Integer id) { - this.id = id; - } - public static OldFunction fromIFunction(@Nonnull IFunction function) { final OldFunction result = new OldFunction(); @@ -167,140 +156,4 @@ public class OldFunction implements IFunction, PersistedEntity, Serializable { public List getParameterNames() { return parameterNames; } - - public void setParameterNames(@Nonnull List parameterNames) { - this.parameterNames = parameterNames; - } - - public static class Builder implements MathEntityBuilder { - - @Nonnull - private String name; - - @Nullable - private String value; - - private boolean system = false; - - @Nullable - private String description; - - @Nullable - private Integer id; - - @Nonnull - private List parameterNames = Collections.emptyList(); - - public Builder() { - } - - public Builder(@Nonnull IFunction function) { - this.name = function.getName(); - this.value = function.getContent(); - this.system = function.isSystem(); - this.description = function.getDescription(); - if (function.isIdDefined()) { - this.id = function.getId(); - } - this.parameterNames = new ArrayList(function.getParameterNames()); - } - - public Builder(@Nonnull String name, - @Nonnull String value, - @Nonnull List parameterNames) { - this.name = name; - this.value = value; - this.parameterNames = parameterNames; - } - - @Nonnull - public Builder setName(@Nonnull String name) { - this.name = name; - return this; - } - - @Nonnull - public Builder setValue(@Nullable String value) { - this.value = value; - return this; - } - - protected Builder setSystem(boolean system) { - this.system = system; - return this; - } - - public void setParameterNames(@Nonnull List parameterNames) { - this.parameterNames = parameterNames; - } - - @Nonnull - public Builder setDescription(@Nullable String description) { - this.description = description; - return this; - } - - @Nonnull - public OldFunction create() throws OldFunction.Builder.CreationException { - final OldFunction result; - if (id != null) { - result = new OldFunction(id); - } else { - result = new OldFunction(); - } - - result.name = name; - try { - result.content = Locator.getInstance().getCalculator().prepareExpression(value).toString(); - } catch (ParseException e) { - throw new CreationException(e); - } - result.system = system; - result.description = Strings.getNotEmpty(description, ""); - result.parameterNames = new ArrayList(parameterNames); - - return result; - } - - public static class CreationException extends RuntimeException implements Message { - - @Nonnull - private final ParseException message; - - public CreationException(@Nonnull ParseException cause) { - super(cause); - message = cause; - } - - @Nonnull - @Override - public String getMessageCode() { - return message.getMessageCode(); - } - - @Nonnull - @Override - public List getParameters() { - return message.getParameters(); - } - - @Nonnull - @Override - public MessageLevel getMessageLevel() { - return message.getMessageLevel(); - } - - @Override - @Nonnull - public String getLocalizedMessage() { - return message.getLocalizedMessage(); - } - - @Nonnull - @Override - public String getLocalizedMessage(@Nonnull Locale locale) { - return message.getLocalizedMessage(locale); - } - } - } } diff --git a/app/src/main/java/org/solovyev/android/calculator/model/OldFunctions.java b/app/src/main/java/org/solovyev/android/calculator/model/OldFunctions.java index b8eee7dd..3c255ab8 100644 --- a/app/src/main/java/org/solovyev/android/calculator/model/OldFunctions.java +++ b/app/src/main/java/org/solovyev/android/calculator/model/OldFunctions.java @@ -23,15 +23,17 @@ package org.solovyev.android.calculator.model; import android.text.TextUtils; + import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; import org.solovyev.android.calculator.PersistedEntitiesContainer; import org.solovyev.android.calculator.function.CppFunction; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +import javax.annotation.Nonnull; + @Root(name = "Functions") public class OldFunctions implements PersistedEntitiesContainer { @@ -46,7 +48,7 @@ public class OldFunctions implements PersistedEntitiesContainer { @Nonnull public static List toCppFunctions(@Nonnull OldFunctions oldFunctions) { final List functions = new ArrayList<>(); - for (OldFunction oldFunction : oldFunctions.getEntities()) { + for (OldFunction oldFunction : oldFunctions.functions) { final String name = oldFunction.getName(); final String body = oldFunction.getContent(); if (TextUtils.isEmpty(name) || TextUtils.isEmpty(body)) { diff --git a/app/src/main/java/org/solovyev/android/calculator/model/Var.java b/app/src/main/java/org/solovyev/android/calculator/model/OldVar.java similarity index 92% rename from app/src/main/java/org/solovyev/android/calculator/model/Var.java rename to app/src/main/java/org/solovyev/android/calculator/model/OldVar.java index 7dd201da..4e198b9b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/model/Var.java +++ b/app/src/main/java/org/solovyev/android/calculator/model/OldVar.java @@ -37,14 +37,8 @@ import jscl.math.function.Constant; import jscl.math.function.ExtendedConstant; import jscl.math.function.IConstant; -/** - * User: serso - * Date: 9/28/11 - * Time: 11:22 PM - */ - -@Root -public class Var implements IConstant, PersistedEntity { +@Root(name = "var") +public class OldVar implements IConstant, PersistedEntity { @Transient private Integer id; @@ -67,10 +61,10 @@ public class Var implements IConstant, PersistedEntity { @Transient private Constant constant; - private Var() { + private OldVar() { } - private Var(@Nonnull Integer id) { + private OldVar(@Nonnull Integer id) { this.id = id; } @@ -167,7 +161,7 @@ public class Var implements IConstant, PersistedEntity { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Var var = (Var) o; + OldVar var = (OldVar) o; if (!name.equals(var.name)) return false; @@ -179,7 +173,7 @@ public class Var implements IConstant, PersistedEntity { return name.hashCode(); } - public static class Builder implements JBuilder, MathEntityBuilder { + public static class Builder implements JBuilder, MathEntityBuilder { @Nonnull private String name; @@ -198,7 +192,7 @@ public class Var implements IConstant, PersistedEntity { public Builder() { } - public Builder(@Nonnull Var var) { + public Builder(@Nonnull OldVar var) { this.name = var.name; this.value = var.value; this.system = var.system; @@ -252,12 +246,12 @@ public class Var implements IConstant, PersistedEntity { } @Nonnull - public Var create() { - final Var result; + public OldVar create() { + final OldVar result; if (id != null) { - result = new Var(id); + result = new OldVar(id); } else { - result = new Var(); + result = new OldVar(); } result.name = name; diff --git a/app/src/main/java/org/solovyev/android/calculator/model/OldVars.java b/app/src/main/java/org/solovyev/android/calculator/model/OldVars.java new file mode 100644 index 00000000..33454ab6 --- /dev/null +++ b/app/src/main/java/org/solovyev/android/calculator/model/OldVars.java @@ -0,0 +1,64 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.calculator.model; + +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; +import org.solovyev.android.calculator.PersistedEntitiesContainer; +import org.solovyev.android.calculator.variables.CppVariable; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nonnull; + +@Root(name = "vars") +public class OldVars implements PersistedEntitiesContainer { + + public static final String PREFS_KEY = "org.solovyev.android.calculator.CalculatorModel_vars"; + @ElementList(type = OldVar.class) + private List vars = new ArrayList(); + + public OldVars() { + } + + public List getEntities() { + return vars; + } + + @Nonnull + public static List toCppVariables(@Nonnull OldVars oldVariables) { + final List variables = new ArrayList<>(); + /*for (OldVar oldVar : oldVariables.vars) { + final String name = oldVar.getName(); + final String body = oldVar.getContent(); + if (TextUtils.isEmpty(name) || TextUtils.isEmpty(body)) { + continue; + } + variables.add(CppFunction.builder(name, body) + .withParameters(oldVar.getParameterNames()) + .withDescription(oldVar.getDescription()).build()); + }*/ + return variables; + } +} diff --git a/app/src/main/java/org/solovyev/android/calculator/model/Vars.java b/app/src/main/java/org/solovyev/android/calculator/model/Vars.java deleted file mode 100644 index 79967bd7..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/model/Vars.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013 serso aka se.solovyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Contact details - * - * Email: se.solovyev@gmail.com - * Site: http://se.solovyev.org - */ - -package org.solovyev.android.calculator.model; - -import org.simpleframework.xml.ElementList; -import org.simpleframework.xml.Root; -import org.solovyev.android.calculator.PersistedEntitiesContainer; - -import java.util.ArrayList; -import java.util.List; - -/** - * User: serso - * Date: 9/29/11 - * Time: 5:19 PM - */ - -@Root -public class Vars implements PersistedEntitiesContainer { - - @ElementList(type = Var.class) - private List vars = new ArrayList(); - - public Vars() { - } - - public List getEntities() { - return vars; - } -} diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/CppVariable.java b/app/src/main/java/org/solovyev/android/calculator/variables/CppVariable.java new file mode 100644 index 00000000..a13c5800 --- /dev/null +++ b/app/src/main/java/org/solovyev/android/calculator/variables/CppVariable.java @@ -0,0 +1,15 @@ +package org.solovyev.android.calculator.variables; + +import org.json.JSONException; +import org.json.JSONObject; +import org.solovyev.android.calculator.json.Jsonable; + +import javax.annotation.Nonnull; + +public class CppVariable implements Jsonable { + @Nonnull + @Override + public JSONObject toJson() throws JSONException { + return null; + } +} 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 45742eca..80983e75 100644 --- a/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -103,7 +103,7 @@ public class CalculatorTestUtils { final JsclMathEngine jsclEngine = JsclMathEngine.getInstance(); - final VariablesRegistry variablesRegistry = new VariablesRegistry(jsclEngine.getConstantsRegistry(), entityDao); + final VariablesRegistry variablesRegistry = new VariablesRegistry(jsclEngine); final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine); final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry()); final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry()); 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 1f042286..3ac2de5e 100644 --- a/app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java @@ -25,7 +25,7 @@ package org.solovyev.android.calculator; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.solovyev.android.calculator.model.Var; +import org.solovyev.android.calculator.model.OldVar; import org.solovyev.android.calculator.text.FromJsclSimplifyTextProcessor; import java.text.DecimalFormatSymbols; @@ -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().getVariablesRegistry().add(new Var.Builder("t2.718281828459045", "2")); - Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("t2.718281828459045", "2")); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.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().getVariablesRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.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().getVariablesRegistry().add(new Var.Builder("k", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.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 eb35a264..2206882e 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().getVariablesRegistry().add(new Var.Builder("si", 5d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.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 36271e5e..15ad5cab 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().getVariablesRegistry().add(new Var.Builder("si", 5d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("si", 5d)); try { cm.setAngleUnits(AngleUnit.rad); @@ -130,14 +130,14 @@ public class EvaluateTest extends AbstractCalculatorTest { cm.setAngleUnits(defaultAngleUnit); } - Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("s", 1d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("s", 1d)); CalculatorTestUtils.assertEval("5", cm.evaluate("si")); - Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k", 3.5d)); - Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k1", 4d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("k", 3.5d)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("k1", 4d)); CalculatorTestUtils.assertEval("4", "k11"); - Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.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().getVariablesRegistry().add(new Var.Builder("t", (String) null)); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("t", (String) null)); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)"); - Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", "2")); + Locator.getInstance().getEngine().getVariablesRegistry().add(new OldVar.Builder("t", "2")); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify); CalculatorTestUtils.assertEval("4", "∂(t^2,t)"); diff --git a/app/src/test/java/org/solovyev/android/calculator/model/OldFunctionsTest.java b/app/src/test/java/org/solovyev/android/calculator/model/OldFunctionsTest.java index ddcf5793..987360ed 100644 --- a/app/src/test/java/org/solovyev/android/calculator/model/OldFunctionsTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/model/OldFunctionsTest.java @@ -22,7 +22,6 @@ package org.solovyev.android.calculator.model; -import jscl.util.ExpressionGenerator; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Assert; @@ -33,12 +32,16 @@ import org.simpleframework.xml.core.Persister; import org.solovyev.android.calculator.CalculatorTestUtils; import org.solovyev.common.Objects; import org.solovyev.common.equals.CollectionEqualizer; -import org.solovyev.common.text.Strings; + +import java.io.StringWriter; +import java.util.Date; +import java.util.List; +import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.io.StringWriter; -import java.util.*; + +import jscl.util.ExpressionGenerator; /** * User: serso @@ -87,31 +90,6 @@ public class OldFunctionsTest { CalculatorTestUtils.staticSetUp(); } - @Test - public void testXml() throws Exception { - final OldFunctions in = new OldFunctions(); - - OldFunction first = new OldFunction.Builder("test", "x+y", Arrays.asList("x", "y")).setDescription("description").setSystem(false).create(); - in.getEntities().add(first); - - OldFunction second = new OldFunction.Builder("z_2", "e^(z_1^2+z_2^2)", Arrays.asList("z_1", "z_2")).setSystem(true).create(); - in.getEntities().add(second); - - OldFunction third = new OldFunction.Builder("z_2", "e^(z_1^2+z_2^2)", Arrays.asList("z_1", "z_2")).setSystem(true).setDescription("").create(); - in.getEntities().add(third); - - final OldFunctions out = testXml(in, xml); - - Assert.assertTrue(!out.getEntities().isEmpty()); - - final OldFunction firstOut = out.getEntities().get(0); - final OldFunction secondOut = out.getEntities().get(1); - - assertEquals(first, firstOut); - assertEquals(second, secondOut); - - } - @Nonnull private OldFunctions testXml(@Nonnull OldFunctions in, @Nullable String expectedXml) throws Exception { final String actualXml = toXml(in); @@ -142,7 +120,7 @@ public class OldFunctionsTest { ExpressionGenerator generator = new ExpressionGenerator(10); for (int i = 0; i < 1000; i++) { - final String content = generator.generate(); +/* final String content = generator.generate(); final String paramsString = Strings.generateRandomString(random.nextInt(10)); final List parameterNames = new ArrayList(); @@ -158,7 +136,7 @@ public class OldFunctionsTest { builder.setSystem(random.nextBoolean()); - in.getEntities().add(builder.create()); + in.getEntities().add(builder.create());*/ } testXml(in, null); diff --git a/app/src/test/java/org/solovyev/android/calculator/model/VarTest.java b/app/src/test/java/org/solovyev/android/calculator/model/OldVarTest.java similarity index 88% rename from app/src/test/java/org/solovyev/android/calculator/model/VarTest.java rename to app/src/test/java/org/solovyev/android/calculator/model/OldVarTest.java index 94b985e4..86ddc77d 100644 --- a/app/src/test/java/org/solovyev/android/calculator/model/VarTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/model/OldVarTest.java @@ -37,7 +37,7 @@ import static org.junit.Assert.assertEquals; * Date: 11/7/11 * Time: 7:52 PM */ -public class VarTest { +public class OldVarTest { private static final String xml = "\n" + " \n" + @@ -57,10 +57,10 @@ public class VarTest { @Test public void testXml() throws Exception { - final Vars vars = new Vars(); - Var first = new Var.Builder("e", Math.E).setDescription("description").setSystem(true).create(); + final OldVars vars = new OldVars(); + OldVar first = new OldVar.Builder("e", Math.E).setDescription("description").setSystem(true).create(); vars.getEntities().add(first); - Var second = new Var.Builder(";", 3d).setSystem(true).create(); + OldVar second = new OldVar.Builder(";", 3d).setSystem(true).create(); vars.getEntities().add(second); final StringWriter sw = new StringWriter(); @@ -69,7 +69,7 @@ public class VarTest { assertEquals(xml, sw.toString()); - final Vars result = serializer.read(Vars.class, xml); + final OldVars result = serializer.read(OldVars.class, xml); final IConstant actualFirst = result.getEntities().get(0); final IConstant actualSecond = result.getEntities().get(1);