CalculatorHistory -> History

This commit is contained in:
serso 2016-01-12 14:00:58 +01:00
parent 6d91013858
commit 5813f41f4c
8 changed files with 42 additions and 39 deletions

View File

@ -25,12 +25,14 @@ package org.solovyev.android.calculator;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.LeakCanary;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ACRAConfiguration; import org.acra.ACRAConfiguration;
import org.acra.sender.HttpSender; import org.acra.sender.HttpSender;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
@ -40,11 +42,12 @@ import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
import org.solovyev.android.calculator.view.EditorTextProcessor; import org.solovyev.android.calculator.view.EditorTextProcessor;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nonnull;
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull @Nonnull
private final List<CalculatorEventListener> listeners = new ArrayList<>(); private final List<CalculatorEventListener> listeners = new ArrayList<>();
@ -74,7 +77,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
new AndroidCalculatorEngine(this), new AndroidCalculatorEngine(this),
new AndroidCalculatorClipboard(this), new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this), new AndroidCalculatorNotifier(this),
new CalculatorHistory(), new History(),
new AndroidCalculatorLogger(), new AndroidCalculatorLogger(),
new AndroidCalculatorPreferenceService(this), new AndroidCalculatorPreferenceService(this),
new CalculatorKeyboard(), new CalculatorKeyboard(),

View File

@ -22,7 +22,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.text.TextProcessorEditorResult; import org.solovyev.android.calculator.text.TextProcessorEditorResult;
@ -41,7 +41,7 @@ public interface CalculatorLocator {
@Nonnull CalculatorEngine engine, @Nonnull CalculatorEngine engine,
@Nonnull CalculatorClipboard clipboard, @Nonnull CalculatorClipboard clipboard,
@Nonnull CalculatorNotifier notifier, @Nonnull CalculatorNotifier notifier,
@Nonnull CalculatorHistory history, @Nonnull History history,
@Nonnull CalculatorLogger logger, @Nonnull CalculatorLogger logger,
@Nonnull CalculatorPreferenceService preferenceService, @Nonnull CalculatorPreferenceService preferenceService,
@Nonnull CalculatorKeyboard keyboard, @Nonnull CalculatorKeyboard keyboard,
@ -70,7 +70,7 @@ public interface CalculatorLocator {
CalculatorNotifier getNotifier(); CalculatorNotifier getNotifier();
@Nonnull @Nonnull
CalculatorHistory getHistory(); History getHistory();
@Nonnull @Nonnull
CalculatorLogger getLogger(); CalculatorLogger getLogger();

View File

@ -22,7 +22,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.text.TextProcessorEditorResult; import org.solovyev.android.calculator.text.TextProcessorEditorResult;
@ -50,7 +50,7 @@ public class Locator implements CalculatorLocator {
@Nonnull @Nonnull
private CalculatorKeyboard calculatorKeyboard; private CalculatorKeyboard calculatorKeyboard;
@Nonnull @Nonnull
private CalculatorHistory calculatorHistory; private History history;
@Nonnull @Nonnull
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier(); private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
@Nonnull @Nonnull
@ -76,7 +76,7 @@ public class Locator implements CalculatorLocator {
@Nonnull CalculatorEngine engine, @Nonnull CalculatorEngine engine,
@Nonnull CalculatorClipboard clipboard, @Nonnull CalculatorClipboard clipboard,
@Nonnull CalculatorNotifier notifier, @Nonnull CalculatorNotifier notifier,
@Nonnull CalculatorHistory history, @Nonnull History history,
@Nonnull CalculatorLogger logger, @Nonnull CalculatorLogger logger,
@Nonnull CalculatorPreferenceService preferenceService, @Nonnull CalculatorPreferenceService preferenceService,
@Nonnull CalculatorKeyboard keyboard, @Nonnull CalculatorKeyboard keyboard,
@ -87,7 +87,7 @@ public class Locator implements CalculatorLocator {
this.calculatorEngine = engine; this.calculatorEngine = engine;
this.calculatorClipboard = clipboard; this.calculatorClipboard = clipboard;
this.calculatorNotifier = notifier; this.calculatorNotifier = notifier;
this.calculatorHistory = history; this.history = history;
this.calculatorLogger = logger; this.calculatorLogger = logger;
this.calculatorPreferenceService = preferenceService; this.calculatorPreferenceService = preferenceService;
this.calculatorPlotter = plotter; this.calculatorPlotter = plotter;
@ -145,8 +145,8 @@ public class Locator implements CalculatorLocator {
@Override @Override
@Nonnull @Nonnull
public CalculatorHistory getHistory() { public History getHistory() {
return calculatorHistory; return history;
} }
@Override @Override

View File

@ -51,7 +51,7 @@ import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class CalculatorHistory { public class History {
public static final String TAG = App.subTag("History"); public static final String TAG = App.subTag("History");
@Nonnull @Nonnull
@ -62,7 +62,7 @@ public class CalculatorHistory {
private EditorState lastEditorState; private EditorState lastEditorState;
private boolean initialized; private boolean initialized;
public CalculatorHistory() { public History() {
App.getBus().register(this); App.getBus().register(this);
App.getInitThread().execute(new Runnable() { App.getInitThread().execute(new Runnable() {
@Override @Override

View File

@ -121,7 +121,7 @@ public class HistoryList {
try { try {
array.put(i, state.toJson()); array.put(i, state.toJson());
} catch (JSONException e) { } catch (JSONException e) {
Log.e(CalculatorHistory.TAG, e.getMessage(), e); Log.e(History.TAG, e.getMessage(), e);
} }
} }
return array; return array;
@ -138,7 +138,7 @@ public class HistoryList {
try { try {
states.add(HistoryState.create(json)); states.add(HistoryState.create(json));
} catch (JSONException e) { } catch (JSONException e) {
Log.e(CalculatorHistory.TAG, e.getMessage(), e); Log.e(History.TAG, e.getMessage(), e);
} }
} }
return states; return states;

View File

@ -23,7 +23,7 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
/** /**
@ -34,7 +34,7 @@ import org.solovyev.android.calculator.plot.CalculatorPlotter;
public class AbstractCalculatorTest { public class AbstractCalculatorTest {
protected void setUp() throws Exception { protected void setUp() throws Exception {
Locator.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null); Locator.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(History.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
Locator.getInstance().getEngine().init(); Locator.getInstance().getEngine().init();
} }

View File

@ -26,7 +26,7 @@ import android.content.Context;
import org.junit.Assert; import org.junit.Assert;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
@ -56,7 +56,7 @@ public class CalculatorTestUtils {
public static final int TIMEOUT = 3; public static final int TIMEOUT = 3;
public static void staticSetUp() throws Exception { public static void staticSetUp() throws Exception {
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null); Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(History.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
Locator.getInstance().getEngine().init(); Locator.getInstance().getEngine().init();
final DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(); final DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols();
@ -66,7 +66,7 @@ public class CalculatorTestUtils {
} }
public static void staticSetUp(@Nullable Context context) throws Exception { public static void staticSetUp(@Nullable Context context) throws Exception {
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null); Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(History.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
Locator.getInstance().getEngine().init(); Locator.getInstance().getEngine().init();
if (context != null) { if (context != null) {

View File

@ -38,7 +38,7 @@ import javax.annotation.Nonnull;
* Date: 10.10.12 * Date: 10.10.12
* Time: 15:07 * Time: 15:07
*/ */
public class CalculatorHistoryTest { public class HistoryTest {
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
@ -47,29 +47,29 @@ public class CalculatorHistoryTest {
@Test @Test
public void testGetStates() throws Exception { public void testGetStates() throws Exception {
CalculatorHistory calculatorHistory = new CalculatorHistory(); History history = new History();
addState(calculatorHistory, "1"); addState(history, "1");
addState(calculatorHistory, "12"); addState(history, "12");
addState(calculatorHistory, "123"); addState(history, "123");
addState(calculatorHistory, "123+"); addState(history, "123+");
addState(calculatorHistory, "123+3"); addState(history, "123+3");
addState(calculatorHistory, ""); addState(history, "");
addState(calculatorHistory, "2"); addState(history, "2");
addState(calculatorHistory, "23"); addState(history, "23");
addState(calculatorHistory, "235"); addState(history, "235");
addState(calculatorHistory, "2355"); addState(history, "2355");
addState(calculatorHistory, "235"); addState(history, "235");
addState(calculatorHistory, "2354"); addState(history, "2354");
addState(calculatorHistory, "23547"); addState(history, "23547");
final List<HistoryState> states = calculatorHistory.getCurrent(); final List<HistoryState> states = history.getCurrent();
Assert.assertEquals(2, states.size()); Assert.assertEquals(2, states.size());
Assert.assertEquals("23547", states.get(1).editor.getTextString()); Assert.assertEquals("23547", states.get(1).editor.getTextString());
Assert.assertEquals("123+3", states.get(0).editor.getTextString()); Assert.assertEquals("123+3", states.get(0).editor.getTextString());
} }
private void addState(@Nonnull CalculatorHistory calculatorHistory, @Nonnull String text) { private void addState(@Nonnull History history, @Nonnull String text) {
calculatorHistory.addCurrent(HistoryState.newBuilder(EditorState.create(text, 3), DisplayState.empty())); history.addCurrent(HistoryState.newBuilder(EditorState.create(text, 3), DisplayState.empty()));
} }
} }