From c62126bfa878241b96991e41c7f24b461b2fe04e Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 19 Sep 2011 12:53:23 +0400 Subject: [PATCH] refactor --- .../android/calculator/CalculatorEditText.java | 9 --------- .../android/calculator/CalculatorModel.java | 12 +++++------- .../android/calculator/CalculatorView.java | 2 +- .../android/calculator/Preprocessor.java | 5 ++--- .../calculator}/math/Functions.java | 2 +- .../calculator}/math/MathEntityType.java | 2 +- .../java/org/solovyev/util/math/Complex.java | 17 ++++++++++------- 7 files changed, 20 insertions(+), 29 deletions(-) rename src/main/java/org/solovyev/{util => android/calculator}/math/Functions.java (95%) rename src/main/java/org/solovyev/{util => android/calculator}/math/MathEntityType.java (98%) diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorEditText.java b/src/main/java/org/solovyev/android/calculator/CalculatorEditText.java index 0bec6c7e..3cac4bdc 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorEditText.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorEditText.java @@ -7,18 +7,9 @@ package org.solovyev.android.calculator; import android.content.Context; import android.content.res.ColorStateList; -import android.text.Html; import android.util.AttributeSet; import android.widget.EditText; -import android.widget.TextView; -import org.solovyev.common.definitions.Pair; import org.solovyev.common.exceptions.SersoException; -import org.solovyev.common.utils.CollectionsUtils; -import org.solovyev.util.math.MathEntityType; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; /** * User: serso diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorModel.java b/src/main/java/org/solovyev/android/calculator/CalculatorModel.java index 27948fe4..99615ebd 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorModel.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorModel.java @@ -10,7 +10,6 @@ import bsh.Interpreter; import org.jetbrains.annotations.NotNull; import org.solovyev.common.exceptions.SersoException; import org.solovyev.common.utils.MathUtils; -import org.solovyev.common.utils.StringUtils; import org.solovyev.util.math.Complex; /** @@ -42,7 +41,7 @@ public class CalculatorModel { String result = String.valueOf(evaluationObject).trim(); try { - result = round(result); + result = String.valueOf(round(result)); } catch (NumberFormatException e) { if (result.contains("sqrt(-1)")) { try { @@ -82,8 +81,8 @@ public class CalculatorModel { int multiplyIndex = s.indexOf("*"); if (multiplyIndex >= 0) { - complex.setImag(round(s.substring(plusIndex >= 0 ? plusIndex+1 : 0, multiplyIndex))); - result += complex.getImag(); + complex.setImaginary(round(s.substring(plusIndex >= 0 ? plusIndex + 1 : 0, multiplyIndex))); + result += complex.getImaginary(); } @@ -92,10 +91,9 @@ public class CalculatorModel { return result; } - private String round(@NotNull String result) { + private Double round(@NotNull String result) { final Double dResult = Double.valueOf(result); - result = String.valueOf(MathUtils.round(dResult, NUMBER_OF_FRACTION_DIGITS)); - return result; + return MathUtils.round(dResult, NUMBER_OF_FRACTION_DIGITS); } public static class ParseException extends SersoException { diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorView.java b/src/main/java/org/solovyev/android/calculator/CalculatorView.java index 86f87d70..0def0da2 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorView.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorView.java @@ -19,6 +19,7 @@ import android.widget.Toast; import bsh.EvalError; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.math.MathEntityType; import org.solovyev.android.view.CursorControl; import org.solovyev.android.view.HistoryControl; import org.solovyev.common.utils.MutableObject; @@ -26,7 +27,6 @@ import org.solovyev.common.utils.StringUtils; import org.solovyev.common.utils.history.HistoryAction; import org.solovyev.common.utils.history.HistoryHelper; import org.solovyev.common.utils.history.SimpleHistoryHelper; -import org.solovyev.util.math.MathEntityType; /** * User: serso diff --git a/src/main/java/org/solovyev/android/calculator/Preprocessor.java b/src/main/java/org/solovyev/android/calculator/Preprocessor.java index 235efeb8..35ad3735 100644 --- a/src/main/java/org/solovyev/android/calculator/Preprocessor.java +++ b/src/main/java/org/solovyev/android/calculator/Preprocessor.java @@ -7,11 +7,10 @@ package org.solovyev.android.calculator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.math.Functions; +import org.solovyev.android.calculator.math.MathEntityType; import org.solovyev.common.utils.CollectionsUtils; -import org.solovyev.common.utils.EqualsFinder; import org.solovyev.common.utils.Finder; -import org.solovyev.util.math.Functions; -import org.solovyev.util.math.MathEntityType; public class Preprocessor { diff --git a/src/main/java/org/solovyev/util/math/Functions.java b/src/main/java/org/solovyev/android/calculator/math/Functions.java similarity index 95% rename from src/main/java/org/solovyev/util/math/Functions.java rename to src/main/java/org/solovyev/android/calculator/math/Functions.java index 962a5ced..67d4e3d5 100644 --- a/src/main/java/org/solovyev/util/math/Functions.java +++ b/src/main/java/org/solovyev/android/calculator/math/Functions.java @@ -3,7 +3,7 @@ * For more information, please, contact se.solovyev@gmail.com */ -package org.solovyev.util.math; +package org.solovyev.android.calculator.math; import org.jetbrains.annotations.NonNls; diff --git a/src/main/java/org/solovyev/util/math/MathEntityType.java b/src/main/java/org/solovyev/android/calculator/math/MathEntityType.java similarity index 98% rename from src/main/java/org/solovyev/util/math/MathEntityType.java rename to src/main/java/org/solovyev/android/calculator/math/MathEntityType.java index 5d2c39e9..95d50f6f 100644 --- a/src/main/java/org/solovyev/util/math/MathEntityType.java +++ b/src/main/java/org/solovyev/android/calculator/math/MathEntityType.java @@ -3,7 +3,7 @@ * For more information, please, contact se.solovyev@gmail.com */ -package org.solovyev.util.math; +package org.solovyev.android.calculator.math; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/org/solovyev/util/math/Complex.java b/src/main/java/org/solovyev/util/math/Complex.java index 0834b8ef..90fe9cf0 100644 --- a/src/main/java/org/solovyev/util/math/Complex.java +++ b/src/main/java/org/solovyev/util/math/Complex.java @@ -15,23 +15,26 @@ import org.jetbrains.annotations.Nullable; public class Complex { @Nullable - private String real, imag; + private Double real; @Nullable - public String getReal() { + private Double imaginary; + + @Nullable + public Double getReal() { return real; } - public void setReal(@Nullable String real) { + public void setReal(@Nullable Double real) { this.real = real; } @Nullable - public String getImag() { - return imag; + public Double getImaginary() { + return imaginary; } - public void setImag(@Nullable String imag) { - this.imag = imag; + public void setImaginary(@Nullable Double imaginary) { + this.imaginary = imaginary; } }