registries
This commit is contained in:
parent
4134204e67
commit
52e6b4b79d
@ -22,7 +22,7 @@ import java.util.Map;
|
|||||||
* Date: 11/17/11
|
* Date: 11/17/11
|
||||||
* Time: 11:28 PM
|
* Time: 11:28 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
|
public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegistry<Function, AFunction> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -33,7 +33,7 @@ public class AndroidFunctionsMathRegistry extends AbstractCalculatorMathRegistry
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
|
private static final String FUNCTION_DESCRIPTION_PREFIX = "c_fun_description_";
|
||||||
|
|
||||||
public AndroidFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
|
public CalculatorFunctionsMathRegistry(@NotNull MathRegistry<Function> functionsRegistry,
|
||||||
@NotNull MathEntityDao<AFunction> mathEntityDao) {
|
@NotNull MathEntityDao<AFunction> mathEntityDao) {
|
||||||
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ import java.util.*;
|
|||||||
* Date: 11/17/11
|
* Date: 11/17/11
|
||||||
* Time: 11:29 PM
|
* Time: 11:29 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
public class CalculatorOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -34,7 +34,7 @@ public class AndroidOperatorsMathRegistry extends AbstractCalculatorMathRegistry
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
||||||
|
|
||||||
public AndroidOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
public CalculatorOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||||
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
}
|
}
|
@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
|
import org.solovyev.android.calculator.model.AndroidVarCategory;
|
||||||
import org.solovyev.android.calculator.model.VarCategory;
|
import org.solovyev.android.calculator.model.VarCategory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +56,13 @@ public class CalculatorVarsActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.getCaptionId(), R.id.main_layout);
|
final AndroidVarCategory androidVarCategory = AndroidVarCategory.valueOf(category);
|
||||||
|
|
||||||
|
if (androidVarCategory != null) {
|
||||||
|
activityHelper.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidVarCategory.getCaptionId(), R.id.main_layout);
|
||||||
|
} else {
|
||||||
|
activityHelper.logError("Unable to find android var category for " + category);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,10 +108,10 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
|
|||||||
|
|
||||||
final JsclMathEngine engine = JsclMathEngine.getInstance();
|
final JsclMathEngine engine = JsclMathEngine.getInstance();
|
||||||
this.calculatorEngine = new CalculatorEngineImpl(engine,
|
this.calculatorEngine = new CalculatorEngineImpl(engine,
|
||||||
new AndroidVarsRegistryImpl(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
|
new CalculatorVarsRegistry(engine.getConstantsRegistry(), new AndroidMathEntityDao<Var>(R.string.p_calc_vars, application, Vars.class)),
|
||||||
new AndroidFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
|
new CalculatorFunctionsMathRegistry(engine.getFunctionsRegistry(), new AndroidMathEntityDao<AFunction>(R.string.p_calc_functions, application, Functions.class)),
|
||||||
new AndroidOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
new CalculatorOperatorsMathRegistry(engine.getOperatorsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
||||||
new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
new CalculatorPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry(), new AndroidMathEntityDao<MathPersistenceEntity>(null, application, null)),
|
||||||
this.lock);
|
this.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package org.solovyev.android.calculator.model;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/7/12
|
||||||
|
* Time: 7:56 PM
|
||||||
|
*/
|
||||||
|
public enum AndroidVarCategory {
|
||||||
|
|
||||||
|
system(R.string.c_var_system),
|
||||||
|
my(R.string.c_var_my);
|
||||||
|
|
||||||
|
private final int captionId;
|
||||||
|
|
||||||
|
AndroidVarCategory(int captionId) {
|
||||||
|
this.captionId = captionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCaptionId() {
|
||||||
|
return captionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static AndroidVarCategory valueOf(@NotNull VarCategory varCategory) {
|
||||||
|
for (AndroidVarCategory androidVarCategory : values()) {
|
||||||
|
if ( androidVarCategory.name().equals(varCategory.name()) ) {
|
||||||
|
return androidVarCategory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||||||
* Date: 11/19/11
|
* Date: 11/19/11
|
||||||
* Time: 1:48 PM
|
* Time: 1:48 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
public class CalculatorPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -34,7 +34,7 @@ public class AndroidPostfixFunctionsRegistry extends AbstractCalculatorMathRegis
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
|
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
|
||||||
|
|
||||||
protected AndroidPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
protected CalculatorPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||||
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
||||||
}
|
}
|
@ -22,7 +22,7 @@ import java.util.Map;
|
|||||||
* Date: 9/29/11
|
* Date: 9/29/11
|
||||||
* Time: 4:57 PM
|
* Time: 4:57 PM
|
||||||
*/
|
*/
|
||||||
class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
@ -34,7 +34,7 @@ class AndroidVarsRegistryImpl extends AbstractCalculatorMathRegistry<IConstant,
|
|||||||
substitutes.put("NaN", "nan");
|
substitutes.put("NaN", "nan");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AndroidVarsRegistryImpl(@NotNull MathRegistry<IConstant> mathRegistry,
|
protected CalculatorVarsRegistry(@NotNull MathRegistry<IConstant> mathRegistry,
|
||||||
@NotNull MathEntityDao<Var> mathEntityDao) {
|
@NotNull MathEntityDao<Var> mathEntityDao) {
|
||||||
super(mathRegistry, "c_var_description_", mathEntityDao);
|
super(mathRegistry, "c_var_description_", mathEntityDao);
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ package org.solovyev.android.calculator.model;
|
|||||||
|
|
||||||
import jscl.math.function.IConstant;
|
import jscl.math.function.IConstant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -16,33 +15,26 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public enum VarCategory {
|
public enum VarCategory {
|
||||||
|
|
||||||
system(R.string.c_var_system, 100){
|
system(100){
|
||||||
@Override
|
@Override
|
||||||
boolean isInCategory(@NotNull IConstant var) {
|
boolean isInCategory(@NotNull IConstant var) {
|
||||||
return var.isSystem();
|
return var.isSystem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
my(R.string.c_var_my, 0) {
|
my(0) {
|
||||||
@Override
|
@Override
|
||||||
boolean isInCategory(@NotNull IConstant var) {
|
boolean isInCategory(@NotNull IConstant var) {
|
||||||
return !var.isSystem();
|
return !var.isSystem();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int captionId;
|
|
||||||
|
|
||||||
private final int tabOrder;
|
private final int tabOrder;
|
||||||
|
|
||||||
VarCategory(int captionId, int tabOrder) {
|
VarCategory(int tabOrder) {
|
||||||
this.captionId = captionId;
|
|
||||||
this.tabOrder = tabOrder;
|
this.tabOrder = tabOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCaptionId() {
|
|
||||||
return captionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract boolean isInCategory(@NotNull IConstant var);
|
abstract boolean isInCategory(@NotNull IConstant var);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
Reference in New Issue
Block a user