changes
This commit is contained in:
@@ -31,4 +31,11 @@ public class CalculatorFailureImpl implements CalculatorFailure {
|
||||
public CalculatorEvalException getCalculationEvalException() {
|
||||
return exception instanceof CalculatorEvalException ? (CalculatorEvalException)exception : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CalculatorFailureImpl{" +
|
||||
"exception=" + exception +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,8 @@ public interface CalculatorLocator {
|
||||
@NotNull CalculatorEngine engine,
|
||||
@NotNull CalculatorClipboard clipboard,
|
||||
@NotNull CalculatorNotifier notifier,
|
||||
@NotNull CalculatorHistory history);
|
||||
@NotNull CalculatorHistory history,
|
||||
@NotNull CalculatorLogger logger);
|
||||
|
||||
@NotNull
|
||||
Calculator getCalculator();
|
||||
@@ -39,4 +40,7 @@ public interface CalculatorLocator {
|
||||
|
||||
@NotNull
|
||||
CalculatorHistory getHistory();
|
||||
|
||||
@NotNull
|
||||
CalculatorLogger getLogger();
|
||||
}
|
||||
|
@@ -1,113 +1,124 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 20.09.12
|
||||
* Time: 12:45
|
||||
*/
|
||||
public class CalculatorLocatorImpl implements CalculatorLocator {
|
||||
|
||||
@NotNull
|
||||
private CalculatorEngine calculatorEngine;
|
||||
|
||||
@NotNull
|
||||
private Calculator calculator;
|
||||
|
||||
@NotNull
|
||||
private CalculatorEditor calculatorEditor;
|
||||
|
||||
@NotNull
|
||||
private CalculatorDisplay calculatorDisplay;
|
||||
|
||||
@NotNull
|
||||
private CalculatorKeyboard calculatorKeyboard;
|
||||
|
||||
@NotNull
|
||||
private CalculatorHistory calculatorHistory;
|
||||
|
||||
@NotNull
|
||||
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
|
||||
|
||||
@NotNull
|
||||
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
|
||||
|
||||
@NotNull
|
||||
private static final CalculatorLocator instance = new CalculatorLocatorImpl();
|
||||
|
||||
public CalculatorLocatorImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(@NotNull Calculator calculator,
|
||||
@NotNull CalculatorEngine engine,
|
||||
@NotNull CalculatorClipboard clipboard,
|
||||
@NotNull CalculatorNotifier notifier,
|
||||
@NotNull CalculatorHistory history) {
|
||||
|
||||
this.calculator = calculator;
|
||||
this.calculatorEngine = engine;
|
||||
this.calculatorClipboard = clipboard;
|
||||
this.calculatorNotifier = notifier;
|
||||
this.calculatorHistory = history;
|
||||
|
||||
calculatorEditor = new CalculatorEditorImpl(this.calculator);
|
||||
calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
|
||||
calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CalculatorLocator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CalculatorEngine getEngine() {
|
||||
return calculatorEngine;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Calculator getCalculator() {
|
||||
return this.calculator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorDisplay getDisplay() {
|
||||
return calculatorDisplay;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CalculatorEditor getEditor() {
|
||||
return calculatorEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorKeyboard getKeyboard() {
|
||||
return calculatorKeyboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorClipboard getClipboard() {
|
||||
return calculatorClipboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorNotifier getNotifier() {
|
||||
return calculatorNotifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorHistory getHistory() {
|
||||
return calculatorHistory;
|
||||
}
|
||||
}
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 20.09.12
|
||||
* Time: 12:45
|
||||
*/
|
||||
public class CalculatorLocatorImpl implements CalculatorLocator {
|
||||
|
||||
@NotNull
|
||||
private CalculatorEngine calculatorEngine;
|
||||
|
||||
@NotNull
|
||||
private Calculator calculator;
|
||||
|
||||
@NotNull
|
||||
private CalculatorEditor calculatorEditor;
|
||||
|
||||
@NotNull
|
||||
private CalculatorDisplay calculatorDisplay;
|
||||
|
||||
@NotNull
|
||||
private CalculatorKeyboard calculatorKeyboard;
|
||||
|
||||
@NotNull
|
||||
private CalculatorHistory calculatorHistory;
|
||||
|
||||
@NotNull
|
||||
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
|
||||
|
||||
@NotNull
|
||||
private CalculatorLogger calculatorLogger = new SystemOutCalculatorLogger();
|
||||
|
||||
@NotNull
|
||||
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
|
||||
|
||||
@NotNull
|
||||
private static final CalculatorLocator instance = new CalculatorLocatorImpl();
|
||||
|
||||
public CalculatorLocatorImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(@NotNull Calculator calculator,
|
||||
@NotNull CalculatorEngine engine,
|
||||
@NotNull CalculatorClipboard clipboard,
|
||||
@NotNull CalculatorNotifier notifier,
|
||||
@NotNull CalculatorHistory history,
|
||||
@NotNull CalculatorLogger logger) {
|
||||
|
||||
this.calculator = calculator;
|
||||
this.calculatorEngine = engine;
|
||||
this.calculatorClipboard = clipboard;
|
||||
this.calculatorNotifier = notifier;
|
||||
this.calculatorHistory = history;
|
||||
this.calculatorLogger = logger;
|
||||
|
||||
calculatorEditor = new CalculatorEditorImpl(this.calculator);
|
||||
calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
|
||||
calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CalculatorLocator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CalculatorEngine getEngine() {
|
||||
return calculatorEngine;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Calculator getCalculator() {
|
||||
return this.calculator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorDisplay getDisplay() {
|
||||
return calculatorDisplay;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CalculatorEditor getEditor() {
|
||||
return calculatorEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorKeyboard getKeyboard() {
|
||||
return calculatorKeyboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorClipboard getClipboard() {
|
||||
return calculatorClipboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorNotifier getNotifier() {
|
||||
return calculatorNotifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorHistory getHistory() {
|
||||
return calculatorHistory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorLogger getLogger() {
|
||||
return calculatorLogger;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/11/12
|
||||
* Time: 12:11 AM
|
||||
*/
|
||||
public interface CalculatorLogger {
|
||||
|
||||
void debug(@Nullable String tag, @NotNull String message);
|
||||
|
||||
void debug(@Nullable String tag, @NotNull String message, @NotNull Throwable e);
|
||||
}
|
@@ -39,10 +39,18 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
|
||||
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
|
||||
final List<CalculatorEventListener> listeners = this.listeners.getListeners();
|
||||
|
||||
final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
|
||||
|
||||
for (CalculatorEvent e : calculatorEvents) {
|
||||
//Log.d(TAG, "Event: " + e.getCalculatorEventType() + " with data: " + e.getData());
|
||||
for (CalculatorEventListener listener : listeners) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());
|
||||
long endTime = System.currentTimeMillis();
|
||||
long totalTime = (endTime - startTime);
|
||||
if ( totalTime > 300 ) {
|
||||
logger.debug(TAG + "_" + e.getCalculatorEventData().getEventId(), "Started event: " + e.getCalculatorEventType() + " with data: " + e.getData() + " for: " + listener.getClass().getSimpleName());
|
||||
logger.debug(TAG + "_" + e.getCalculatorEventData().getEventId(), "Total time, ms: " + totalTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/11/12
|
||||
* Time: 12:12 AM
|
||||
*/
|
||||
public class SystemOutCalculatorLogger implements CalculatorLogger {
|
||||
|
||||
@NotNull
|
||||
private static final String TAG = SystemOutCalculatorLogger.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void debug(@Nullable String tag, @NotNull String message) {
|
||||
System.out.println(getTag(tag) + ": " + message);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getTag(@Nullable String tag) {
|
||||
return tag != null ? tag : TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(@Nullable String tag, @NotNull String message, @NotNull Throwable e) {
|
||||
debug(tag, message);
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
public class AbstractCalculatorTest {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ public class CalculatorTestUtils {
|
||||
public static final int TIMEOUT = 1;
|
||||
|
||||
public static void staticSetUp() throws Exception {
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
|
||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user