registries
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.math.operator.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.JBuilder;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/17/11
|
||||
* Time: 11:29 PM
|
||||
*/
|
||||
public class CalculatorOperatorsMathRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||
|
||||
@NotNull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
static {
|
||||
substitutes.put("Σ", "sum");
|
||||
substitutes.put("∏", "product");
|
||||
substitutes.put("∂", "derivative");
|
||||
substitutes.put("∫ab", "integral_ab");
|
||||
substitutes.put("∫", "integral");
|
||||
substitutes.put("Σ", "sum");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static final String OPERATOR_DESCRIPTION_PREFIX = "c_op_description_";
|
||||
|
||||
public CalculatorOperatorsMathRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||
super(functionsRegistry, OPERATOR_DESCRIPTION_PREFIX, mathEntityDao);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory(@NotNull Operator operator) {
|
||||
for (OperatorCategory category : OperatorCategory.values()) {
|
||||
if ( category.isInCategory(operator) ) {
|
||||
return category.name();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// not supported yet
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// not supported yet
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MathPersistenceEntity transform(@NotNull Operator entity) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.math.operator.Operator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.JBuilder;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/19/11
|
||||
* Time: 1:48 PM
|
||||
*/
|
||||
public class CalculatorPostfixFunctionsRegistry extends AbstractCalculatorMathRegistry<Operator, MathPersistenceEntity> {
|
||||
|
||||
@NotNull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
static {
|
||||
substitutes.put("%", "percent");
|
||||
substitutes.put("!", "factorial");
|
||||
substitutes.put("!!", "double_factorial");
|
||||
substitutes.put("°", "degree");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static final String POSTFIX_FUNCTION_DESCRIPTION_PREFIX = "c_pf_description_";
|
||||
|
||||
public CalculatorPostfixFunctionsRegistry(@NotNull MathRegistry<Operator> functionsRegistry,
|
||||
@NotNull MathEntityDao<MathPersistenceEntity> mathEntityDao) {
|
||||
super(functionsRegistry, POSTFIX_FUNCTION_DESCRIPTION_PREFIX, mathEntityDao);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory(@NotNull Operator operator) {
|
||||
for (OperatorCategory category : OperatorCategory.values()) {
|
||||
if ( category.isInCategory(operator) ) {
|
||||
return category.name();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// not supported yet
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JBuilder<? extends Operator> createBuilder(@NotNull MathPersistenceEntity entity) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// not supported yet
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MathPersistenceEntity transform(@NotNull Operator entity) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected MathEntityPersistenceContainer<MathPersistenceEntity> createPersistenceContainer() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.model.Var;
|
||||
import org.solovyev.android.calculator.model.Vars;
|
||||
import org.solovyev.common.JBuilder;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/29/11
|
||||
* Time: 4:57 PM
|
||||
*/
|
||||
public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
||||
|
||||
@NotNull
|
||||
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(@NotNull MathRegistry<IConstant> mathRegistry,
|
||||
@NotNull MathEntityDao<Var> mathEntityDao) {
|
||||
super(mathRegistry, "c_var_description_", mathEntityDao);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@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());
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JBuilder<? extends IConstant> createBuilder(@NotNull Var entity) {
|
||||
return new Var.Builder(entity);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected MathEntityPersistenceContainer<Var> createPersistenceContainer() {
|
||||
return new Vars();
|
||||
}
|
||||
|
||||
private void tryToAddAuxVar(@NotNull String name) {
|
||||
if ( !contains(name) ) {
|
||||
add(new Var.Builder(name, (String)null));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Var transform(@NotNull IConstant entity) {
|
||||
if (entity instanceof Var) {
|
||||
return (Var) entity;
|
||||
} else {
|
||||
return new Var.Builder(entity).create();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(@NotNull String mathEntityName) {
|
||||
final IConstant var = get(mathEntityName);
|
||||
if (var != null && !var.isSystem()) {
|
||||
return var.getDescription();
|
||||
} else {
|
||||
return super.getDescription(mathEntityName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory(@NotNull IConstant var) {
|
||||
for (VarCategory category : VarCategory.values()) {
|
||||
if ( category.isInCategory(var) ) {
|
||||
return category.name();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.math.operator.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.collections.CollectionsUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/7/12
|
||||
* Time: 7:40 PM
|
||||
*/
|
||||
public enum OperatorCategory {
|
||||
|
||||
derivatives(100){
|
||||
@Override
|
||||
public boolean isInCategory(@NotNull Operator operator) {
|
||||
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
|
||||
}
|
||||
},
|
||||
|
||||
other(200) {
|
||||
@Override
|
||||
public boolean isInCategory(@NotNull Operator operator) {
|
||||
return operator instanceof Sum || operator instanceof Product;
|
||||
}
|
||||
},
|
||||
|
||||
my(0) {
|
||||
@Override
|
||||
public boolean isInCategory(@NotNull Operator operator) {
|
||||
return !operator.isSystem();
|
||||
}
|
||||
},
|
||||
|
||||
common(50) {
|
||||
@Override
|
||||
public boolean isInCategory(@NotNull Operator operator) {
|
||||
for (OperatorCategory category : values()) {
|
||||
if ( category != this ) {
|
||||
if ( category.isInCategory(operator) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private final int tabOrder;
|
||||
|
||||
OperatorCategory(int tabOrder) {
|
||||
this.tabOrder = tabOrder;
|
||||
}
|
||||
|
||||
public abstract boolean isInCategory(@NotNull Operator operator);
|
||||
|
||||
@NotNull
|
||||
public static List<OperatorCategory> getCategoriesByTabOrder() {
|
||||
final List<OperatorCategory> result = CollectionsUtils.asList(OperatorCategory.values());
|
||||
|
||||
Collections.sort(result, new Comparator<OperatorCategory>() {
|
||||
@Override
|
||||
public int compare(OperatorCategory category, OperatorCategory category1) {
|
||||
return category.tabOrder - category1.tabOrder;
|
||||
}
|
||||
});
|
||||
|
||||
// todo serso: current solution (as creating operators is not implemented yet)
|
||||
result.remove(my);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.collections.CollectionsUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/22/11
|
||||
* Time: 4:25 PM
|
||||
*/
|
||||
public enum VarCategory {
|
||||
|
||||
system(100){
|
||||
@Override
|
||||
public boolean isInCategory(@NotNull IConstant var) {
|
||||
return var.isSystem();
|
||||
}
|
||||
},
|
||||
|
||||
my(0) {
|
||||
@Override
|
||||
public boolean isInCategory(@NotNull IConstant var) {
|
||||
return !var.isSystem();
|
||||
}
|
||||
};
|
||||
|
||||
private final int tabOrder;
|
||||
|
||||
VarCategory(int tabOrder) {
|
||||
this.tabOrder = tabOrder;
|
||||
}
|
||||
|
||||
public abstract boolean isInCategory(@NotNull IConstant var);
|
||||
|
||||
@NotNull
|
||||
public static List<VarCategory> getCategoriesByTabOrder() {
|
||||
final List<VarCategory> result = CollectionsUtils.asList(VarCategory.values());
|
||||
|
||||
Collections.sort(result, new Comparator<VarCategory>() {
|
||||
@Override
|
||||
public int compare(VarCategory category, VarCategory category1) {
|
||||
return category.tabOrder - category1.tabOrder;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user