refactor
This commit is contained in:
@@ -15,23 +15,26 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class Complex {
|
||||
|
||||
@Nullable
|
||||
private String real, imag;
|
||||
private Double real;
|
||||
|
||||
@Nullable
|
||||
public String getReal() {
|
||||
private Double imaginary;
|
||||
|
||||
@Nullable
|
||||
public Double getReal() {
|
||||
return real;
|
||||
}
|
||||
|
||||
public void setReal(@Nullable String real) {
|
||||
public void setReal(@Nullable Double real) {
|
||||
this.real = real;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getImag() {
|
||||
return imag;
|
||||
public Double getImaginary() {
|
||||
return imaginary;
|
||||
}
|
||||
|
||||
public void setImag(@Nullable String imag) {
|
||||
this.imag = imag;
|
||||
public void setImaginary(@Nullable Double imaginary) {
|
||||
this.imaginary = imaginary;
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.util.math;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/17/11
|
||||
* Time: 10:01 PM
|
||||
*/
|
||||
public interface Functions {
|
||||
|
||||
String SIN = "sin";
|
||||
String SINH = "sinh";
|
||||
String ASIN = "asin";
|
||||
String ASINH = "asinh";
|
||||
String COS = "cos";
|
||||
String COSH = "cosh";
|
||||
String ACOS = "acos";
|
||||
String ACOSH = "acosh";
|
||||
String TAN = "tan";
|
||||
String TANH = "tanh";
|
||||
String ATAN = "atan";
|
||||
String ATANH = "atanh";
|
||||
String LOG = "log";
|
||||
String LN = "ln";
|
||||
String MOD = "mod";
|
||||
String EXP = "exp";
|
||||
String SQRT_SIGN = "√";
|
||||
String SQRT = "sqrt";
|
||||
|
||||
public static final List<String> all = Arrays.asList(SIN, SINH, ASIN, ASINH, COS, COSH, ACOS, ACOSH, TAN, TANH, ATAN, ATANH, LOG, LN, MOD, SQRT, SQRT_SIGN, EXP);
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.util.math;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum MathEntityType {
|
||||
|
||||
digit,
|
||||
constant,
|
||||
dot,
|
||||
function,
|
||||
unary_operation,
|
||||
binary_operation,
|
||||
group_symbols,
|
||||
group_symbol;
|
||||
|
||||
public static final List<Character> constants = Arrays.asList('e', 'π', 'i');
|
||||
|
||||
public static final List<Character> dots = Arrays.asList('.', ',');
|
||||
|
||||
public static final List<Character> unaryOperations = Arrays.asList('-', '=', '!');
|
||||
|
||||
public static final List<Character> binaryOperations = Arrays.asList('-', '+', '*', '×', '∙', '/', '^' );
|
||||
|
||||
public static final List<String> functions = Functions.all;
|
||||
|
||||
public static final List<String> groupSymbols = Arrays.asList("[]", "()", "{}");
|
||||
|
||||
public static final List<Character> openGroupSymbols = Arrays.asList('[', '(', '{');
|
||||
|
||||
public static final List<Character> closeGroupSymbols = Arrays.asList(']', ')', '}');
|
||||
|
||||
public static final List<Character> singleGroupSymbols;
|
||||
static {
|
||||
final List<Character> list = new ArrayList<Character>();
|
||||
list.addAll(openGroupSymbols);
|
||||
list.addAll(closeGroupSymbols);
|
||||
singleGroupSymbols = Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MathEntityType getType( @NotNull String s ) {
|
||||
MathEntityType result = null;
|
||||
|
||||
if ( s.length() == 1 ) {
|
||||
result = getType(s.charAt(0));
|
||||
}
|
||||
|
||||
if ( result == null ) {
|
||||
if ( functions.contains(s) ) {
|
||||
result = MathEntityType.function;
|
||||
} else if ( groupSymbols.contains(s) ) {
|
||||
result = MathEntityType.group_symbols;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MathEntityType getType(char ch) {
|
||||
MathEntityType result = null;
|
||||
|
||||
if ( Character.isDigit(ch) ) {
|
||||
result = MathEntityType.digit;
|
||||
} else if ( unaryOperations.contains(ch) ) {
|
||||
result = MathEntityType.unary_operation;
|
||||
} else if ( binaryOperations.contains(ch) ) {
|
||||
result = MathEntityType.binary_operation;
|
||||
} else if ( singleGroupSymbols.contains(ch) ) {
|
||||
result = MathEntityType.group_symbol;
|
||||
} else if ( constants.contains(ch) ) {
|
||||
result = MathEntityType.constant;
|
||||
} else if ( dots.contains(ch) ) {
|
||||
result = MathEntityType.dot;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user