From d834ccc30564293ce56aa03728f121dbab5c1f47 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 5 Jan 2016 09:42:17 +0100 Subject: [PATCH] core moved to android-app --- android-app/build.gradle | 17 +- .../AbstractCalculatorMathRegistry.java | 0 .../calculator/AbstractFixableError.java | 88 +-- .../calculator/AbstractNumberBuilder.java | 0 .../android/calculator/Calculator.java | 0 .../calculator/CalculatorClipboard.java | 0 .../CalculatorConversionEventData.java | 98 +-- .../CalculatorConversionEventDataImpl.java | 0 .../android/calculator/CalculatorDisplay.java | 0 .../CalculatorDisplayChangeEventData.java | 0 .../CalculatorDisplayChangeEventDataImpl.java | 0 .../calculator/CalculatorDisplayImpl.java | 0 .../calculator/CalculatorDisplayView.java | 0 .../CalculatorDisplayViewState.java | 0 .../CalculatorDisplayViewStateImpl.java | 0 .../android/calculator/CalculatorEditor.java | 0 .../CalculatorEditorChangeEventData.java | 0 .../calculator/CalculatorEditorImpl.java | 0 .../calculator/CalculatorEditorView.java | 70 +-- .../calculator/CalculatorEditorViewState.java | 0 .../CalculatorEditorViewStateImpl.java | 170 ++--- .../android/calculator/CalculatorEngine.java | 0 .../calculator/CalculatorEngineControl.java | 70 +-- .../calculator/CalculatorEngineImpl.java | 0 .../calculator/CalculatorEvalException.java | 176 +++--- .../CalculatorEvaluationEventData.java | 82 +-- .../CalculatorEvaluationEventDataImpl.java | 0 .../calculator/CalculatorEventContainer.java | 158 ++--- .../calculator/CalculatorEventData.java | 0 .../calculator/CalculatorEventDataImpl.java | 0 .../calculator/CalculatorEventHolder.java | 200 +++--- .../calculator/CalculatorEventListener.java | 78 +-- .../calculator/CalculatorEventType.java | 0 .../android/calculator/CalculatorFailure.java | 0 .../calculator/CalculatorFailureImpl.java | 0 .../calculator/CalculatorFixableError.java | 0 .../CalculatorFunctionsMathRegistry.java | 0 .../android/calculator/CalculatorImpl.java | 0 .../android/calculator/CalculatorInput.java | 0 .../calculator/CalculatorInputImpl.java | 0 .../calculator/CalculatorKeyboard.java | 94 +-- .../calculator/CalculatorKeyboardImpl.java | 0 .../android/calculator/CalculatorLocator.java | 0 .../android/calculator/CalculatorLogger.java | 0 .../calculator/CalculatorMathEngine.java | 0 .../calculator/CalculatorMathRegistry.java | 0 .../android/calculator/CalculatorMessage.java | 0 .../calculator/CalculatorMessages.java | 0 .../calculator/CalculatorNotifier.java | 0 .../CalculatorOperatorsMathRegistry.java | 0 .../android/calculator/CalculatorOutput.java | 0 .../calculator/CalculatorOutputImpl.java | 0 .../calculator/CalculatorParseException.java | 216 +++---- .../CalculatorPostfixFunctionsRegistry.java | 0 .../CalculatorPreferenceService.java | 0 .../calculator/CalculatorSpecialButton.java | 0 .../android/calculator/CalculatorUtils.java | 0 .../calculator/CalculatorVarsRegistry.java | 306 ++++----- .../solovyev/android/calculator/Change.java | 0 .../android/calculator/ChangeImpl.java | 0 .../android/calculator/ConversionFailure.java | 72 +-- .../calculator/ConversionFailureImpl.java | 92 +-- .../android/calculator/DialogData.java | 0 .../calculator/DummyCalculatorClipboard.java | 0 .../calculator/DummyCalculatorNotifier.java | 0 .../solovyev/android/calculator/Editor.java | 86 +-- .../android/calculator/FixableError.java | 0 .../android/calculator/FunctionCategory.java | 0 .../ListCalculatorEventContainer.java | 0 .../android/calculator/LiteNumberBuilder.java | 0 .../solovyev/android/calculator/Locator.java | 0 .../android/calculator/MathEntityDao.java | 0 .../MathEntityPersistenceContainer.java | 0 .../calculator/MathPersistenceEntity.java | 0 .../android/calculator/MessageDialogData.java | 0 .../android/calculator/NumberBuilder.java | 0 .../android/calculator/OperatorCategory.java | 0 .../calculator/PreparedExpression.java | 164 ++--- .../android/calculator/StringDialogData.java | 0 .../calculator/SystemOutCalculatorLogger.java | 0 .../calculator/ToJsclTextProcessor.java | 0 .../android/calculator/VarCategory.java | 0 .../function/FunctionBuilderAdapter.java | 0 .../history/AbstractHistoryState.java | 194 +++--- .../CalculatorDisplayHistoryState.java | 322 +++++----- .../calculator/history/CalculatorHistory.java | 126 ++-- .../history/CalculatorHistoryImpl.java | 584 +++++++++--------- .../history/CalculatorHistoryState.java | 0 .../history/EditorHistoryState.java | 0 .../android/calculator/history/History.java | 98 +-- .../calculator/history/HistoryUtils.java | 156 ++--- .../jscl/FromJsclNumericTextProcessor.java | 92 +-- .../calculator/jscl/JsclOperation.java | 0 .../android/calculator/math/MathType.java | 0 .../android/calculator/model/AFunction.java | 0 .../android/calculator/model/Functions.java | 0 .../calculator/model/MathEntityBuilder.java | 0 .../android/calculator/model/Var.java | 0 .../android/calculator/model/Vars.java | 0 .../calculator/plot/CalculatorPlotter.java | 0 .../plot/CalculatorPlotterImpl.java | 0 .../calculator/plot/FunctionEvaluator.java | 0 .../plot/MapPlotResourceManager.java | 0 .../calculator/plot/PlotBoundaries.java | 0 .../android/calculator/plot/PlotData.java | 0 .../android/calculator/plot/PlotFunction.java | 0 .../calculator/plot/PlotLineColor.java | 0 .../calculator/plot/PlotLineColorType.java | 0 .../android/calculator/plot/PlotLineDef.java | 0 .../calculator/plot/PlotLineStyle.java | 0 .../calculator/plot/PlotResourceManager.java | 0 .../android/calculator/plot/PlotUtils.java | 0 .../android/calculator/plot/XyFunction.java | 498 +++++++-------- .../calculator/text/DummyTextProcessor.java | 90 +-- .../text/FromJsclSimplifyTextProcessor.java | 0 .../calculator/text/TextProcessor.java | 76 +-- .../text/TextProcessorEditorResult.java | 0 .../units/CalculatorNumeralBase.java | 238 +++---- .../android/calculator/messages.properties | 0 .../android/calculator/messages_ar.properties | 0 .../android/calculator/messages_cs.properties | 0 .../android/calculator/messages_de.properties | 0 .../android/calculator/messages_el.properties | 0 .../android/calculator/messages_es.properties | 0 .../calculator/messages_es_ES.properties | 0 .../android/calculator/messages_fi.properties | 0 .../android/calculator/messages_fr.properties | 0 .../android/calculator/messages_it.properties | 0 .../android/calculator/messages_ja.properties | 0 .../android/calculator/messages_nl.properties | 0 .../android/calculator/messages_pl.properties | 0 .../calculator/messages_pt_BR.properties | 0 .../calculator/messages_pt_PT.properties | 0 .../android/calculator/messages_ru.properties | 0 .../android/calculator/messages_tr.properties | 0 .../android/calculator/messages_uk.properties | 0 .../android/calculator/messages_vi.properties | 0 .../android/calculator/messages_zh.properties | 0 .../calculator/messages_zh_CN.properties | 0 .../calculator/messages_zh_TW.properties | 0 .../calculator/AbstractCalculatorTest.java | 0 .../CalculatorDisplayViewStateImplTest.java | 0 .../calculator/CalculatorEditorImplTest.java | 0 .../CalculatorEditorViewStateImplTest.java | 0 .../calculator/CalculatorImplTest.java | 106 ++-- .../calculator/CalculatorMessagesTest.java | 0 .../calculator/CalculatorTestUtils.java | 0 .../FromJsclSimplifyTextProcessorTest.java | 0 .../history/CalculatorHistoryImplTest.java | 152 ++--- .../FromJsclNumericTextProcessorTest.java | 0 .../android/calculator/math/MathTypeTest.java | 0 .../model/AndroidCalculatorEngineTest.java | 436 ++++++------- .../calculator/model/ComparisonTest.java | 0 .../calculator/model/EvaluateTest.java | 0 .../calculator/model/FunctionsTest.java | 0 .../calculator/model/NumeralBaseTest.java | 0 .../model/ToJsclTextProcessorTest.java | 0 .../android/calculator/model/nb_table.csv | 0 core/build.gradle | 28 - .../solovyev/acraanalyzer/AcraAnalyzer.java | 291 --------- settings.gradle | 2 +- 161 files changed, 2711 insertions(+), 3015 deletions(-) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/AbstractCalculatorMathRegistry.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/Calculator.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorClipboard.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventDataImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplay.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventDataImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplayImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplayView.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewState.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEditorChangeEventData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewState.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEngine.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEngineImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventDataImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEventData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEventDataImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorFailure.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorInput.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorInputImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorMathEngine.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorMathRegistry.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorMessage.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorNotifier.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorPostfixFunctionsRegistry.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorPreferenceService.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorSpecialButton.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/Change.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/ChangeImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/ConversionFailure.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/DialogData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/DummyCalculatorClipboard.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/DummyCalculatorNotifier.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/Editor.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/FixableError.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/FunctionCategory.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/LiteNumberBuilder.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/Locator.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/MathEntityDao.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/MathEntityPersistenceContainer.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/MathPersistenceEntity.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/MessageDialogData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/NumberBuilder.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/OperatorCategory.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/PreparedExpression.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/StringDialogData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/VarCategory.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/function/FunctionBuilderAdapter.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java (95%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java (97%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryState.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/History.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/jscl/JsclOperation.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/math/MathType.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/model/AFunction.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/model/Functions.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/model/MathEntityBuilder.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/model/Var.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/model/Vars.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/FunctionEvaluator.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/MapPlotResourceManager.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotBoundaries.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotData.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotLineColor.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotLineColorType.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotLineDef.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotLineStyle.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotResourceManager.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/text/FromJsclSimplifyTextProcessor.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java (96%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/text/TextProcessorEditorResult.java (100%) rename {core => android-app}/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java (96%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_ar.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_cs.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_de.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_el.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_es.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_es_ES.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_fi.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_fr.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_it.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_ja.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_nl.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_pl.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_pt_BR.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_pt_PT.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_ru.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_tr.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_uk.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_vi.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_zh.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_zh_CN.properties (100%) rename {core => android-app}/src/main/resources/org/solovyev/android/calculator/messages_zh_TW.properties (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImplTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/CalculatorEditorImplTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/CalculatorEditorViewStateImplTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java (96%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/CalculatorMessagesTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java (97%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java (97%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/model/ComparisonTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java (100%) rename {core => android-app}/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java (100%) rename {core => android-app}/src/test/resources/org/solovyev/android/calculator/model/nb_table.csv (100%) delete mode 100644 core/build.gradle delete mode 100644 core/src/main/java/org/solovyev/acraanalyzer/AcraAnalyzer.java diff --git a/android-app/build.gradle b/android-app/build.gradle index 51458120..ccdb566d 100644 --- a/android-app/build.gradle +++ b/android-app/build.gradle @@ -62,7 +62,6 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':core') compile 'org.solovyev:common-core:1.0.7' compile 'org.solovyev:common-text:1.0.7' compile 'org.solovyev:common-security:1.0.7' @@ -91,6 +90,22 @@ dependencies { debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' + compile group: 'org.solovyev', name: 'common-text', version: '1.0.7' + compile group: 'org.solovyev', name: 'common-listeners', version: '1.0.7' + compile(group: 'com.google.guava', name: 'guava', version: '11.0.2') { + exclude(module: 'jsr305') + } + compile(group: 'org.solovyev', name: 'jscl', version: '1.0.11') { + exclude(module: 'xercesImpl') + } + compile(group: 'org.simpleframework', name: 'simple-xml', version: '2.6.1') { + exclude(module: 'stax-api') + exclude(module: 'xpp3') + } + compile group: 'commons-cli', name: 'commons-cli', version: '1.2' + testCompile group: 'junit', name: 'junit', version: '4.11' + testCompile group: 'net.sf.opencsv', name: 'opencsv', version: '2.0' + testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0' } task androidJavadocs(type: Javadoc) { diff --git a/core/src/main/java/org/solovyev/android/calculator/AbstractCalculatorMathRegistry.java b/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorMathRegistry.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/AbstractCalculatorMathRegistry.java rename to android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorMathRegistry.java diff --git a/core/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java b/android-app/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java rename to android-app/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java index 3b0c4073..3db71b6c 100644 --- a/core/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/AbstractFixableError.java @@ -1,44 +1,44 @@ -/* - * 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; - -import javax.annotation.Nullable; - -public abstract class AbstractFixableError implements FixableError { - - @Nullable - private String fixCaption; - - protected AbstractFixableError() { - } - - protected AbstractFixableError(@Nullable String fixCaption) { - this.fixCaption = fixCaption; - } - - @Nullable - @Override - public CharSequence getFixCaption() { - return fixCaption; - } -} +/* + * 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; + +import javax.annotation.Nullable; + +public abstract class AbstractFixableError implements FixableError { + + @Nullable + private String fixCaption; + + protected AbstractFixableError() { + } + + protected AbstractFixableError(@Nullable String fixCaption) { + this.fixCaption = fixCaption; + } + + @Nullable + @Override + public CharSequence getFixCaption() { + return fixCaption; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java b/android-app/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java rename to android-app/src/main/java/org/solovyev/android/calculator/AbstractNumberBuilder.java diff --git a/core/src/main/java/org/solovyev/android/calculator/Calculator.java b/android-app/src/main/java/org/solovyev/android/calculator/Calculator.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/Calculator.java rename to android-app/src/main/java/org/solovyev/android/calculator/Calculator.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorClipboard.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorClipboard.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorClipboard.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorClipboard.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java index c34356c4..81c7505c 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventData.java @@ -1,49 +1,49 @@ -/* - * 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; - -import javax.annotation.Nonnull; - -import jscl.NumeralBase; -import jscl.math.Generic; - -/** - * User: Solovyev_S - * Date: 24.09.12 - * Time: 16:45 - */ -public interface CalculatorConversionEventData extends CalculatorEventData { - - // display state on the moment of conversion - @Nonnull - CalculatorDisplayViewState getDisplayState(); - - @Nonnull - NumeralBase getFromNumeralBase(); - - @Nonnull - NumeralBase getToNumeralBase(); - - @Nonnull - Generic getValue(); -} +/* + * 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; + +import javax.annotation.Nonnull; + +import jscl.NumeralBase; +import jscl.math.Generic; + +/** + * User: Solovyev_S + * Date: 24.09.12 + * Time: 16:45 + */ +public interface CalculatorConversionEventData extends CalculatorEventData { + + // display state on the moment of conversion + @Nonnull + CalculatorDisplayViewState getDisplayState(); + + @Nonnull + NumeralBase getFromNumeralBase(); + + @Nonnull + NumeralBase getToNumeralBase(); + + @Nonnull + Generic getValue(); +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventDataImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventDataImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventDataImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorConversionEventDataImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplay.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplay.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplay.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplay.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventData.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventData.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventDataImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventDataImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventDataImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayChangeEventDataImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayView.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayView.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayView.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayView.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewState.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewState.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewState.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewState.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditor.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorChangeEventData.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorChangeEventData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEditorChangeEventData.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorChangeEventData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java index 668d5af0..3b4d8783 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorView.java @@ -1,35 +1,35 @@ -/* - * 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; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 21.09.12 - * Time: 11:48 - */ -public interface CalculatorEditorView { - - void setState(@Nonnull CalculatorEditorViewState viewState); -} +/* + * 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; + +import javax.annotation.Nonnull; + +/** + * User: Solovyev_S + * Date: 21.09.12 + * Time: 11:48 + */ +public interface CalculatorEditorView { + + void setState(@Nonnull CalculatorEditorViewState viewState); +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewState.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewState.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewState.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewState.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java index d882c9f2..7d21ab2b 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorViewStateImpl.java @@ -1,85 +1,85 @@ -/* - * 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; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 21.09.12 - * Time: 12:02 - */ -public class CalculatorEditorViewStateImpl implements CalculatorEditorViewState { - - @Nonnull - private CharSequence text = ""; - - private int selection = 0; - - private CalculatorEditorViewStateImpl() { - } - - public CalculatorEditorViewStateImpl(@Nonnull CalculatorEditorViewState viewState) { - this.text = viewState.getText(); - this.selection = viewState.getSelection(); - } - - @Nonnull - public static CalculatorEditorViewState newDefaultInstance() { - return new CalculatorEditorViewStateImpl(); - } - - @Nonnull - public static CalculatorEditorViewState newSelection(@Nonnull CalculatorEditorViewState viewState, int newSelection) { - final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl(viewState); - - result.selection = newSelection; - - return result; - } - - @Nonnull - public static CalculatorEditorViewState newInstance(@Nonnull CharSequence text, int selection) { - final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl(); - result.text = text; - result.selection = selection; - return result; - } - - @Nonnull - @Override - public String getText() { - return this.text.toString(); - } - - @Nonnull - @Override - public CharSequence getTextAsCharSequence() { - return this.text; - } - - @Override - public int getSelection() { - return this.selection; - } -} +/* + * 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; + +import javax.annotation.Nonnull; + +/** + * User: Solovyev_S + * Date: 21.09.12 + * Time: 12:02 + */ +public class CalculatorEditorViewStateImpl implements CalculatorEditorViewState { + + @Nonnull + private CharSequence text = ""; + + private int selection = 0; + + private CalculatorEditorViewStateImpl() { + } + + public CalculatorEditorViewStateImpl(@Nonnull CalculatorEditorViewState viewState) { + this.text = viewState.getText(); + this.selection = viewState.getSelection(); + } + + @Nonnull + public static CalculatorEditorViewState newDefaultInstance() { + return new CalculatorEditorViewStateImpl(); + } + + @Nonnull + public static CalculatorEditorViewState newSelection(@Nonnull CalculatorEditorViewState viewState, int newSelection) { + final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl(viewState); + + result.selection = newSelection; + + return result; + } + + @Nonnull + public static CalculatorEditorViewState newInstance(@Nonnull CharSequence text, int selection) { + final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl(); + result.text = text; + result.selection = selection; + return result; + } + + @Nonnull + @Override + public String getText() { + return this.text.toString(); + } + + @Nonnull + @Override + public CharSequence getTextAsCharSequence() { + return this.text; + } + + @Override + public int getSelection() { + return this.selection; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEngine.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngine.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEngine.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngine.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java index 920e5506..f8f4b7b0 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngineControl.java @@ -1,35 +1,35 @@ -/* - * 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; - -/** - * User: serso - * Date: 10/24/11 - * Time: 9:55 PM - */ -public interface CalculatorEngineControl { - - void evaluate(); - - void simplify(); -} +/* + * 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; + +/** + * User: serso + * Date: 10/24/11 + * Time: 9:55 PM + */ +public interface CalculatorEngineControl { + + void evaluate(); + + void simplify(); +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEngineImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngineImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEngineImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEngineImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java index 1518e749..bd77f212 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvalException.java @@ -1,88 +1,88 @@ -/* - * 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; - -import org.solovyev.common.msg.Message; -import org.solovyev.common.msg.MessageLevel; - -import java.util.List; -import java.util.Locale; - -import javax.annotation.Nonnull; - -/** - * User: serso - * Date: 12/8/11 - * Time: 1:27 AM - */ -public class CalculatorEvalException extends Exception implements Message { - - @Nonnull - private final Message message; - - @Nonnull - private final String expression; - - public CalculatorEvalException(@Nonnull Message message, @Nonnull Throwable cause, String expression) { - super(cause); - this.message = message; - this.expression = expression; - } - - - @Nonnull - public String getExpression() { - return expression; - } - - @Nonnull - @Override - public String getMessageCode() { - return this.message.getMessageCode(); - } - - @Nonnull - @Override - public List getParameters() { - return this.message.getParameters(); - } - - @Nonnull - @Override - public MessageLevel getMessageLevel() { - return this.message.getMessageLevel(); - } - - @Override - @Nonnull - public String getLocalizedMessage() { - return this.message.getLocalizedMessage(Locale.getDefault()); - } - - @Nonnull - @Override - public String getLocalizedMessage(@Nonnull Locale locale) { - return this.message.getLocalizedMessage(locale); - } -} - +/* + * 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; + +import org.solovyev.common.msg.Message; +import org.solovyev.common.msg.MessageLevel; + +import java.util.List; +import java.util.Locale; + +import javax.annotation.Nonnull; + +/** + * User: serso + * Date: 12/8/11 + * Time: 1:27 AM + */ +public class CalculatorEvalException extends Exception implements Message { + + @Nonnull + private final Message message; + + @Nonnull + private final String expression; + + public CalculatorEvalException(@Nonnull Message message, @Nonnull Throwable cause, String expression) { + super(cause); + this.message = message; + this.expression = expression; + } + + + @Nonnull + public String getExpression() { + return expression; + } + + @Nonnull + @Override + public String getMessageCode() { + return this.message.getMessageCode(); + } + + @Nonnull + @Override + public List getParameters() { + return this.message.getParameters(); + } + + @Nonnull + @Override + public MessageLevel getMessageLevel() { + return this.message.getMessageLevel(); + } + + @Override + @Nonnull + public String getLocalizedMessage() { + return this.message.getLocalizedMessage(Locale.getDefault()); + } + + @Nonnull + @Override + public String getLocalizedMessage(@Nonnull Locale locale) { + return this.message.getLocalizedMessage(locale); + } +} + diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java index 3a2f7f91..c376813d 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventData.java @@ -1,41 +1,41 @@ -/* - * 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; - -import org.solovyev.android.calculator.jscl.JsclOperation; - -import javax.annotation.Nonnull; - -/** - * User: serso - * Date: 9/20/12 - * Time: 10:00 PM - */ -public interface CalculatorEvaluationEventData extends CalculatorEventData { - - @Nonnull - JsclOperation getOperation(); - - @Nonnull - String getExpression(); -} +/* + * 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; + +import org.solovyev.android.calculator.jscl.JsclOperation; + +import javax.annotation.Nonnull; + +/** + * User: serso + * Date: 9/20/12 + * Time: 10:00 PM + */ +public interface CalculatorEvaluationEventData extends CalculatorEventData { + + @Nonnull + JsclOperation getOperation(); + + @Nonnull + String getExpression(); +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventDataImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventDataImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventDataImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEvaluationEventDataImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java index 98efe0db..69922286 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventContainer.java @@ -1,79 +1,79 @@ -/* - * 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; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: Solovyev_S - * Date: 20.09.12 - * Time: 16:39 - */ -public interface CalculatorEventContainer { - - void addCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener); - - void removeCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener); - - void fireCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data); - - void fireCalculatorEvents(@Nonnull List calculatorEvents); - - public static class CalculatorEvent { - - @Nonnull - private CalculatorEventData calculatorEventData; - - @Nonnull - private CalculatorEventType calculatorEventType; - - @Nullable - private Object data; - - public CalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, - @Nonnull CalculatorEventType calculatorEventType, - @Nullable Object data) { - this.calculatorEventData = calculatorEventData; - this.calculatorEventType = calculatorEventType; - this.data = data; - } - - @Nonnull - public CalculatorEventData getCalculatorEventData() { - return calculatorEventData; - } - - @Nonnull - public CalculatorEventType getCalculatorEventType() { - return calculatorEventType; - } - - @Nullable - public Object getData() { - return data; - } - } -} +/* + * 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; + +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: Solovyev_S + * Date: 20.09.12 + * Time: 16:39 + */ +public interface CalculatorEventContainer { + + void addCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener); + + void removeCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener); + + void fireCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data); + + void fireCalculatorEvents(@Nonnull List calculatorEvents); + + public static class CalculatorEvent { + + @Nonnull + private CalculatorEventData calculatorEventData; + + @Nonnull + private CalculatorEventType calculatorEventType; + + @Nullable + private Object data; + + public CalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, + @Nonnull CalculatorEventType calculatorEventType, + @Nullable Object data) { + this.calculatorEventData = calculatorEventData; + this.calculatorEventType = calculatorEventType; + this.data = data; + } + + @Nonnull + public CalculatorEventData getCalculatorEventData() { + return calculatorEventData; + } + + @Nonnull + public CalculatorEventType getCalculatorEventType() { + return calculatorEventType; + } + + @Nullable + public Object getData() { + return data; + } + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventData.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEventData.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventDataImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventDataImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEventDataImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventDataImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java index 341b7de5..bc1efadd 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventHolder.java @@ -1,100 +1,100 @@ -/* - * 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; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 10/9/12 - * Time: 9:59 PM - */ -public class CalculatorEventHolder { - - @Nonnull - private volatile CalculatorEventData lastEventData; - - public CalculatorEventHolder(@Nonnull CalculatorEventData lastEventData) { - this.lastEventData = lastEventData; - } - - @Nonnull - public synchronized CalculatorEventData getLastEventData() { - return lastEventData; - } - - @Nonnull - public synchronized Result apply(@Nonnull CalculatorEventData newEventData) { - final Result result = new Result(lastEventData, newEventData); - - if (result.isNewAfter()) { - this.lastEventData = newEventData; - } - - return result; - } - - public static class Result { - - @Nonnull - private final CalculatorEventData lastEventData; - - @Nonnull - private final CalculatorEventData newEventData; - - @Nullable - private Boolean after = null; - - @Nullable - private Boolean sameSequence = null; - - public Result(@Nonnull CalculatorEventData lastEventData, - @Nonnull CalculatorEventData newEventData) { - this.lastEventData = lastEventData; - this.newEventData = newEventData; - } - - public boolean isNewAfter() { - if (after == null) { - after = newEventData.isAfter(lastEventData); - } - return after; - } - - public boolean isSameSequence() { - if (sameSequence == null) { - sameSequence = newEventData.isSameSequence(lastEventData); - } - return sameSequence; - } - - public boolean isNewAfterSequence() { - return newEventData.isAfterSequence(lastEventData); - } - - public boolean isNewSameOrAfterSequence() { - return isSameSequence() || isNewAfterSequence(); - } - } -} +/* + * 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; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 10/9/12 + * Time: 9:59 PM + */ +public class CalculatorEventHolder { + + @Nonnull + private volatile CalculatorEventData lastEventData; + + public CalculatorEventHolder(@Nonnull CalculatorEventData lastEventData) { + this.lastEventData = lastEventData; + } + + @Nonnull + public synchronized CalculatorEventData getLastEventData() { + return lastEventData; + } + + @Nonnull + public synchronized Result apply(@Nonnull CalculatorEventData newEventData) { + final Result result = new Result(lastEventData, newEventData); + + if (result.isNewAfter()) { + this.lastEventData = newEventData; + } + + return result; + } + + public static class Result { + + @Nonnull + private final CalculatorEventData lastEventData; + + @Nonnull + private final CalculatorEventData newEventData; + + @Nullable + private Boolean after = null; + + @Nullable + private Boolean sameSequence = null; + + public Result(@Nonnull CalculatorEventData lastEventData, + @Nonnull CalculatorEventData newEventData) { + this.lastEventData = lastEventData; + this.newEventData = newEventData; + } + + public boolean isNewAfter() { + if (after == null) { + after = newEventData.isAfter(lastEventData); + } + return after; + } + + public boolean isSameSequence() { + if (sameSequence == null) { + sameSequence = newEventData.isSameSequence(lastEventData); + } + return sameSequence; + } + + public boolean isNewAfterSequence() { + return newEventData.isAfterSequence(lastEventData); + } + + public boolean isNewSameOrAfterSequence() { + return isSameSequence() || isNewAfterSequence(); + } + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java index fe180692..b16eabad 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventListener.java @@ -1,39 +1,39 @@ -/* - * 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; - -import java.util.EventListener; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: Solovyev_S - * Date: 20.09.12 - * Time: 16:39 - */ -public interface CalculatorEventListener extends EventListener { - - void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data); - -} +/* + * 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; + +import java.util.EventListener; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: Solovyev_S + * Date: 20.09.12 + * Time: 16:39 + */ +public interface CalculatorEventListener extends EventListener { + + void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data); + +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorFailure.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFailure.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorFailure.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorFailure.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorFixableError.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsMathRegistry.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorInput.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorInput.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorInput.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorInput.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorInputImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorInputImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorInputImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorInputImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java index 291073c4..45fc7a1f 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java @@ -1,47 +1,47 @@ -/* - * 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; - -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 9/22/12 - * Time: 1:08 PM - */ -public interface CalculatorKeyboard { - - boolean buttonPressed(@Nullable String text); - - void roundBracketsButtonPressed(); - - void pasteButtonPressed(); - - void clearButtonPressed(); - - void copyButtonPressed(); - - void moveCursorLeft(); - - void moveCursorRight(); -} +/* + * 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; + +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 9/22/12 + * Time: 1:08 PM + */ +public interface CalculatorKeyboard { + + boolean buttonPressed(@Nullable String text); + + void roundBracketsButtonPressed(); + + void pasteButtonPressed(); + + void clearButtonPressed(); + + void copyButtonPressed(); + + void moveCursorLeft(); + + void moveCursorRight(); +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorMathEngine.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMathEngine.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorMathEngine.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorMathEngine.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorMathRegistry.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMathRegistry.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorMathRegistry.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorMathRegistry.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorMessage.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessage.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorMessage.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessage.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorNotifier.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorNotifier.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorNotifier.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorNotifier.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorOperatorsMathRegistry.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java index 5599ca28..eb0b6821 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorParseException.java @@ -1,108 +1,108 @@ -/* - * 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; - -import org.solovyev.common.msg.Message; -import org.solovyev.common.msg.MessageLevel; - -import java.util.List; -import java.util.Locale; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 10/6/11 - * Time: 9:25 PM - */ -public class CalculatorParseException extends Exception implements Message { - - @Nonnull - private final Message message; - - @Nonnull - private final String expression; - - @Nullable - private final Integer position; - - public CalculatorParseException(@Nonnull jscl.text.ParseException jsclParseException) { - this.message = jsclParseException; - this.expression = jsclParseException.getExpression(); - this.position = jsclParseException.getPosition(); - } - - public CalculatorParseException(@Nullable Integer position, - @Nonnull String expression, - @Nonnull Message message) { - this.message = message; - this.expression = expression; - this.position = position; - } - - public CalculatorParseException(@Nonnull String expression, - @Nonnull Message message) { - this(null, expression, message); - } - - @Nonnull - public String getExpression() { - return expression; - } - - @Nullable - public Integer getPosition() { - return position; - } - - @Nonnull - @Override - public String getMessageCode() { - return this.message.getMessageCode(); - } - - @Nonnull - @Override - public List getParameters() { - return this.message.getParameters(); - } - - @Nonnull - @Override - public MessageLevel getMessageLevel() { - return this.message.getMessageLevel(); - } - - @Override - @Nonnull - public String getLocalizedMessage() { - return this.message.getLocalizedMessage(Locale.getDefault()); - } - - @Nonnull - @Override - public String getLocalizedMessage(@Nonnull Locale locale) { - return this.message.getLocalizedMessage(locale); - } -} +/* + * 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; + +import org.solovyev.common.msg.Message; +import org.solovyev.common.msg.MessageLevel; + +import java.util.List; +import java.util.Locale; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 10/6/11 + * Time: 9:25 PM + */ +public class CalculatorParseException extends Exception implements Message { + + @Nonnull + private final Message message; + + @Nonnull + private final String expression; + + @Nullable + private final Integer position; + + public CalculatorParseException(@Nonnull jscl.text.ParseException jsclParseException) { + this.message = jsclParseException; + this.expression = jsclParseException.getExpression(); + this.position = jsclParseException.getPosition(); + } + + public CalculatorParseException(@Nullable Integer position, + @Nonnull String expression, + @Nonnull Message message) { + this.message = message; + this.expression = expression; + this.position = position; + } + + public CalculatorParseException(@Nonnull String expression, + @Nonnull Message message) { + this(null, expression, message); + } + + @Nonnull + public String getExpression() { + return expression; + } + + @Nullable + public Integer getPosition() { + return position; + } + + @Nonnull + @Override + public String getMessageCode() { + return this.message.getMessageCode(); + } + + @Nonnull + @Override + public List getParameters() { + return this.message.getParameters(); + } + + @Nonnull + @Override + public MessageLevel getMessageLevel() { + return this.message.getMessageLevel(); + } + + @Override + @Nonnull + public String getLocalizedMessage() { + return this.message.getLocalizedMessage(Locale.getDefault()); + } + + @Nonnull + @Override + public String getLocalizedMessage(@Nonnull Locale locale) { + return this.message.getLocalizedMessage(locale); + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorPostfixFunctionsRegistry.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorPostfixFunctionsRegistry.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorPostfixFunctionsRegistry.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorPostfixFunctionsRegistry.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorPreferenceService.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorPreferenceService.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorPreferenceService.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorPreferenceService.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorSpecialButton.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorSpecialButton.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorSpecialButton.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorSpecialButton.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorUtils.java diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java rename to android-app/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java index 3439eb48..972a45d0 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorVarsRegistry.java @@ -1,153 +1,153 @@ -/* - * 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; - -import org.solovyev.android.calculator.model.MathEntityBuilder; -import org.solovyev.android.calculator.model.Var; -import org.solovyev.android.calculator.model.Vars; -import org.solovyev.common.JBuilder; -import org.solovyev.common.math.MathEntity; -import org.solovyev.common.math.MathRegistry; - -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import jscl.math.function.IConstant; - -/** - * User: serso - * Date: 9/29/11 - * Time: 4:57 PM - */ -public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry { - - @Nonnull - public static final String ANS = "ans"; - - @Nonnull - private static final Map substitutes = new HashMap(); - - static { - substitutes.put("π", "pi"); - substitutes.put("Π", "PI"); - substitutes.put("∞", "inf"); - substitutes.put("h", "h_reduced"); - substitutes.put("NaN", "nan"); - } - - public CalculatorVarsRegistry(@Nonnull MathRegistry mathRegistry, - @Nonnull MathEntityDao mathEntityDao) { - super(mathRegistry, "c_var_description_", mathEntityDao); - } - - public static void saveVariable(@Nonnull CalculatorMathRegistry registry, - @Nonnull MathEntityBuilder builder, - @Nullable T editedInstance, - @Nonnull Object source, boolean save) { - final T addedVar = registry.add(builder); - - if (save) { - registry.save(); - } - - if (editedInstance == null) { - Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source); - } else { - Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source); - } - } - - @Nonnull - @Override - protected Map getSubstitutes() { - return substitutes; - } - - public synchronized void load() { - super.load(); - - tryToAddAuxVar("x"); - tryToAddAuxVar("y"); - tryToAddAuxVar("t"); - tryToAddAuxVar("j"); - - - /*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!"); - for (Var var : vars) { - Log.d(AndroidVarsRegistry.class.getName(), var.toString()); - }*/ - } - - - @Nonnull - @Override - protected JBuilder createBuilder(@Nonnull Var entity) { - return new Var.Builder(entity); - } - - @Nonnull - @Override - protected MathEntityPersistenceContainer createPersistenceContainer() { - return new Vars(); - } - - private void tryToAddAuxVar(@Nonnull String name) { - if (!contains(name)) { - add(new Var.Builder(name, (String) null)); - } - } - - @Nonnull - @Override - protected Var transform(@Nonnull IConstant entity) { - if (entity instanceof Var) { - return (Var) entity; - } else { - return new Var.Builder(entity).create(); - } - } - - @Override - public String getDescription(@Nonnull String mathEntityName) { - final IConstant var = get(mathEntityName); - if (var != null && !var.isSystem()) { - return var.getDescription(); - } else { - return super.getDescription(mathEntityName); - } - } - - @Override - public String getCategory(@Nonnull IConstant var) { - for (VarCategory category : VarCategory.values()) { - if (category.isInCategory(var)) { - return category.name(); - } - } - - return null; - } -} +/* + * 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; + +import org.solovyev.android.calculator.model.MathEntityBuilder; +import org.solovyev.android.calculator.model.Var; +import org.solovyev.android.calculator.model.Vars; +import org.solovyev.common.JBuilder; +import org.solovyev.common.math.MathEntity; +import org.solovyev.common.math.MathRegistry; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import jscl.math.function.IConstant; + +/** + * User: serso + * Date: 9/29/11 + * Time: 4:57 PM + */ +public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry { + + @Nonnull + public static final String ANS = "ans"; + + @Nonnull + private static final Map substitutes = new HashMap(); + + static { + substitutes.put("π", "pi"); + substitutes.put("Π", "PI"); + substitutes.put("∞", "inf"); + substitutes.put("h", "h_reduced"); + substitutes.put("NaN", "nan"); + } + + public CalculatorVarsRegistry(@Nonnull MathRegistry mathRegistry, + @Nonnull MathEntityDao mathEntityDao) { + super(mathRegistry, "c_var_description_", mathEntityDao); + } + + public static void saveVariable(@Nonnull CalculatorMathRegistry registry, + @Nonnull MathEntityBuilder builder, + @Nullable T editedInstance, + @Nonnull Object source, boolean save) { + final T addedVar = registry.add(builder); + + if (save) { + registry.save(); + } + + if (editedInstance == null) { + Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source); + } else { + Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source); + } + } + + @Nonnull + @Override + protected Map getSubstitutes() { + return substitutes; + } + + public synchronized void load() { + super.load(); + + tryToAddAuxVar("x"); + tryToAddAuxVar("y"); + tryToAddAuxVar("t"); + tryToAddAuxVar("j"); + + + /*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!"); + for (Var var : vars) { + Log.d(AndroidVarsRegistry.class.getName(), var.toString()); + }*/ + } + + + @Nonnull + @Override + protected JBuilder createBuilder(@Nonnull Var entity) { + return new Var.Builder(entity); + } + + @Nonnull + @Override + protected MathEntityPersistenceContainer createPersistenceContainer() { + return new Vars(); + } + + private void tryToAddAuxVar(@Nonnull String name) { + if (!contains(name)) { + add(new Var.Builder(name, (String) null)); + } + } + + @Nonnull + @Override + protected Var transform(@Nonnull IConstant entity) { + if (entity instanceof Var) { + return (Var) entity; + } else { + return new Var.Builder(entity).create(); + } + } + + @Override + public String getDescription(@Nonnull String mathEntityName) { + final IConstant var = get(mathEntityName); + if (var != null && !var.isSystem()) { + return var.getDescription(); + } else { + return super.getDescription(mathEntityName); + } + } + + @Override + public String getCategory(@Nonnull IConstant var) { + for (VarCategory category : VarCategory.values()) { + if (category.isInCategory(var)) { + return category.name(); + } + } + + return null; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/Change.java b/android-app/src/main/java/org/solovyev/android/calculator/Change.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/Change.java rename to android-app/src/main/java/org/solovyev/android/calculator/Change.java diff --git a/core/src/main/java/org/solovyev/android/calculator/ChangeImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/ChangeImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/ChangeImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/ChangeImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/ConversionFailure.java b/android-app/src/main/java/org/solovyev/android/calculator/ConversionFailure.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/ConversionFailure.java rename to android-app/src/main/java/org/solovyev/android/calculator/ConversionFailure.java index 1da678ad..aa22ad78 100644 --- a/core/src/main/java/org/solovyev/android/calculator/ConversionFailure.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ConversionFailure.java @@ -1,36 +1,36 @@ -/* - * 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; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 24.09.12 - * Time: 16:12 - */ -public interface ConversionFailure { - - @Nonnull - Exception getException(); -} +/* + * 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; + +import javax.annotation.Nonnull; + +/** + * User: Solovyev_S + * Date: 24.09.12 + * Time: 16:12 + */ +public interface ConversionFailure { + + @Nonnull + Exception getException(); +} diff --git a/core/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java index dbd053a1..fba1d178 100644 --- a/core/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ConversionFailureImpl.java @@ -1,46 +1,46 @@ -/* - * 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; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 24.09.12 - * Time: 16:12 - */ -public class ConversionFailureImpl implements ConversionFailure { - - @Nonnull - private Exception exception; - - public ConversionFailureImpl(@Nonnull Exception exception) { - this.exception = exception; - } - - @Nonnull - @Override - public Exception getException() { - return this.exception; - } -} +/* + * 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; + +import javax.annotation.Nonnull; + +/** + * User: Solovyev_S + * Date: 24.09.12 + * Time: 16:12 + */ +public class ConversionFailureImpl implements ConversionFailure { + + @Nonnull + private Exception exception; + + public ConversionFailureImpl(@Nonnull Exception exception) { + this.exception = exception; + } + + @Nonnull + @Override + public Exception getException() { + return this.exception; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/DialogData.java b/android-app/src/main/java/org/solovyev/android/calculator/DialogData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/DialogData.java rename to android-app/src/main/java/org/solovyev/android/calculator/DialogData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/DummyCalculatorClipboard.java b/android-app/src/main/java/org/solovyev/android/calculator/DummyCalculatorClipboard.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/DummyCalculatorClipboard.java rename to android-app/src/main/java/org/solovyev/android/calculator/DummyCalculatorClipboard.java diff --git a/core/src/main/java/org/solovyev/android/calculator/DummyCalculatorNotifier.java b/android-app/src/main/java/org/solovyev/android/calculator/DummyCalculatorNotifier.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/DummyCalculatorNotifier.java rename to android-app/src/main/java/org/solovyev/android/calculator/DummyCalculatorNotifier.java diff --git a/core/src/main/java/org/solovyev/android/calculator/Editor.java b/android-app/src/main/java/org/solovyev/android/calculator/Editor.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/Editor.java rename to android-app/src/main/java/org/solovyev/android/calculator/Editor.java index ff7e165f..8fae3b52 100644 --- a/core/src/main/java/org/solovyev/android/calculator/Editor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/Editor.java @@ -1,43 +1,43 @@ -/* - * 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; - -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 12/17/11 - * Time: 9:37 PM - */ -public interface Editor { - - @Nullable - CharSequence getText(); - - void setText(@Nullable CharSequence text); - - int getSelection(); - - void setSelection(int selection); - -} +/* + * 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; + +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 12/17/11 + * Time: 9:37 PM + */ +public interface Editor { + + @Nullable + CharSequence getText(); + + void setText(@Nullable CharSequence text); + + int getSelection(); + + void setSelection(int selection); + +} diff --git a/core/src/main/java/org/solovyev/android/calculator/FixableError.java b/android-app/src/main/java/org/solovyev/android/calculator/FixableError.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/FixableError.java rename to android-app/src/main/java/org/solovyev/android/calculator/FixableError.java diff --git a/core/src/main/java/org/solovyev/android/calculator/FunctionCategory.java b/android-app/src/main/java/org/solovyev/android/calculator/FunctionCategory.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/FunctionCategory.java rename to android-app/src/main/java/org/solovyev/android/calculator/FunctionCategory.java diff --git a/core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java b/android-app/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java rename to android-app/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java diff --git a/core/src/main/java/org/solovyev/android/calculator/LiteNumberBuilder.java b/android-app/src/main/java/org/solovyev/android/calculator/LiteNumberBuilder.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/LiteNumberBuilder.java rename to android-app/src/main/java/org/solovyev/android/calculator/LiteNumberBuilder.java diff --git a/core/src/main/java/org/solovyev/android/calculator/Locator.java b/android-app/src/main/java/org/solovyev/android/calculator/Locator.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/Locator.java rename to android-app/src/main/java/org/solovyev/android/calculator/Locator.java diff --git a/core/src/main/java/org/solovyev/android/calculator/MathEntityDao.java b/android-app/src/main/java/org/solovyev/android/calculator/MathEntityDao.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/MathEntityDao.java rename to android-app/src/main/java/org/solovyev/android/calculator/MathEntityDao.java diff --git a/core/src/main/java/org/solovyev/android/calculator/MathEntityPersistenceContainer.java b/android-app/src/main/java/org/solovyev/android/calculator/MathEntityPersistenceContainer.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/MathEntityPersistenceContainer.java rename to android-app/src/main/java/org/solovyev/android/calculator/MathEntityPersistenceContainer.java diff --git a/core/src/main/java/org/solovyev/android/calculator/MathPersistenceEntity.java b/android-app/src/main/java/org/solovyev/android/calculator/MathPersistenceEntity.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/MathPersistenceEntity.java rename to android-app/src/main/java/org/solovyev/android/calculator/MathPersistenceEntity.java diff --git a/core/src/main/java/org/solovyev/android/calculator/MessageDialogData.java b/android-app/src/main/java/org/solovyev/android/calculator/MessageDialogData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/MessageDialogData.java rename to android-app/src/main/java/org/solovyev/android/calculator/MessageDialogData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/NumberBuilder.java b/android-app/src/main/java/org/solovyev/android/calculator/NumberBuilder.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/NumberBuilder.java rename to android-app/src/main/java/org/solovyev/android/calculator/NumberBuilder.java diff --git a/core/src/main/java/org/solovyev/android/calculator/OperatorCategory.java b/android-app/src/main/java/org/solovyev/android/calculator/OperatorCategory.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/OperatorCategory.java rename to android-app/src/main/java/org/solovyev/android/calculator/OperatorCategory.java diff --git a/core/src/main/java/org/solovyev/android/calculator/PreparedExpression.java b/android-app/src/main/java/org/solovyev/android/calculator/PreparedExpression.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/PreparedExpression.java rename to android-app/src/main/java/org/solovyev/android/calculator/PreparedExpression.java index b0583fc0..a145e2d1 100644 --- a/core/src/main/java/org/solovyev/android/calculator/PreparedExpression.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/PreparedExpression.java @@ -1,82 +1,82 @@ -/* - * 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; - -import java.util.List; - -import javax.annotation.Nonnull; - -import jscl.math.function.IConstant; - -/** - * User: serso - * Date: 10/18/11 - * Time: 10:07 PM - */ -public class PreparedExpression implements CharSequence { - - @Nonnull - private String expression; - - @Nonnull - private List undefinedVars; - - public PreparedExpression(@Nonnull String expression, @Nonnull List undefinedVars) { - this.expression = expression; - this.undefinedVars = undefinedVars; - } - - @Nonnull - public String getExpression() { - return expression; - } - - public boolean isExistsUndefinedVar() { - return !this.undefinedVars.isEmpty(); - } - - @Nonnull - public List getUndefinedVars() { - return undefinedVars; - } - - @Override - public int length() { - return expression.length(); - } - - @Override - public char charAt(int i) { - return expression.charAt(i); - } - - @Override - public CharSequence subSequence(int i, int i1) { - return expression.subSequence(i, i1); - } - - @Override - public String toString() { - return this.expression; - } -} +/* + * 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; + +import java.util.List; + +import javax.annotation.Nonnull; + +import jscl.math.function.IConstant; + +/** + * User: serso + * Date: 10/18/11 + * Time: 10:07 PM + */ +public class PreparedExpression implements CharSequence { + + @Nonnull + private String expression; + + @Nonnull + private List undefinedVars; + + public PreparedExpression(@Nonnull String expression, @Nonnull List undefinedVars) { + this.expression = expression; + this.undefinedVars = undefinedVars; + } + + @Nonnull + public String getExpression() { + return expression; + } + + public boolean isExistsUndefinedVar() { + return !this.undefinedVars.isEmpty(); + } + + @Nonnull + public List getUndefinedVars() { + return undefinedVars; + } + + @Override + public int length() { + return expression.length(); + } + + @Override + public char charAt(int i) { + return expression.charAt(i); + } + + @Override + public CharSequence subSequence(int i, int i1) { + return expression.subSequence(i, i1); + } + + @Override + public String toString() { + return this.expression; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/StringDialogData.java b/android-app/src/main/java/org/solovyev/android/calculator/StringDialogData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/StringDialogData.java rename to android-app/src/main/java/org/solovyev/android/calculator/StringDialogData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java b/android-app/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java rename to android-app/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java diff --git a/core/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java rename to android-app/src/main/java/org/solovyev/android/calculator/ToJsclTextProcessor.java diff --git a/core/src/main/java/org/solovyev/android/calculator/VarCategory.java b/android-app/src/main/java/org/solovyev/android/calculator/VarCategory.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/VarCategory.java rename to android-app/src/main/java/org/solovyev/android/calculator/VarCategory.java diff --git a/core/src/main/java/org/solovyev/android/calculator/function/FunctionBuilderAdapter.java b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionBuilderAdapter.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/function/FunctionBuilderAdapter.java rename to android-app/src/main/java/org/solovyev/android/calculator/function/FunctionBuilderAdapter.java diff --git a/core/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java b/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java similarity index 95% rename from core/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java index 2204e33c..dc40d5c6 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/AbstractHistoryState.java @@ -1,97 +1,97 @@ -/* - * 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.history; - -import org.simpleframework.xml.Element; -import org.simpleframework.xml.Transient; - -import java.util.Date; - -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 10/15/11 - * Time: 1:45 PM - */ -public class AbstractHistoryState implements Cloneable { - - @Element - private long time = new Date().getTime(); - - @Element(required = false) - @Nullable - private String comment; - - @Transient - private boolean saved; - - @Transient - private int id = 0; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public long getTime() { - return time; - } - - public void setTime(long time) { - this.time = time; - } - - @Nullable - public String getComment() { - return comment; - } - - public void setComment(@Nullable String comment) { - this.comment = comment; - } - - public boolean isSaved() { - return saved; - } - - public void setSaved(boolean saved) { - this.saved = saved; - } - - @Override - protected AbstractHistoryState clone() { - AbstractHistoryState clone; - - try { - clone = (AbstractHistoryState) super.clone(); - } catch (CloneNotSupportedException e) { - throw new UnsupportedOperationException(e); - } - - return clone; - } -} +/* + * 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.history; + +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Transient; + +import java.util.Date; + +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 10/15/11 + * Time: 1:45 PM + */ +public class AbstractHistoryState implements Cloneable { + + @Element + private long time = new Date().getTime(); + + @Element(required = false) + @Nullable + private String comment; + + @Transient + private boolean saved; + + @Transient + private int id = 0; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } + + @Nullable + public String getComment() { + return comment; + } + + public void setComment(@Nullable String comment) { + this.comment = comment; + } + + public boolean isSaved() { + return saved; + } + + public void setSaved(boolean saved) { + this.saved = saved; + } + + @Override + protected AbstractHistoryState clone() { + AbstractHistoryState clone; + + try { + clone = (AbstractHistoryState) super.clone(); + } catch (CloneNotSupportedException e) { + throw new UnsupportedOperationException(e); + } + + return clone; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java index abaaa8c3..6af6ab91 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorDisplayHistoryState.java @@ -1,161 +1,161 @@ -/* - * 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.history; - -import org.simpleframework.xml.Element; -import org.simpleframework.xml.Root; -import org.simpleframework.xml.Transient; -import org.solovyev.android.calculator.CalculatorDisplay; -import org.solovyev.android.calculator.CalculatorDisplayViewState; -import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl; -import org.solovyev.android.calculator.jscl.JsclOperation; -import org.solovyev.common.text.Strings; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import jscl.math.Generic; - -/** - * User: serso - * Date: 9/17/11 - * Time: 11:05 PM - */ - -@Root -public class CalculatorDisplayHistoryState implements Cloneable { - - @Transient - private boolean valid = true; - - @Transient - @Nullable - private String errorMessage = null; - - @Element - @Nonnull - private EditorHistoryState editorState; - - @Element - @Nonnull - private JsclOperation jsclOperation; - - @Transient - @Nullable - private Generic genericResult; - - private CalculatorDisplayHistoryState() { - // for xml - } - - @Nonnull - public static CalculatorDisplayHistoryState newInstance(@Nonnull CalculatorDisplayViewState viewState) { - final CalculatorDisplayHistoryState result = new CalculatorDisplayHistoryState(); - - result.editorState = EditorHistoryState.newInstance(viewState); - - result.valid = viewState.isValid(); - result.jsclOperation = viewState.getOperation(); - result.genericResult = viewState.getResult(); - result.errorMessage = viewState.getErrorMessage(); - - return result; - } - - public void setValuesFromHistory(@Nonnull CalculatorDisplay display) { - if (this.isValid()) { - display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), Strings.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition())); - } else { - display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), Strings.getNotEmpty(this.getErrorMessage(), ""))); - } - } - - - public boolean isValid() { - return valid; - } - - @Nonnull - public EditorHistoryState getEditorState() { - return editorState; - } - - @Nonnull - public JsclOperation getJsclOperation() { - return jsclOperation; - } - - @Nullable - public String getErrorMessage() { - return errorMessage; - } - - @Nullable - public Generic getGenericResult() { - return genericResult; - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CalculatorDisplayHistoryState that = (CalculatorDisplayHistoryState) o; - - if (!editorState.equals(that.editorState)) return false; - if (jsclOperation != that.jsclOperation) return false; - - return true; - } - - @Override - public int hashCode() { - int result = editorState.hashCode(); - result = 31 * result + jsclOperation.hashCode(); - return result; - } - - @Override - public String toString() { - return "CalculatorDisplayHistoryState{" + - "valid=" + valid + - ", errorMessage='" + errorMessage + '\'' + - ", editorHistoryState=" + editorState + - ", jsclOperation=" + jsclOperation + - '}'; - } - - @Override - protected CalculatorDisplayHistoryState clone() { - try { - final CalculatorDisplayHistoryState clone = (CalculatorDisplayHistoryState) super.clone(); - - clone.editorState = this.editorState.clone(); - - return clone; - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); - } - } -} +/* + * 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.history; + +import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; +import org.simpleframework.xml.Transient; +import org.solovyev.android.calculator.CalculatorDisplay; +import org.solovyev.android.calculator.CalculatorDisplayViewState; +import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl; +import org.solovyev.android.calculator.jscl.JsclOperation; +import org.solovyev.common.text.Strings; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import jscl.math.Generic; + +/** + * User: serso + * Date: 9/17/11 + * Time: 11:05 PM + */ + +@Root +public class CalculatorDisplayHistoryState implements Cloneable { + + @Transient + private boolean valid = true; + + @Transient + @Nullable + private String errorMessage = null; + + @Element + @Nonnull + private EditorHistoryState editorState; + + @Element + @Nonnull + private JsclOperation jsclOperation; + + @Transient + @Nullable + private Generic genericResult; + + private CalculatorDisplayHistoryState() { + // for xml + } + + @Nonnull + public static CalculatorDisplayHistoryState newInstance(@Nonnull CalculatorDisplayViewState viewState) { + final CalculatorDisplayHistoryState result = new CalculatorDisplayHistoryState(); + + result.editorState = EditorHistoryState.newInstance(viewState); + + result.valid = viewState.isValid(); + result.jsclOperation = viewState.getOperation(); + result.genericResult = viewState.getResult(); + result.errorMessage = viewState.getErrorMessage(); + + return result; + } + + public void setValuesFromHistory(@Nonnull CalculatorDisplay display) { + if (this.isValid()) { + display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), Strings.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition())); + } else { + display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), Strings.getNotEmpty(this.getErrorMessage(), ""))); + } + } + + + public boolean isValid() { + return valid; + } + + @Nonnull + public EditorHistoryState getEditorState() { + return editorState; + } + + @Nonnull + public JsclOperation getJsclOperation() { + return jsclOperation; + } + + @Nullable + public String getErrorMessage() { + return errorMessage; + } + + @Nullable + public Generic getGenericResult() { + return genericResult; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CalculatorDisplayHistoryState that = (CalculatorDisplayHistoryState) o; + + if (!editorState.equals(that.editorState)) return false; + if (jsclOperation != that.jsclOperation) return false; + + return true; + } + + @Override + public int hashCode() { + int result = editorState.hashCode(); + result = 31 * result + jsclOperation.hashCode(); + return result; + } + + @Override + public String toString() { + return "CalculatorDisplayHistoryState{" + + "valid=" + valid + + ", errorMessage='" + errorMessage + '\'' + + ", editorHistoryState=" + editorState + + ", jsclOperation=" + jsclOperation + + '}'; + } + + @Override + protected CalculatorDisplayHistoryState clone() { + try { + final CalculatorDisplayHistoryState clone = (CalculatorDisplayHistoryState) super.clone(); + + clone.editorState = this.editorState.clone(); + + return clone; + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java index d9fa8f1f..0ccb6a41 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistory.java @@ -1,63 +1,63 @@ -/* - * 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.history; - -import org.solovyev.android.calculator.CalculatorEventListener; -import org.solovyev.common.history.HistoryHelper; - -import java.util.List; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 20.09.12 - * Time: 16:11 - */ -public interface CalculatorHistory extends HistoryHelper, CalculatorEventListener { - - void load(); - - void save(); - - void fromXml(@Nonnull String xml); - - String toXml(); - - void clearSavedHistory(); - - void removeSavedHistory(@Nonnull CalculatorHistoryState historyState); - - @Nonnull - List getSavedHistory(); - - @Nonnull - CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState); - - @Nonnull - List getStates(); - - @Nonnull - List getStates(boolean includeIntermediateStates); - -} +/* + * 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.history; + +import org.solovyev.android.calculator.CalculatorEventListener; +import org.solovyev.common.history.HistoryHelper; + +import java.util.List; + +import javax.annotation.Nonnull; + +/** + * User: Solovyev_S + * Date: 20.09.12 + * Time: 16:11 + */ +public interface CalculatorHistory extends HistoryHelper, CalculatorEventListener { + + void load(); + + void save(); + + void fromXml(@Nonnull String xml); + + String toXml(); + + void clearSavedHistory(); + + void removeSavedHistory(@Nonnull CalculatorHistoryState historyState); + + @Nonnull + List getSavedHistory(); + + @Nonnull + CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState); + + @Nonnull + List getStates(); + + @Nonnull + List getStates(boolean includeIntermediateStates); + +} diff --git a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java similarity index 97% rename from core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java index 8953aa22..fec202f1 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryImpl.java @@ -1,292 +1,292 @@ -/* - * 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.history; - -import org.solovyev.android.calculator.Calculator; -import org.solovyev.android.calculator.CalculatorDisplayChangeEventData; -import org.solovyev.android.calculator.CalculatorDisplayViewState; -import org.solovyev.android.calculator.CalculatorEditorChangeEventData; -import org.solovyev.android.calculator.CalculatorEditorViewState; -import org.solovyev.android.calculator.CalculatorEventData; -import org.solovyev.android.calculator.CalculatorEventHolder; -import org.solovyev.android.calculator.CalculatorEventType; -import org.solovyev.android.calculator.CalculatorUtils; -import org.solovyev.android.calculator.Locator; -import org.solovyev.common.history.HistoryAction; -import org.solovyev.common.history.HistoryHelper; -import org.solovyev.common.history.SimpleHistoryHelper; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed; -import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed; -import static org.solovyev.android.calculator.CalculatorEventType.manual_calculation_requested; - -/** - * User: Solovyev_S - * Date: 20.09.12 - * Time: 16:12 - */ -public class CalculatorHistoryImpl implements CalculatorHistory { - - private final AtomicInteger counter = new AtomicInteger(0); - - @Nonnull - private final HistoryHelper history = SimpleHistoryHelper.newInstance(); - - @Nonnull - private final List savedHistory = new ArrayList(); - - @Nonnull - private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId()); - - @Nullable - private volatile CalculatorEditorViewState lastEditorViewState; - - public CalculatorHistoryImpl(@Nonnull Calculator calculator) { - calculator.addCalculatorEventListener(this); - } - - @Override - public boolean isEmpty() { - synchronized (history) { - return this.history.isEmpty(); - } - } - - @Override - public CalculatorHistoryState getLastHistoryState() { - synchronized (history) { - return this.history.getLastHistoryState(); - } - } - - @Override - public boolean isUndoAvailable() { - synchronized (history) { - return history.isUndoAvailable(); - } - } - - @Override - public CalculatorHistoryState undo(@Nullable CalculatorHistoryState currentState) { - synchronized (history) { - return history.undo(currentState); - } - } - - @Override - public boolean isRedoAvailable() { - return history.isRedoAvailable(); - } - - @Override - public CalculatorHistoryState redo(@Nullable CalculatorHistoryState currentState) { - synchronized (history) { - return history.redo(currentState); - } - } - - @Override - public boolean isActionAvailable(@Nonnull HistoryAction historyAction) { - synchronized (history) { - return history.isActionAvailable(historyAction); - } - } - - @Override - public CalculatorHistoryState doAction(@Nonnull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) { - synchronized (history) { - return history.doAction(historyAction, currentState); - } - } - - @Override - public void addState(@Nullable CalculatorHistoryState currentState) { - synchronized (history) { - history.addState(currentState); - Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState); - } - } - - @Nonnull - @Override - public List getStates() { - synchronized (history) { - return history.getStates(); - } - } - - @Nonnull - @Override - public List getStates(boolean includeIntermediateStates) { - synchronized (history) { - if (includeIntermediateStates) { - return getStates(); - } else { - final List states = getStates(); - - final List result = new LinkedList(); - - CalculatorHistoryState laterState = null; - for (CalculatorHistoryState state : org.solovyev.common.collections.Collections.reversed(states)) { - if (laterState != null) { - final String laterEditorText = laterState.getEditorState().getText(); - final String editorText = state.getEditorState().getText(); - if (laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) { - // intermediate result => skip from add - } else { - result.add(0, state); - } - } else { - result.add(0, state); - } - - laterState = state; - } - - return result; - } - } - } - - private boolean isIntermediate(@Nonnull String laterEditorText, - @Nonnull String editorText) { - if (Math.abs(laterEditorText.length() - editorText.length()) <= 1) { - if (laterEditorText.length() > editorText.length()) { - return laterEditorText.startsWith(editorText); - } else { - return editorText.startsWith(laterEditorText); - } - } - - return false; - } - - @Override - public void clear() { - synchronized (history) { - this.history.clear(); - } - } - - @Override - @Nonnull - public List getSavedHistory() { - return Collections.unmodifiableList(savedHistory); - } - - @Override - @Nonnull - public CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState) { - if (historyState.isSaved()) { - return historyState; - } else { - final CalculatorHistoryState savedState = historyState.clone(); - - savedState.setId(counter.incrementAndGet()); - savedState.setSaved(true); - - savedHistory.add(savedState); - - return savedState; - } - } - - @Override - public void load() { - // todo serso: create saved/loader class - } - - @Override - public void save() { - // todo serso: create saved/loader class - } - - @Override - public void fromXml(@Nonnull String xml) { - clearSavedHistory(); - - HistoryUtils.fromXml(xml, this.savedHistory); - for (CalculatorHistoryState historyState : savedHistory) { - historyState.setSaved(true); - historyState.setId(counter.incrementAndGet()); - } - } - - @Override - public String toXml() { - return HistoryUtils.toXml(this.savedHistory); - } - - @Override - public void clearSavedHistory() { - this.savedHistory.clear(); - } - - @Override - public void removeSavedHistory(@Nonnull CalculatorHistoryState historyState) { - this.savedHistory.remove(historyState); - } - - @Override - public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, - @Nonnull CalculatorEventType calculatorEventType, - @Nullable Object data) { - if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) { - - final CalculatorEventHolder.Result result = lastEventData.apply(calculatorEventData); - - if (result.isNewAfter() && result.isNewSameOrAfterSequence()) { - switch (calculatorEventType) { - case manual_calculation_requested: - lastEditorViewState = (CalculatorEditorViewState) data; - break; - case editor_state_changed: - final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data; - lastEditorViewState = editorChangeData.getNewValue(); - break; - case display_state_changed: - if (result.isSameSequence()) { - if (lastEditorViewState != null) { - final CalculatorEditorViewState editorViewState = lastEditorViewState; - final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data; - final CalculatorDisplayViewState displayViewState = displayChangeData.getNewValue(); - addState(CalculatorHistoryState.newInstance(editorViewState, displayViewState)); - } - } else { - lastEditorViewState = null; - } - break; - } - } - } - } -} +/* + * 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.history; + +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.CalculatorDisplayChangeEventData; +import org.solovyev.android.calculator.CalculatorDisplayViewState; +import org.solovyev.android.calculator.CalculatorEditorChangeEventData; +import org.solovyev.android.calculator.CalculatorEditorViewState; +import org.solovyev.android.calculator.CalculatorEventData; +import org.solovyev.android.calculator.CalculatorEventHolder; +import org.solovyev.android.calculator.CalculatorEventType; +import org.solovyev.android.calculator.CalculatorUtils; +import org.solovyev.android.calculator.Locator; +import org.solovyev.common.history.HistoryAction; +import org.solovyev.common.history.HistoryHelper; +import org.solovyev.common.history.SimpleHistoryHelper; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed; +import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed; +import static org.solovyev.android.calculator.CalculatorEventType.manual_calculation_requested; + +/** + * User: Solovyev_S + * Date: 20.09.12 + * Time: 16:12 + */ +public class CalculatorHistoryImpl implements CalculatorHistory { + + private final AtomicInteger counter = new AtomicInteger(0); + + @Nonnull + private final HistoryHelper history = SimpleHistoryHelper.newInstance(); + + @Nonnull + private final List savedHistory = new ArrayList(); + + @Nonnull + private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId()); + + @Nullable + private volatile CalculatorEditorViewState lastEditorViewState; + + public CalculatorHistoryImpl(@Nonnull Calculator calculator) { + calculator.addCalculatorEventListener(this); + } + + @Override + public boolean isEmpty() { + synchronized (history) { + return this.history.isEmpty(); + } + } + + @Override + public CalculatorHistoryState getLastHistoryState() { + synchronized (history) { + return this.history.getLastHistoryState(); + } + } + + @Override + public boolean isUndoAvailable() { + synchronized (history) { + return history.isUndoAvailable(); + } + } + + @Override + public CalculatorHistoryState undo(@Nullable CalculatorHistoryState currentState) { + synchronized (history) { + return history.undo(currentState); + } + } + + @Override + public boolean isRedoAvailable() { + return history.isRedoAvailable(); + } + + @Override + public CalculatorHistoryState redo(@Nullable CalculatorHistoryState currentState) { + synchronized (history) { + return history.redo(currentState); + } + } + + @Override + public boolean isActionAvailable(@Nonnull HistoryAction historyAction) { + synchronized (history) { + return history.isActionAvailable(historyAction); + } + } + + @Override + public CalculatorHistoryState doAction(@Nonnull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) { + synchronized (history) { + return history.doAction(historyAction, currentState); + } + } + + @Override + public void addState(@Nullable CalculatorHistoryState currentState) { + synchronized (history) { + history.addState(currentState); + Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState); + } + } + + @Nonnull + @Override + public List getStates() { + synchronized (history) { + return history.getStates(); + } + } + + @Nonnull + @Override + public List getStates(boolean includeIntermediateStates) { + synchronized (history) { + if (includeIntermediateStates) { + return getStates(); + } else { + final List states = getStates(); + + final List result = new LinkedList(); + + CalculatorHistoryState laterState = null; + for (CalculatorHistoryState state : org.solovyev.common.collections.Collections.reversed(states)) { + if (laterState != null) { + final String laterEditorText = laterState.getEditorState().getText(); + final String editorText = state.getEditorState().getText(); + if (laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) { + // intermediate result => skip from add + } else { + result.add(0, state); + } + } else { + result.add(0, state); + } + + laterState = state; + } + + return result; + } + } + } + + private boolean isIntermediate(@Nonnull String laterEditorText, + @Nonnull String editorText) { + if (Math.abs(laterEditorText.length() - editorText.length()) <= 1) { + if (laterEditorText.length() > editorText.length()) { + return laterEditorText.startsWith(editorText); + } else { + return editorText.startsWith(laterEditorText); + } + } + + return false; + } + + @Override + public void clear() { + synchronized (history) { + this.history.clear(); + } + } + + @Override + @Nonnull + public List getSavedHistory() { + return Collections.unmodifiableList(savedHistory); + } + + @Override + @Nonnull + public CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState) { + if (historyState.isSaved()) { + return historyState; + } else { + final CalculatorHistoryState savedState = historyState.clone(); + + savedState.setId(counter.incrementAndGet()); + savedState.setSaved(true); + + savedHistory.add(savedState); + + return savedState; + } + } + + @Override + public void load() { + // todo serso: create saved/loader class + } + + @Override + public void save() { + // todo serso: create saved/loader class + } + + @Override + public void fromXml(@Nonnull String xml) { + clearSavedHistory(); + + HistoryUtils.fromXml(xml, this.savedHistory); + for (CalculatorHistoryState historyState : savedHistory) { + historyState.setSaved(true); + historyState.setId(counter.incrementAndGet()); + } + } + + @Override + public String toXml() { + return HistoryUtils.toXml(this.savedHistory); + } + + @Override + public void clearSavedHistory() { + this.savedHistory.clear(); + } + + @Override + public void removeSavedHistory(@Nonnull CalculatorHistoryState historyState) { + this.savedHistory.remove(historyState); + } + + @Override + public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, + @Nonnull CalculatorEventType calculatorEventType, + @Nullable Object data) { + if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) { + + final CalculatorEventHolder.Result result = lastEventData.apply(calculatorEventData); + + if (result.isNewAfter() && result.isNewSameOrAfterSequence()) { + switch (calculatorEventType) { + case manual_calculation_requested: + lastEditorViewState = (CalculatorEditorViewState) data; + break; + case editor_state_changed: + final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data; + lastEditorViewState = editorChangeData.getNewValue(); + break; + case display_state_changed: + if (result.isSameSequence()) { + if (lastEditorViewState != null) { + final CalculatorEditorViewState editorViewState = lastEditorViewState; + final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data; + final CalculatorDisplayViewState displayViewState = displayChangeData.getNewValue(); + addState(CalculatorHistoryState.newInstance(editorViewState, displayViewState)); + } + } else { + lastEditorViewState = null; + } + break; + } + } + } + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryState.java b/android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryState.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryState.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryState.java diff --git a/core/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java b/android-app/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/EditorHistoryState.java diff --git a/core/src/main/java/org/solovyev/android/calculator/history/History.java b/android-app/src/main/java/org/solovyev/android/calculator/history/History.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/history/History.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/History.java index 62c62782..1ac19c92 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/History.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/History.java @@ -1,49 +1,49 @@ -/* - * 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.history; - -import org.simpleframework.xml.ElementList; -import org.simpleframework.xml.Root; - -import java.util.ArrayList; -import java.util.List; - -/** - * User: serso - * Date: 12/17/11 - * Time: 9:30 PM - */ - -@Root -public class History { - - @ElementList(type = CalculatorHistoryState.class) - private List historyItems = new ArrayList(); - - public History() { - } - - public List getHistoryItems() { - return historyItems; - } -} +/* + * 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.history; + +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; + +import java.util.ArrayList; +import java.util.List; + +/** + * User: serso + * Date: 12/17/11 + * Time: 9:30 PM + */ + +@Root +public class History { + + @ElementList(type = CalculatorHistoryState.class) + private List historyItems = new ArrayList(); + + public History() { + } + + public List getHistoryItems() { + return historyItems; + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java rename to android-app/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java index 1c071368..f2f246e8 100644 --- a/core/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryUtils.java @@ -1,78 +1,78 @@ -/* - * 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.history; - -import org.simpleframework.xml.Serializer; -import org.simpleframework.xml.core.Persister; - -import java.io.StringWriter; -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * User: serso - * Date: 12/17/11 - * Time: 9:59 PM - */ -class HistoryUtils { - - // not intended for instantiation - private HistoryUtils() { - throw new AssertionError(); - } - - public static void fromXml(@Nullable String xml, @Nonnull List historyItems) { - if (xml != null) { - final Serializer serializer = new Persister(); - try { - final History history = serializer.read(History.class, xml); - for (CalculatorHistoryState historyItem : history.getHistoryItems()) { - historyItems.add(historyItem); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - @Nonnull - public static String toXml(@Nonnull List historyItems) { - final History history = new History(); - for (CalculatorHistoryState historyState : historyItems) { - if (historyState.isSaved()) { - history.getHistoryItems().add(historyState); - } - } - - final StringWriter xml = new StringWriter(); - final Serializer serializer = new Persister(); - try { - serializer.write(history, xml); - } catch (Exception e) { - throw new RuntimeException(e); - } - return xml.toString(); - } -} +/* + * 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.history; + +import org.simpleframework.xml.Serializer; +import org.simpleframework.xml.core.Persister; + +import java.io.StringWriter; +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 12/17/11 + * Time: 9:59 PM + */ +class HistoryUtils { + + // not intended for instantiation + private HistoryUtils() { + throw new AssertionError(); + } + + public static void fromXml(@Nullable String xml, @Nonnull List historyItems) { + if (xml != null) { + final Serializer serializer = new Persister(); + try { + final History history = serializer.read(History.class, xml); + for (CalculatorHistoryState historyItem : history.getHistoryItems()) { + historyItems.add(historyItem); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + @Nonnull + public static String toXml(@Nonnull List historyItems) { + final History history = new History(); + for (CalculatorHistoryState historyState : historyItems) { + if (historyState.isSaved()) { + history.getHistoryItems().add(historyState); + } + } + + final StringWriter xml = new StringWriter(); + final Serializer serializer = new Persister(); + try { + serializer.write(history, xml); + } catch (Exception e) { + throw new RuntimeException(e); + } + return xml.toString(); + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java rename to android-app/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java index fbbd61af..d0229f55 100644 --- a/core/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessor.java @@ -1,46 +1,46 @@ -/* - * 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.jscl; - -import org.solovyev.android.calculator.CalculatorParseException; -import org.solovyev.android.calculator.text.TextProcessor; - -import javax.annotation.Nonnull; - -import jscl.math.Generic; - -/** - * User: serso - * Date: 10/6/11 - * Time: 9:48 PM - */ -class FromJsclNumericTextProcessor implements TextProcessor { - - public static final FromJsclNumericTextProcessor instance = new FromJsclNumericTextProcessor(); - - @Nonnull - @Override - public String process(@Nonnull Generic numeric) throws CalculatorParseException { - return numeric.toString().replace("*", ""); - } -} +/* + * 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.jscl; + +import org.solovyev.android.calculator.CalculatorParseException; +import org.solovyev.android.calculator.text.TextProcessor; + +import javax.annotation.Nonnull; + +import jscl.math.Generic; + +/** + * User: serso + * Date: 10/6/11 + * Time: 9:48 PM + */ +class FromJsclNumericTextProcessor implements TextProcessor { + + public static final FromJsclNumericTextProcessor instance = new FromJsclNumericTextProcessor(); + + @Nonnull + @Override + public String process(@Nonnull Generic numeric) throws CalculatorParseException { + return numeric.toString().replace("*", ""); + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/jscl/JsclOperation.java b/android-app/src/main/java/org/solovyev/android/calculator/jscl/JsclOperation.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/jscl/JsclOperation.java rename to android-app/src/main/java/org/solovyev/android/calculator/jscl/JsclOperation.java diff --git a/core/src/main/java/org/solovyev/android/calculator/math/MathType.java b/android-app/src/main/java/org/solovyev/android/calculator/math/MathType.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/math/MathType.java rename to android-app/src/main/java/org/solovyev/android/calculator/math/MathType.java diff --git a/core/src/main/java/org/solovyev/android/calculator/model/AFunction.java b/android-app/src/main/java/org/solovyev/android/calculator/model/AFunction.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/model/AFunction.java rename to android-app/src/main/java/org/solovyev/android/calculator/model/AFunction.java diff --git a/core/src/main/java/org/solovyev/android/calculator/model/Functions.java b/android-app/src/main/java/org/solovyev/android/calculator/model/Functions.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/model/Functions.java rename to android-app/src/main/java/org/solovyev/android/calculator/model/Functions.java diff --git a/core/src/main/java/org/solovyev/android/calculator/model/MathEntityBuilder.java b/android-app/src/main/java/org/solovyev/android/calculator/model/MathEntityBuilder.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/model/MathEntityBuilder.java rename to android-app/src/main/java/org/solovyev/android/calculator/model/MathEntityBuilder.java diff --git a/core/src/main/java/org/solovyev/android/calculator/model/Var.java b/android-app/src/main/java/org/solovyev/android/calculator/model/Var.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/model/Var.java rename to android-app/src/main/java/org/solovyev/android/calculator/model/Var.java diff --git a/core/src/main/java/org/solovyev/android/calculator/model/Vars.java b/android-app/src/main/java/org/solovyev/android/calculator/model/Vars.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/model/Vars.java rename to android-app/src/main/java/org/solovyev/android/calculator/model/Vars.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotter.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotterImpl.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/FunctionEvaluator.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/FunctionEvaluator.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/FunctionEvaluator.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/FunctionEvaluator.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/MapPlotResourceManager.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/MapPlotResourceManager.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/MapPlotResourceManager.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/MapPlotResourceManager.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotBoundaries.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotBoundaries.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotBoundaries.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotBoundaries.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotData.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotData.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotData.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotData.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotFunction.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotLineColor.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineColor.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotLineColor.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineColor.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotLineColorType.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineColorType.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotLineColorType.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineColorType.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotLineDef.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineDef.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotLineDef.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineDef.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotLineStyle.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineStyle.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotLineStyle.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotLineStyle.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotResourceManager.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotResourceManager.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotResourceManager.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotResourceManager.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java diff --git a/core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java rename to android-app/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java index 7380eb45..652593b7 100644 --- a/core/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/XyFunction.java @@ -1,249 +1,249 @@ -/* - * 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.plot; - -import org.solovyev.common.text.Strings; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import jscl.math.Generic; -import jscl.math.function.Constant; - -public class XyFunction implements FunctionEvaluator { - - /* - ********************************************************************** - * - * FIELDS - * - ********************************************************************** - */ - - @Nonnull - private final String id; - @Nonnull - private final FunctionEvaluator evaluator; - @Nonnull - private Generic expression; - @Nonnull - private String expressionString; - @Nullable - private Constant xVariable; - @Nullable - private String xVariableName; - @Nullable - private Constant yVariable; - private boolean imag; - @Nullable - private String yVariableName; - private int arity; - - public XyFunction(@Nonnull Generic expression, - @Nullable Constant xVariable, - @Nullable Constant yVariable, - boolean imag) { - this.expression = expression; - this.xVariable = xVariable; - this.yVariable = yVariable; - this.imag = imag; - - if (imag) { - this.expressionString = "Im(" + expression.toString() + ")"; - this.evaluator = new ImaginaryEvaluator(this); - } else { - this.expressionString = expression.toString(); - this.evaluator = new RealEvaluator(this); - } - this.xVariableName = xVariable == null ? null : xVariable.getName(); - this.yVariableName = yVariable == null ? null : yVariable.getName(); - - this.arity = 2; - if (this.yVariableName == null) { - this.arity--; - } - if (this.xVariableName == null) { - this.arity--; - } - - this.id = this.expressionString + "_" + Strings.getNotEmpty(this.xVariableName, "") + "_" + Strings.getNotEmpty(this.yVariableName, ""); - - } - - public boolean isImag() { - return imag; - } - - @Override - public int getArity() { - return arity; - } - - @Override - public double eval() { - return evaluator.eval(); - } - - @Override - public double eval(double x) { - return evaluator.eval(x); - } - - @Override - public double eval(double x, double y) { - return evaluator.eval(x, y); - } - - @Nonnull - public Generic getExpression() { - return expression; - } - - @Nullable - public Constant getXVariable() { - return xVariable; - } - - @Nullable - public Constant getYVariable() { - return yVariable; - } - - @Nonnull - public String getExpressionString() { - return expressionString; - } - - @Nonnull - public String getId() { - return id; - } - - @Nullable - public String getXVariableName() { - return xVariableName; - } - - @Nullable - public String getYVariableName() { - return yVariableName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof XyFunction)) return false; - - final XyFunction that = (XyFunction) o; - - if (!id.equals(that.id)) return false; - - return true; - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - /* - ********************************************************************** - * - * STATIC - * - ********************************************************************** - */ - - private static abstract class AbstractEvaluator implements FunctionEvaluator { - - @Nonnull - protected final XyFunction xyFunction; - - @Nullable - private Double constant = null; - - public AbstractEvaluator(@Nonnull XyFunction xyFunction) { - this.xyFunction = xyFunction; - } - - @Override - public final double eval() { - if (constant == null) { - constant = eval0(); - } - return constant; - } - - protected abstract double eval0(); - - @Override - public final int getArity() { - return xyFunction.getArity(); - } - - } - - private static class RealEvaluator extends AbstractEvaluator { - - private RealEvaluator(@Nonnull XyFunction xyFunction) { - super(xyFunction); - } - - @Override - public double eval0() { - return PlotUtils.calculatorExpression(xyFunction.expression).realPart(); - } - - @Override - public double eval(double x) { - return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x).realPart(); - } - - @Override - public double eval(double x, double y) { - return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x, xyFunction.yVariable, y).realPart(); - } - } - - private static class ImaginaryEvaluator extends AbstractEvaluator { - - private ImaginaryEvaluator(@Nonnull XyFunction xyFunction) { - super(xyFunction); - } - - @Override - public double eval0() { - return PlotUtils.calculatorExpression(xyFunction.expression).imaginaryPart(); - } - - @Override - public double eval(double x) { - return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x).imaginaryPart(); - } - - @Override - public double eval(double x, double y) { - return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x, xyFunction.yVariable, y).imaginaryPart(); - } - } -} +/* + * 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.plot; + +import org.solovyev.common.text.Strings; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import jscl.math.Generic; +import jscl.math.function.Constant; + +public class XyFunction implements FunctionEvaluator { + + /* + ********************************************************************** + * + * FIELDS + * + ********************************************************************** + */ + + @Nonnull + private final String id; + @Nonnull + private final FunctionEvaluator evaluator; + @Nonnull + private Generic expression; + @Nonnull + private String expressionString; + @Nullable + private Constant xVariable; + @Nullable + private String xVariableName; + @Nullable + private Constant yVariable; + private boolean imag; + @Nullable + private String yVariableName; + private int arity; + + public XyFunction(@Nonnull Generic expression, + @Nullable Constant xVariable, + @Nullable Constant yVariable, + boolean imag) { + this.expression = expression; + this.xVariable = xVariable; + this.yVariable = yVariable; + this.imag = imag; + + if (imag) { + this.expressionString = "Im(" + expression.toString() + ")"; + this.evaluator = new ImaginaryEvaluator(this); + } else { + this.expressionString = expression.toString(); + this.evaluator = new RealEvaluator(this); + } + this.xVariableName = xVariable == null ? null : xVariable.getName(); + this.yVariableName = yVariable == null ? null : yVariable.getName(); + + this.arity = 2; + if (this.yVariableName == null) { + this.arity--; + } + if (this.xVariableName == null) { + this.arity--; + } + + this.id = this.expressionString + "_" + Strings.getNotEmpty(this.xVariableName, "") + "_" + Strings.getNotEmpty(this.yVariableName, ""); + + } + + public boolean isImag() { + return imag; + } + + @Override + public int getArity() { + return arity; + } + + @Override + public double eval() { + return evaluator.eval(); + } + + @Override + public double eval(double x) { + return evaluator.eval(x); + } + + @Override + public double eval(double x, double y) { + return evaluator.eval(x, y); + } + + @Nonnull + public Generic getExpression() { + return expression; + } + + @Nullable + public Constant getXVariable() { + return xVariable; + } + + @Nullable + public Constant getYVariable() { + return yVariable; + } + + @Nonnull + public String getExpressionString() { + return expressionString; + } + + @Nonnull + public String getId() { + return id; + } + + @Nullable + public String getXVariableName() { + return xVariableName; + } + + @Nullable + public String getYVariableName() { + return yVariableName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof XyFunction)) return false; + + final XyFunction that = (XyFunction) o; + + if (!id.equals(that.id)) return false; + + return true; + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + /* + ********************************************************************** + * + * STATIC + * + ********************************************************************** + */ + + private static abstract class AbstractEvaluator implements FunctionEvaluator { + + @Nonnull + protected final XyFunction xyFunction; + + @Nullable + private Double constant = null; + + public AbstractEvaluator(@Nonnull XyFunction xyFunction) { + this.xyFunction = xyFunction; + } + + @Override + public final double eval() { + if (constant == null) { + constant = eval0(); + } + return constant; + } + + protected abstract double eval0(); + + @Override + public final int getArity() { + return xyFunction.getArity(); + } + + } + + private static class RealEvaluator extends AbstractEvaluator { + + private RealEvaluator(@Nonnull XyFunction xyFunction) { + super(xyFunction); + } + + @Override + public double eval0() { + return PlotUtils.calculatorExpression(xyFunction.expression).realPart(); + } + + @Override + public double eval(double x) { + return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x).realPart(); + } + + @Override + public double eval(double x, double y) { + return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x, xyFunction.yVariable, y).realPart(); + } + } + + private static class ImaginaryEvaluator extends AbstractEvaluator { + + private ImaginaryEvaluator(@Nonnull XyFunction xyFunction) { + super(xyFunction); + } + + @Override + public double eval0() { + return PlotUtils.calculatorExpression(xyFunction.expression).imaginaryPart(); + } + + @Override + public double eval(double x) { + return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x).imaginaryPart(); + } + + @Override + public double eval(double x, double y) { + return PlotUtils.calculatorExpression(xyFunction.expression, xyFunction.xVariable, x, xyFunction.yVariable, y).imaginaryPart(); + } + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java rename to android-app/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java index f16c35cd..4cf72fdb 100644 --- a/core/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/text/DummyTextProcessor.java @@ -1,45 +1,45 @@ -/* - * 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.text; - -import org.solovyev.android.calculator.CalculatorParseException; - -import javax.annotation.Nonnull; - -import jscl.math.Generic; - -/** - * User: serso - * Date: 10/18/11 - * Time: 10:39 PM - */ -public enum DummyTextProcessor implements TextProcessor { - - instance; - - @Nonnull - @Override - public String process(@Nonnull Generic s) throws CalculatorParseException { - return s.toString(); - } -} +/* + * 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.text; + +import org.solovyev.android.calculator.CalculatorParseException; + +import javax.annotation.Nonnull; + +import jscl.math.Generic; + +/** + * User: serso + * Date: 10/18/11 + * Time: 10:39 PM + */ +public enum DummyTextProcessor implements TextProcessor { + + instance; + + @Nonnull + @Override + public String process(@Nonnull Generic s) throws CalculatorParseException { + return s.toString(); + } +} diff --git a/core/src/main/java/org/solovyev/android/calculator/text/FromJsclSimplifyTextProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/text/FromJsclSimplifyTextProcessor.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/text/FromJsclSimplifyTextProcessor.java rename to android-app/src/main/java/org/solovyev/android/calculator/text/FromJsclSimplifyTextProcessor.java diff --git a/core/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java rename to android-app/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java index 9dcd66fe..2f65dbef 100644 --- a/core/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/text/TextProcessor.java @@ -1,38 +1,38 @@ -/* - * 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.text; - -import org.solovyev.android.calculator.CalculatorParseException; - -import javax.annotation.Nonnull; - -/** - * User: serso - * Date: 9/26/11 - * Time: 12:12 PM - */ -public interface TextProcessor { - - @Nonnull - TO process(@Nonnull FROM from) throws CalculatorParseException; -} +/* + * 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.text; + +import org.solovyev.android.calculator.CalculatorParseException; + +import javax.annotation.Nonnull; + +/** + * User: serso + * Date: 9/26/11 + * Time: 12:12 PM + */ +public interface TextProcessor { + + @Nonnull + TO process(@Nonnull FROM from) throws CalculatorParseException; +} diff --git a/core/src/main/java/org/solovyev/android/calculator/text/TextProcessorEditorResult.java b/android-app/src/main/java/org/solovyev/android/calculator/text/TextProcessorEditorResult.java similarity index 100% rename from core/src/main/java/org/solovyev/android/calculator/text/TextProcessorEditorResult.java rename to android-app/src/main/java/org/solovyev/android/calculator/text/TextProcessorEditorResult.java diff --git a/core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java b/android-app/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java similarity index 96% rename from core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java rename to android-app/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java index 6450c1cd..dbed130c 100644 --- a/core/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/units/CalculatorNumeralBase.java @@ -1,119 +1,119 @@ -/* - * 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.units; - -import org.solovyev.common.units.Unit; -import org.solovyev.common.units.UnitConverter; -import org.solovyev.common.units.UnitImpl; -import org.solovyev.common.units.UnitType; - -import java.math.BigInteger; - -import javax.annotation.Nonnull; - -import jscl.NumeralBase; - -/** - * User: Solovyev_S - * Date: 24.09.12 - * Time: 16:05 - */ -public enum CalculatorNumeralBase implements UnitType { - - - bin(NumeralBase.bin), - - oct(NumeralBase.oct), - - dec(NumeralBase.dec), - - hex(NumeralBase.hex); - - @Nonnull - private static final CalculatorNumeralBase.Converter converter = new CalculatorNumeralBase.Converter(); - @Nonnull - private final NumeralBase numeralBase; - - private CalculatorNumeralBase(@Nonnull NumeralBase numeralBase) { - this.numeralBase = numeralBase; - } - - @Nonnull - public static CalculatorNumeralBase.Converter getConverter() { - return converter; - } - - @Nonnull - public static CalculatorNumeralBase valueOf(@Nonnull NumeralBase nb) { - for (CalculatorNumeralBase calculatorNumeralBase : values()) { - if (calculatorNumeralBase.numeralBase == nb) { - return calculatorNumeralBase; - } - } - - throw new IllegalArgumentException(nb + " is not supported numeral base!"); - } - - @Nonnull - public NumeralBase getNumeralBase() { - return numeralBase; - } - - @Nonnull - @Override - public Class getUnitValueClass() { - return String.class; - } - - @Nonnull - public Unit createUnit(@Nonnull String value) { - return UnitImpl.newInstance(value, this); - } - - public static class Converter implements UnitConverter { - - private Converter() { - } - - @Override - public boolean isSupported(@Nonnull UnitType from, @Nonnull UnitType to) { - return CalculatorNumeralBase.class.isAssignableFrom(from.getClass()) && CalculatorNumeralBase.class.isAssignableFrom(to.getClass()); - } - - @Nonnull - @Override - public Unit convert(@Nonnull Unit from, @Nonnull UnitType toType) { - if (!isSupported(from.getUnitType(), toType)) { - throw new IllegalArgumentException("Types are not supported!"); - } - - final CalculatorNumeralBase fromTypeAndroid = (CalculatorNumeralBase) from.getUnitType(); - final NumeralBase fromNumeralBase = fromTypeAndroid.numeralBase; - final NumeralBase toNumeralBase = ((CalculatorNumeralBase) toType).numeralBase; - final String fromValue = (String) from.getValue(); - - final BigInteger decBigInteger = fromNumeralBase.toBigInteger(fromValue); - return UnitImpl.newInstance(toNumeralBase.toString(decBigInteger), toType); - } - } -} +/* + * 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.units; + +import org.solovyev.common.units.Unit; +import org.solovyev.common.units.UnitConverter; +import org.solovyev.common.units.UnitImpl; +import org.solovyev.common.units.UnitType; + +import java.math.BigInteger; + +import javax.annotation.Nonnull; + +import jscl.NumeralBase; + +/** + * User: Solovyev_S + * Date: 24.09.12 + * Time: 16:05 + */ +public enum CalculatorNumeralBase implements UnitType { + + + bin(NumeralBase.bin), + + oct(NumeralBase.oct), + + dec(NumeralBase.dec), + + hex(NumeralBase.hex); + + @Nonnull + private static final CalculatorNumeralBase.Converter converter = new CalculatorNumeralBase.Converter(); + @Nonnull + private final NumeralBase numeralBase; + + private CalculatorNumeralBase(@Nonnull NumeralBase numeralBase) { + this.numeralBase = numeralBase; + } + + @Nonnull + public static CalculatorNumeralBase.Converter getConverter() { + return converter; + } + + @Nonnull + public static CalculatorNumeralBase valueOf(@Nonnull NumeralBase nb) { + for (CalculatorNumeralBase calculatorNumeralBase : values()) { + if (calculatorNumeralBase.numeralBase == nb) { + return calculatorNumeralBase; + } + } + + throw new IllegalArgumentException(nb + " is not supported numeral base!"); + } + + @Nonnull + public NumeralBase getNumeralBase() { + return numeralBase; + } + + @Nonnull + @Override + public Class getUnitValueClass() { + return String.class; + } + + @Nonnull + public Unit createUnit(@Nonnull String value) { + return UnitImpl.newInstance(value, this); + } + + public static class Converter implements UnitConverter { + + private Converter() { + } + + @Override + public boolean isSupported(@Nonnull UnitType from, @Nonnull UnitType to) { + return CalculatorNumeralBase.class.isAssignableFrom(from.getClass()) && CalculatorNumeralBase.class.isAssignableFrom(to.getClass()); + } + + @Nonnull + @Override + public Unit convert(@Nonnull Unit from, @Nonnull UnitType toType) { + if (!isSupported(from.getUnitType(), toType)) { + throw new IllegalArgumentException("Types are not supported!"); + } + + final CalculatorNumeralBase fromTypeAndroid = (CalculatorNumeralBase) from.getUnitType(); + final NumeralBase fromNumeralBase = fromTypeAndroid.numeralBase; + final NumeralBase toNumeralBase = ((CalculatorNumeralBase) toType).numeralBase; + final String fromValue = (String) from.getValue(); + + final BigInteger decBigInteger = fromNumeralBase.toBigInteger(fromValue); + return UnitImpl.newInstance(toNumeralBase.toString(decBigInteger), toType); + } + } +} diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_ar.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_ar.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_ar.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_ar.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_cs.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_cs.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_cs.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_cs.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_de.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_de.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_de.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_de.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_el.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_el.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_el.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_el.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_es.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_es.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_es.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_es.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_es_ES.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_es_ES.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_es_ES.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_es_ES.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_fi.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_fi.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_fi.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_fi.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_fr.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_fr.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_fr.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_fr.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_it.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_it.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_it.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_it.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_ja.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_ja.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_ja.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_ja.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_nl.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_nl.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_nl.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_nl.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_pl.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_pl.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_pl.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_pl.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_pt_BR.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_pt_BR.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_pt_BR.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_pt_BR.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_pt_PT.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_pt_PT.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_pt_PT.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_pt_PT.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_ru.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_ru.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_ru.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_ru.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_tr.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_tr.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_tr.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_tr.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_uk.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_uk.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_uk.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_uk.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_vi.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_vi.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_vi.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_vi.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_zh.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_zh.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_zh.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_zh.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_zh_CN.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_zh_CN.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_zh_CN.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_zh_CN.properties diff --git a/core/src/main/resources/org/solovyev/android/calculator/messages_zh_TW.properties b/android-app/src/main/resources/org/solovyev/android/calculator/messages_zh_TW.properties similarity index 100% rename from core/src/main/resources/org/solovyev/android/calculator/messages_zh_TW.properties rename to android-app/src/main/resources/org/solovyev/android/calculator/messages_zh_TW.properties diff --git a/core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java b/android-app/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImplTest.java b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImplTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImplTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/CalculatorDisplayViewStateImplTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorEditorImplTest.java b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorEditorImplTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/CalculatorEditorImplTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/CalculatorEditorImplTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorEditorViewStateImplTest.java b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorEditorViewStateImplTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/CalculatorEditorViewStateImplTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/CalculatorEditorViewStateImplTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java similarity index 96% rename from core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java index 2b62fc2c..a5a4488b 100644 --- a/core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java +++ b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java @@ -1,53 +1,53 @@ -/* - * 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; - -import org.junit.Before; -import org.junit.Test; - -/** - * User: Solovyev_S - * Date: 15.10.12 - * Time: 12:30 - */ -public class CalculatorImplTest extends AbstractCalculatorTest { - - @Before - public void setUp() throws Exception { - super.setUp(); - } - - @Test - public void testAnsVariable() throws Exception { - CalculatorTestUtils.assertEval("2", "2"); - CalculatorTestUtils.assertEval("2", "ans"); - CalculatorTestUtils.assertEval("4", "ans^2"); - CalculatorTestUtils.assertEval("16", "ans^2"); - CalculatorTestUtils.assertEval("0", "0"); - CalculatorTestUtils.assertEval("0", "ans"); - CalculatorTestUtils.assertEval("3", "3"); - CalculatorTestUtils.assertEval("9", "ans*ans"); - CalculatorTestUtils.assertError("ans*an"); - CalculatorTestUtils.assertEval("81", "ans*ans"); - } -} +/* + * 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; + +import org.junit.Before; +import org.junit.Test; + +/** + * User: Solovyev_S + * Date: 15.10.12 + * Time: 12:30 + */ +public class CalculatorImplTest extends AbstractCalculatorTest { + + @Before + public void setUp() throws Exception { + super.setUp(); + } + + @Test + public void testAnsVariable() throws Exception { + CalculatorTestUtils.assertEval("2", "2"); + CalculatorTestUtils.assertEval("2", "ans"); + CalculatorTestUtils.assertEval("4", "ans^2"); + CalculatorTestUtils.assertEval("16", "ans^2"); + CalculatorTestUtils.assertEval("0", "0"); + CalculatorTestUtils.assertEval("0", "ans"); + CalculatorTestUtils.assertEval("3", "3"); + CalculatorTestUtils.assertEval("9", "ans*ans"); + CalculatorTestUtils.assertError("ans*an"); + CalculatorTestUtils.assertEval("81", "ans*ans"); + } +} diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorMessagesTest.java b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorMessagesTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/CalculatorMessagesTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/CalculatorMessagesTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/android-app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java rename to android-app/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java diff --git a/core/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java b/android-app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/FromJsclSimplifyTextProcessorTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java b/android-app/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java similarity index 97% rename from core/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java index acfa8210..d2228bc4 100644 --- a/core/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java +++ b/android-app/src/test/java/org/solovyev/android/calculator/history/CalculatorHistoryImplTest.java @@ -1,76 +1,76 @@ -/* - * 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.history; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl; -import org.solovyev.android.calculator.CalculatorEditorViewStateImpl; -import org.solovyev.android.calculator.CalculatorTestUtils; -import org.solovyev.android.calculator.Locator; - -import java.util.List; - -import javax.annotation.Nonnull; - -/** - * User: Solovyev_S - * Date: 10.10.12 - * Time: 15:07 - */ -public class CalculatorHistoryImplTest { - - @BeforeClass - public static void setUp() throws Exception { - CalculatorTestUtils.staticSetUp(); - } - - @Test - public void testGetStates() throws Exception { - CalculatorHistory calculatorHistory = new CalculatorHistoryImpl(Locator.getInstance().getCalculator()); - - addState(calculatorHistory, "1"); - addState(calculatorHistory, "12"); - addState(calculatorHistory, "123"); - addState(calculatorHistory, "123+"); - addState(calculatorHistory, "123+3"); - addState(calculatorHistory, ""); - addState(calculatorHistory, "2"); - addState(calculatorHistory, "23"); - addState(calculatorHistory, "235"); - addState(calculatorHistory, "2355"); - addState(calculatorHistory, "235"); - addState(calculatorHistory, "2354"); - addState(calculatorHistory, "23547"); - - final List states = calculatorHistory.getStates(false); - Assert.assertEquals(2, states.size()); - Assert.assertEquals("23547", states.get(1).getEditorState().getText()); - Assert.assertEquals("123+3", states.get(0).getEditorState().getText()); - } - - private void addState(@Nonnull CalculatorHistory calculatorHistory, @Nonnull String text) { - calculatorHistory.addState(CalculatorHistoryState.newInstance(CalculatorEditorViewStateImpl.newInstance(text, 3), CalculatorDisplayViewStateImpl.newDefaultInstance())); - } -} +/* + * 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.history; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl; +import org.solovyev.android.calculator.CalculatorEditorViewStateImpl; +import org.solovyev.android.calculator.CalculatorTestUtils; +import org.solovyev.android.calculator.Locator; + +import java.util.List; + +import javax.annotation.Nonnull; + +/** + * User: Solovyev_S + * Date: 10.10.12 + * Time: 15:07 + */ +public class CalculatorHistoryImplTest { + + @BeforeClass + public static void setUp() throws Exception { + CalculatorTestUtils.staticSetUp(); + } + + @Test + public void testGetStates() throws Exception { + CalculatorHistory calculatorHistory = new CalculatorHistoryImpl(Locator.getInstance().getCalculator()); + + addState(calculatorHistory, "1"); + addState(calculatorHistory, "12"); + addState(calculatorHistory, "123"); + addState(calculatorHistory, "123+"); + addState(calculatorHistory, "123+3"); + addState(calculatorHistory, ""); + addState(calculatorHistory, "2"); + addState(calculatorHistory, "23"); + addState(calculatorHistory, "235"); + addState(calculatorHistory, "2355"); + addState(calculatorHistory, "235"); + addState(calculatorHistory, "2354"); + addState(calculatorHistory, "23547"); + + final List states = calculatorHistory.getStates(false); + Assert.assertEquals(2, states.size()); + Assert.assertEquals("23547", states.get(1).getEditorState().getText()); + Assert.assertEquals("123+3", states.get(0).getEditorState().getText()); + } + + private void addState(@Nonnull CalculatorHistory calculatorHistory, @Nonnull String text) { + calculatorHistory.addState(CalculatorHistoryState.newInstance(CalculatorEditorViewStateImpl.newInstance(text, 3), CalculatorDisplayViewStateImpl.newDefaultInstance())); + } +} diff --git a/core/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java b/android-app/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/jscl/FromJsclNumericTextProcessorTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java b/android-app/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java b/android-app/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java similarity index 97% rename from core/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java index cd83e13e..47e3d8c3 100644 --- a/core/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java +++ b/android-app/src/test/java/org/solovyev/android/calculator/model/AndroidCalculatorEngineTest.java @@ -1,218 +1,218 @@ -/* - * 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 junit.framework.Assert; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.solovyev.android.calculator.AbstractCalculatorTest; -import org.solovyev.android.calculator.CalculatorEvalException; -import org.solovyev.android.calculator.CalculatorTestUtils; -import org.solovyev.android.calculator.Locator; -import org.solovyev.android.calculator.jscl.JsclOperation; - -import java.text.DecimalFormatSymbols; -import java.util.Locale; - -import jscl.AngleUnit; -import jscl.JsclMathEngine; -import jscl.MathEngine; -import jscl.NumeralBase; -import jscl.math.Expression; -import jscl.math.function.CustomFunction; -import jscl.text.ParseException; - -import static org.junit.Assert.fail; - - -/** - * User: serso - * Date: 9/17/11 - * Time: 9:47 PM - */ - -@SuppressWarnings("deprecation") -public class AndroidCalculatorEngineTest extends AbstractCalculatorTest { - - @BeforeClass - public static void staticSetUp() throws Exception { - CalculatorTestUtils.staticSetUp(); - Locator.getInstance().getEngine().setPrecision(3); - } - - - @Test - public void testDegrees() throws Exception { - final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); - - final AngleUnit defaultAngleUnit = cm.getAngleUnits(); - try { - cm.setAngleUnits(AngleUnit.rad); - cm.setPrecision(3); - CalculatorTestUtils.assertError("°"); - CalculatorTestUtils.assertEval("0.017", "1°"); - CalculatorTestUtils.assertEval("0.349", "20.0°"); - CalculatorTestUtils.assertEval("0.5", "sin(30°)"); - CalculatorTestUtils.assertEval("0.524", "asin(sin(30°))"); - CalculatorTestUtils.assertEval("∂(cos(t), t, t, 1°)", "∂(cos(t),t,t,1°)"); - - CalculatorTestUtils.assertEval("∂(cos(t), t, t, 1°)", "∂(cos(t),t,t,1°)", JsclOperation.simplify); - } finally { - cm.setAngleUnits(defaultAngleUnit); - } - } - - @Test - public void testFormatting() throws Exception { - final MathEngine ce = Locator.getInstance().getEngine().getMathEngine0(); - - CalculatorTestUtils.assertEval("12 345", ce.simplify("12345")); - - } - - @Test - public void testI() throws ParseException, CalculatorEvalException { - final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); - - CalculatorTestUtils.assertEval("-i", cm.evaluate("i^3")); - for (int i = 0; i < 1000; i++) { - double real = (Math.random() - 0.5) * 1000; - double imag = (Math.random() - 0.5) * 1000; - int exp = (int) (Math.random() * 10); - - final StringBuilder sb = new StringBuilder(); - sb.append(real); - if (imag > 0) { - sb.append("+"); - } - sb.append(imag); - sb.append("^").append(exp); - try { - cm.evaluate(sb.toString()); - } catch (Throwable e) { - fail(sb.toString()); - } - } - } - - @Test - public void testEmptyFunction() throws Exception { - final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); - try { - cm.evaluate("cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))"); - Assert.fail(); - } catch (ParseException e) { - } - CalculatorTestUtils.assertEval("0.34+1.382i", "ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(100)))))))))))))))"); - try { - cm.evaluate("cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos())))))))))))))))))))))))))))))))))))"); - Assert.fail(); - } catch (ParseException e) { - } - - final AngleUnit defaultAngleUnit = cm.getAngleUnits(); - try { - cm.setAngleUnits(AngleUnit.rad); - CalculatorTestUtils.assertEval("0.739", cm.evaluate("cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(1))))))))))))))))))))))))))))))))))))")); - } finally { - cm.setAngleUnits(defaultAngleUnit); - } - - Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d)); - CalculatorTestUtils.assertEval("5", cm.evaluate("si")); - - CalculatorTestUtils.assertError("sin"); - } - - @Test - public void testRounding() throws Exception { - final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); - - try { - DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault()); - decimalGroupSymbols.setDecimalSeparator('.'); - decimalGroupSymbols.setGroupingSeparator('\''); - cm.setDecimalGroupSymbols(decimalGroupSymbols); - cm.setPrecision(2); - CalculatorTestUtils.assertEval("12'345'678.9", cm.evaluate("1.23456789E7")); - cm.setPrecision(10); - CalculatorTestUtils.assertEval("12'345'678.9", cm.evaluate("1.23456789E7")); - CalculatorTestUtils.assertEval("123'456'789", cm.evaluate("1.234567890E8")); - CalculatorTestUtils.assertEval("1'234'567'890.1", cm.evaluate("1.2345678901E9")); - } finally { - cm.setPrecision(3); - DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault()); - decimalGroupSymbols.setDecimalSeparator('.'); - decimalGroupSymbols.setGroupingSeparator(JsclMathEngine.GROUPING_SEPARATOR_DEFAULT.charAt(0)); - cm.setDecimalGroupSymbols(decimalGroupSymbols); - } - } - - @Test - public void testNumeralSystems() throws Exception { - final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); - - CalculatorTestUtils.assertEval("11 259 375", "0x:ABCDEF"); - CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e"); - CalculatorTestUtils.assertEval("30 606 154.462", "e*0x:ABCDEF"); - CalculatorTestUtils.assertEval("e", "e*0x:ABCDEF/0x:ABCDEF"); - CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF"); - CalculatorTestUtils.assertEval("30 606 154.462", "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C"); - CalculatorTestUtils.assertEval("1 446 257 064 651.832", "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) "); - CalculatorTestUtils.assertEval("13", "0b:1101"); - - CalculatorTestUtils.assertError("0b:π"); - - final NumeralBase defaultNumeralBase = cm.getNumeralBase(); - try { - cm.setNumeralBase(NumeralBase.bin); - CalculatorTestUtils.assertEval("101", "10+11"); - CalculatorTestUtils.assertEval("0.101", "10/11"); - - cm.setNumeralBase(NumeralBase.hex); - CalculatorTestUtils.assertEval("63 7B", "56CE+CAD"); - CalculatorTestUtils.assertEval("E", "E"); - } finally { - cm.setNumeralBase(defaultNumeralBase); - } - } - - @Test - public void testLog() throws Exception { - final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); - - CalculatorTestUtils.assertEval("∞", Expression.valueOf("1/0").numeric().toString()); - CalculatorTestUtils.assertEval("∞", Expression.valueOf("ln(10)/ln(1)").numeric().toString()); - - // logarithm - CalculatorTestUtils.assertEval("ln(x)/ln(base)", ((CustomFunction) cm.getFunctionsRegistry().get("log")).getContent()); - CalculatorTestUtils.assertEval("∞", "log(1, 10)"); - CalculatorTestUtils.assertEval("3.322", "log(2, 10)"); - CalculatorTestUtils.assertEval("1.431", "log(5, 10)"); - CalculatorTestUtils.assertEval("0.96", "log(11, 10)"); - CalculatorTestUtils.assertEval("1/(bln(a))", "∂(log(a, b), b)", JsclOperation.simplify); - CalculatorTestUtils.assertEval("-ln(b)/(aln(a)^2)", "∂(log(a, b), a)", JsclOperation.simplify); - - } -} +/* + * 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 junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.solovyev.android.calculator.AbstractCalculatorTest; +import org.solovyev.android.calculator.CalculatorEvalException; +import org.solovyev.android.calculator.CalculatorTestUtils; +import org.solovyev.android.calculator.Locator; +import org.solovyev.android.calculator.jscl.JsclOperation; + +import java.text.DecimalFormatSymbols; +import java.util.Locale; + +import jscl.AngleUnit; +import jscl.JsclMathEngine; +import jscl.MathEngine; +import jscl.NumeralBase; +import jscl.math.Expression; +import jscl.math.function.CustomFunction; +import jscl.text.ParseException; + +import static org.junit.Assert.fail; + + +/** + * User: serso + * Date: 9/17/11 + * Time: 9:47 PM + */ + +@SuppressWarnings("deprecation") +public class AndroidCalculatorEngineTest extends AbstractCalculatorTest { + + @BeforeClass + public static void staticSetUp() throws Exception { + CalculatorTestUtils.staticSetUp(); + Locator.getInstance().getEngine().setPrecision(3); + } + + + @Test + public void testDegrees() throws Exception { + final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); + + final AngleUnit defaultAngleUnit = cm.getAngleUnits(); + try { + cm.setAngleUnits(AngleUnit.rad); + cm.setPrecision(3); + CalculatorTestUtils.assertError("°"); + CalculatorTestUtils.assertEval("0.017", "1°"); + CalculatorTestUtils.assertEval("0.349", "20.0°"); + CalculatorTestUtils.assertEval("0.5", "sin(30°)"); + CalculatorTestUtils.assertEval("0.524", "asin(sin(30°))"); + CalculatorTestUtils.assertEval("∂(cos(t), t, t, 1°)", "∂(cos(t),t,t,1°)"); + + CalculatorTestUtils.assertEval("∂(cos(t), t, t, 1°)", "∂(cos(t),t,t,1°)", JsclOperation.simplify); + } finally { + cm.setAngleUnits(defaultAngleUnit); + } + } + + @Test + public void testFormatting() throws Exception { + final MathEngine ce = Locator.getInstance().getEngine().getMathEngine0(); + + CalculatorTestUtils.assertEval("12 345", ce.simplify("12345")); + + } + + @Test + public void testI() throws ParseException, CalculatorEvalException { + final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); + + CalculatorTestUtils.assertEval("-i", cm.evaluate("i^3")); + for (int i = 0; i < 1000; i++) { + double real = (Math.random() - 0.5) * 1000; + double imag = (Math.random() - 0.5) * 1000; + int exp = (int) (Math.random() * 10); + + final StringBuilder sb = new StringBuilder(); + sb.append(real); + if (imag > 0) { + sb.append("+"); + } + sb.append(imag); + sb.append("^").append(exp); + try { + cm.evaluate(sb.toString()); + } catch (Throwable e) { + fail(sb.toString()); + } + } + } + + @Test + public void testEmptyFunction() throws Exception { + final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); + try { + cm.evaluate("cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))"); + Assert.fail(); + } catch (ParseException e) { + } + CalculatorTestUtils.assertEval("0.34+1.382i", "ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(100)))))))))))))))"); + try { + cm.evaluate("cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos())))))))))))))))))))))))))))))))))))"); + Assert.fail(); + } catch (ParseException e) { + } + + final AngleUnit defaultAngleUnit = cm.getAngleUnits(); + try { + cm.setAngleUnits(AngleUnit.rad); + CalculatorTestUtils.assertEval("0.739", cm.evaluate("cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(1))))))))))))))))))))))))))))))))))))")); + } finally { + cm.setAngleUnits(defaultAngleUnit); + } + + Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d)); + CalculatorTestUtils.assertEval("5", cm.evaluate("si")); + + CalculatorTestUtils.assertError("sin"); + } + + @Test + public void testRounding() throws Exception { + final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); + + try { + DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault()); + decimalGroupSymbols.setDecimalSeparator('.'); + decimalGroupSymbols.setGroupingSeparator('\''); + cm.setDecimalGroupSymbols(decimalGroupSymbols); + cm.setPrecision(2); + CalculatorTestUtils.assertEval("12'345'678.9", cm.evaluate("1.23456789E7")); + cm.setPrecision(10); + CalculatorTestUtils.assertEval("12'345'678.9", cm.evaluate("1.23456789E7")); + CalculatorTestUtils.assertEval("123'456'789", cm.evaluate("1.234567890E8")); + CalculatorTestUtils.assertEval("1'234'567'890.1", cm.evaluate("1.2345678901E9")); + } finally { + cm.setPrecision(3); + DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault()); + decimalGroupSymbols.setDecimalSeparator('.'); + decimalGroupSymbols.setGroupingSeparator(JsclMathEngine.GROUPING_SEPARATOR_DEFAULT.charAt(0)); + cm.setDecimalGroupSymbols(decimalGroupSymbols); + } + } + + @Test + public void testNumeralSystems() throws Exception { + final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); + + CalculatorTestUtils.assertEval("11 259 375", "0x:ABCDEF"); + CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e"); + CalculatorTestUtils.assertEval("30 606 154.462", "e*0x:ABCDEF"); + CalculatorTestUtils.assertEval("e", "e*0x:ABCDEF/0x:ABCDEF"); + CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF"); + CalculatorTestUtils.assertEval("30 606 154.462", "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C"); + CalculatorTestUtils.assertEval("1 446 257 064 651.832", "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) "); + CalculatorTestUtils.assertEval("13", "0b:1101"); + + CalculatorTestUtils.assertError("0b:π"); + + final NumeralBase defaultNumeralBase = cm.getNumeralBase(); + try { + cm.setNumeralBase(NumeralBase.bin); + CalculatorTestUtils.assertEval("101", "10+11"); + CalculatorTestUtils.assertEval("0.101", "10/11"); + + cm.setNumeralBase(NumeralBase.hex); + CalculatorTestUtils.assertEval("63 7B", "56CE+CAD"); + CalculatorTestUtils.assertEval("E", "E"); + } finally { + cm.setNumeralBase(defaultNumeralBase); + } + } + + @Test + public void testLog() throws Exception { + final MathEngine cm = Locator.getInstance().getEngine().getMathEngine0(); + + CalculatorTestUtils.assertEval("∞", Expression.valueOf("1/0").numeric().toString()); + CalculatorTestUtils.assertEval("∞", Expression.valueOf("ln(10)/ln(1)").numeric().toString()); + + // logarithm + CalculatorTestUtils.assertEval("ln(x)/ln(base)", ((CustomFunction) cm.getFunctionsRegistry().get("log")).getContent()); + CalculatorTestUtils.assertEval("∞", "log(1, 10)"); + CalculatorTestUtils.assertEval("3.322", "log(2, 10)"); + CalculatorTestUtils.assertEval("1.431", "log(5, 10)"); + CalculatorTestUtils.assertEval("0.96", "log(11, 10)"); + CalculatorTestUtils.assertEval("1/(bln(a))", "∂(log(a, b), b)", JsclOperation.simplify); + CalculatorTestUtils.assertEval("-ln(b)/(aln(a)^2)", "∂(log(a, b), a)", JsclOperation.simplify); + + } +} diff --git a/core/src/test/java/org/solovyev/android/calculator/model/ComparisonTest.java b/android-app/src/test/java/org/solovyev/android/calculator/model/ComparisonTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/model/ComparisonTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/model/ComparisonTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java b/android-app/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/model/EvaluateTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java b/android-app/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/model/FunctionsTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java b/android-app/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java diff --git a/core/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java b/android-app/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java similarity index 100% rename from core/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java rename to android-app/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java diff --git a/core/src/test/resources/org/solovyev/android/calculator/model/nb_table.csv b/android-app/src/test/resources/org/solovyev/android/calculator/model/nb_table.csv similarity index 100% rename from core/src/test/resources/org/solovyev/android/calculator/model/nb_table.csv rename to android-app/src/test/resources/org/solovyev/android/calculator/model/nb_table.csv diff --git a/core/build.gradle b/core/build.gradle deleted file mode 100644 index 7720f4dc..00000000 --- a/core/build.gradle +++ /dev/null @@ -1,28 +0,0 @@ -apply plugin: 'java' -description = 'Calculator++ Core' -dependencies { - compile group: 'org.solovyev', name: 'common-text', version: '1.0.7' - compile group: 'org.solovyev', name: 'common-listeners', version: '1.0.7' - compile(group: 'com.google.guava', name: 'guava', version: '11.0.2') { - exclude(module: 'jsr305') - } - compile(group: 'org.solovyev', name: 'jscl', version: '1.0.11') { - exclude(module: 'xercesImpl') - } - compile(group: 'org.simpleframework', name: 'simple-xml', version: '2.6.1') { - exclude(module: 'stax-api') - exclude(module: 'xpp3') - } - compile group: 'commons-cli', name: 'commons-cli', version: '1.2' - testCompile group: 'junit', name: 'junit', version: '4.11' - testCompile group: 'net.sf.opencsv', name: 'opencsv', version: '2.0' - testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0' -} - -test { - maxParallelForks = 15 - forkEvery = 1 -} - -sourceCompatibility = JavaVersion.VERSION_1_7 -targetCompatibility = JavaVersion.VERSION_1_7 \ No newline at end of file diff --git a/core/src/main/java/org/solovyev/acraanalyzer/AcraAnalyzer.java b/core/src/main/java/org/solovyev/acraanalyzer/AcraAnalyzer.java deleted file mode 100644 index e3200a7b..00000000 --- a/core/src/main/java/org/solovyev/acraanalyzer/AcraAnalyzer.java +++ /dev/null @@ -1,291 +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.acraanalyzer; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static org.solovyev.common.collections.Collections.getFirstCollectionElement; -import static org.solovyev.common.text.Strings.isEmpty; - -/** - * User: serso - * Date: 6/12/13 - * Time: 10:08 PM - */ -public final class AcraAnalyzer { - - private static final String NEW_LINE = System.getProperty("line.separator"); - - public static void main(String[] args) throws ParseException, FileNotFoundException { - final Options options = new Options(); - options.addOption("path", true, "Path to the ACRA reports"); - options.addOption("file", true, "File name of MBOX file"); - options.addOption("version", true, "Version of the app"); - options.addOption("out", true, "Output file"); - - final CommandLineParser parser = new GnuParser(); - final CommandLine cmd = parser.parse(options, args); - final String path = cmd.getOptionValue("path"); - final String file = cmd.getOptionValue("file"); - final String version = cmd.getOptionValue("version"); - final String out = cmd.getOptionValue("out"); - - if (isEmpty(path) && isEmpty(file)) { - throw new IllegalArgumentException("Either path or filename should be specified"); - } else if (!isEmpty(path) && !isEmpty(file)) { - throw new IllegalArgumentException("Specify either path or filename"); - } else { - final Map> reports = new HashMap>(); - - if (!isEmpty(path)) { - scanFiles(path, reports, version); - } else { - scanMbox(file, reports, version); - } - - PrintStream outIs; - if (!isEmpty(out)) { - final File outFile = new File(out); - outIs = new PrintStream(outFile); - System.out.println("Output will be written to " + outFile.getPath()); - } else { - outIs = System.out; - } - - final List> sortedReports = new ArrayList>(reports.size()); - for (Map.Entry> entry : reports.entrySet()) { - sortedReports.add(entry.getValue()); - } - - Collections.sort(sortedReports, new Comparator>() { - @Override - public int compare(Collection lhs, Collection rhs) { - if (lhs.size() == rhs.size()) { - return 0; - } else if (lhs.size() < rhs.size()) { - return 1; - } else { - return -1; - } - } - }); - - if (!sortedReports.isEmpty()) { - for (Collection sortedReport : sortedReports) { - final AcraReport report = getFirstCollectionElement(sortedReport); - outIs.println("Count: " + sortedReport.size()); - outIs.println("App version: " + report.appVersion); - outIs.println("Android versions: " + getAndroidVersions(sortedReport)); - outIs.println("Phones: " + getPhones(sortedReport)); - outIs.println("Stack trace: " + report.stackTrace); - } - } else { - outIs.println("No ACRA reports found"); - } - } - } - - @Nonnull - private static String getPhones(@Nonnull Collection reports) { - final Set versions = new HashSet(); - for (AcraReport report : reports) { - versions.add(report.brand + "/" + report.phoneModel); - } - return versions.toString(); - } - - @Nonnull - private static String getAndroidVersions(@Nonnull Collection reports) { - final Set versions = new HashSet(); - for (AcraReport report : reports) { - versions.add(report.androidVersion); - } - return versions.toString(); - } - - private static void scanMbox(@Nonnull String filename, @Nonnull Map> reports, @Nullable String version) { - final File file = new File(filename); - if (!file.isDirectory()) { - Scanner scanner = null; - - try { - scanner = new Scanner(file); - while (scanner.hasNextLine()) { - final AcraReport report = readReport(scanner); - putReport(reports, report, version); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } finally { - if (scanner != null) { - scanner.close(); - } - } - } - } - - private static void scanFiles(@Nonnull String path, @Nonnull Map> reports, @Nullable String version) { - final File directory = new File(path); - if (directory.isDirectory()) { - scanFiles(directory, reports, version); - } - } - - private static void scanFiles(@Nonnull File directory, @Nonnull Map> reports, @Nullable String version) { - final File[] files = directory.listFiles(); - if (files != null) { - for (File file : files) { - if (file.isDirectory()) { - scanFiles(file, reports, version); - } else { - analyzeFile(file, reports, version); - } - } - } - } - - private static void analyzeFile(File file, Map> reports, @Nullable String version) { - final AcraReport report = readReport(file); - putReport(reports, report, version); - } - - private static void putReport(@Nonnull Map> reports, @Nonnull AcraReport report, @Nullable String version) { - if (!isEmpty(report.stackTrace) && (version == null || version.equals(report.appVersion))) { - List acraReports = reports.get(report.stackTrace); - if (acraReports == null) { - acraReports = new ArrayList(); - reports.put(report.stackTrace, acraReports); - } - acraReports.add(report); - } - } - - private static AcraReport readReport(@Nonnull File file) { - Scanner scanner = null; - - try { - scanner = new Scanner(file); - return readReport(scanner); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } finally { - if (scanner != null) { - scanner.close(); - } - } - - return new AcraReport(); - } - - @Nonnull - private static AcraReport readReport(@Nonnull Scanner scanner) { - final AcraReport result = new AcraReport(); - - while (scanner.hasNextLine()) { - final String line = scanner.nextLine(); - if (line.startsWith("STACK_TRACE")) { - result.stackTrace = readStackTrace(line.substring("STACK_TRACE=".length()), scanner); - break; - } else if (line.startsWith("ANDROID_VERSION")) { - result.androidVersion = line.substring("ANDROID_VERSION=".length()); - } else if (line.startsWith("APP_VERSION_NAME")) { - result.appVersion = line.substring("APP_VERSION_NAME=".length()); - } else if (line.startsWith("BRAND")) { - result.brand = line.substring("BRAND=".length()); - } else if (line.startsWith("USER_COMMENT")) { - result.userComment = line.substring("USER_COMMENT=".length()); - } else if (line.startsWith("PHONE_MODEL")) { - result.phoneModel = line.substring("PHONE_MODEL=".length()); - } - } - - return result; - } - - private static String readStackTrace(String firstLine, Scanner scanner) { - final StringBuilder sb = new StringBuilder(); - sb.append(firstLine.trim()).append(newLine()); - - while (scanner.hasNextLine()) { - final String line = scanner.nextLine().trim(); - if (isEmpty(line)) { - break; - } else { - sb.append(line).append(newLine()); - } - } - - return sb.toString(); - } - - public static String newLine() { - return NEW_LINE; - } - - private static final class AcraReport { - private String userComment; - private String phoneModel; - private String brand; - private String appVersion; - private String androidVersion; - private String stackTrace = ""; - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - AcraReport that = (AcraReport) o; - - if (!stackTrace.equals(that.stackTrace)) return false; - - return true; - } - - @Override - public int hashCode() { - return stackTrace.hashCode(); - } - } -} diff --git a/settings.gradle b/settings.gradle index a957f493..e0b7ac4f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -include ':core', ':android-app' +include ':android-app' include ':android-app-tests'