core moved to android-app

This commit is contained in:
serso 2016-01-05 09:42:17 +01:00
parent c2146dc0f6
commit d834ccc305
161 changed files with 2711 additions and 3015 deletions

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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<Object> 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<Object> 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);
}
}

View File

@ -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();
}

View File

@ -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<CalculatorEvent> 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<CalculatorEvent> 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;
}
}
}

View File

@ -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();
}
}
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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<Object> 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<Object> 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);
}
}

View File

@ -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<IConstant, Var> {
@Nonnull
public static final String ANS = "ans";
@Nonnull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("π", "pi");
substitutes.put("Π", "PI");
substitutes.put("", "inf");
substitutes.put("h", "h_reduced");
substitutes.put("NaN", "nan");
}
public CalculatorVarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
@Nonnull MathEntityDao<Var> mathEntityDao) {
super(mathRegistry, "c_var_description_", mathEntityDao);
}
public static <T extends MathEntity> void saveVariable(@Nonnull CalculatorMathRegistry<T> registry,
@Nonnull MathEntityBuilder<? extends T> 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<String, String> 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<? extends IConstant> createBuilder(@Nonnull Var entity) {
return new Var.Builder(entity);
}
@Nonnull
@Override
protected MathEntityPersistenceContainer<Var> 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<IConstant, Var> {
@Nonnull
public static final String ANS = "ans";
@Nonnull
private static final Map<String, String> substitutes = new HashMap<String, String>();
static {
substitutes.put("π", "pi");
substitutes.put("Π", "PI");
substitutes.put("", "inf");
substitutes.put("h", "h_reduced");
substitutes.put("NaN", "nan");
}
public CalculatorVarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
@Nonnull MathEntityDao<Var> mathEntityDao) {
super(mathRegistry, "c_var_description_", mathEntityDao);
}
public static <T extends MathEntity> void saveVariable(@Nonnull CalculatorMathRegistry<T> registry,
@Nonnull MathEntityBuilder<? extends T> 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<String, String> 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<? extends IConstant> createBuilder(@Nonnull Var entity) {
return new Var.Builder(entity);
}
@Nonnull
@Override
protected MathEntityPersistenceContainer<Var> 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;
}
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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<IConstant> undefinedVars;
public PreparedExpression(@Nonnull String expression, @Nonnull List<IConstant> undefinedVars) {
this.expression = expression;
this.undefinedVars = undefinedVars;
}
@Nonnull
public String getExpression() {
return expression;
}
public boolean isExistsUndefinedVar() {
return !this.undefinedVars.isEmpty();
}
@Nonnull
public List<IConstant> 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<IConstant> undefinedVars;
public PreparedExpression(@Nonnull String expression, @Nonnull List<IConstant> undefinedVars) {
this.expression = expression;
this.undefinedVars = undefinedVars;
}
@Nonnull
public String getExpression() {
return expression;
}
public boolean isExistsUndefinedVar() {
return !this.undefinedVars.isEmpty();
}
@Nonnull
public List<IConstant> 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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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<CalculatorHistoryState>, CalculatorEventListener {
void load();
void save();
void fromXml(@Nonnull String xml);
String toXml();
void clearSavedHistory();
void removeSavedHistory(@Nonnull CalculatorHistoryState historyState);
@Nonnull
List<CalculatorHistoryState> getSavedHistory();
@Nonnull
CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState);
@Nonnull
List<CalculatorHistoryState> getStates();
@Nonnull
List<CalculatorHistoryState> 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<CalculatorHistoryState>, CalculatorEventListener {
void load();
void save();
void fromXml(@Nonnull String xml);
String toXml();
void clearSavedHistory();
void removeSavedHistory(@Nonnull CalculatorHistoryState historyState);
@Nonnull
List<CalculatorHistoryState> getSavedHistory();
@Nonnull
CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState);
@Nonnull
List<CalculatorHistoryState> getStates();
@Nonnull
List<CalculatorHistoryState> getStates(boolean includeIntermediateStates);
}

View File

@ -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<CalculatorHistoryState> history = SimpleHistoryHelper.newInstance();
@Nonnull
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
@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<CalculatorHistoryState> getStates() {
synchronized (history) {
return history.getStates();
}
}
@Nonnull
@Override
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
synchronized (history) {
if (includeIntermediateStates) {
return getStates();
} else {
final List<CalculatorHistoryState> states = getStates();
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
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<CalculatorHistoryState> 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<CalculatorHistoryState> history = SimpleHistoryHelper.newInstance();
@Nonnull
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
@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<CalculatorHistoryState> getStates() {
synchronized (history) {
return history.getStates();
}
}
@Nonnull
@Override
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
synchronized (history) {
if (includeIntermediateStates) {
return getStates();
} else {
final List<CalculatorHistoryState> states = getStates();
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
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<CalculatorHistoryState> 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;
}
}
}
}
}

View File

@ -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<CalculatorHistoryState> historyItems = new ArrayList<CalculatorHistoryState>();
public History() {
}
public List<CalculatorHistoryState> 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<CalculatorHistoryState> historyItems = new ArrayList<CalculatorHistoryState>();
public History() {
}
public List<CalculatorHistoryState> getHistoryItems() {
return historyItems;
}
}

View File

@ -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<CalculatorHistoryState> 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<CalculatorHistoryState> 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<CalculatorHistoryState> 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<CalculatorHistoryState> 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();
}
}

View File

@ -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<String, Generic> {
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<String, Generic> {
public static final FromJsclNumericTextProcessor instance = new FromJsclNumericTextProcessor();
@Nonnull
@Override
public String process(@Nonnull Generic numeric) throws CalculatorParseException {
return numeric.toString().replace("*", "");
}
}

Some files were not shown because too many files have changed in this diff Show More