Android project initiated
This commit is contained in:
17
src/org/solovyev/util/StringUtils.java
Normal file
17
src/org/solovyev/util/StringUtils.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.solovyev.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public static boolean isEmpty ( @Nullable String s ){
|
||||
return s == null || s.length() == 0;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getNotEmpty ( @Nullable String s, @NotNull String defaultValue ){
|
||||
return isEmpty(s) ? defaultValue : s;
|
||||
}
|
||||
}
|
||||
|
||||
11
src/org/solovyev/util/date/DateUtils.java
Normal file
11
src/org/solovyev/util/date/DateUtils.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package org.solovyev.util.date;
|
||||
|
||||
public class DateUtils {
|
||||
|
||||
public static long MS_IN_SECONDS = 1000l;
|
||||
|
||||
public static long msToSeconds (long ms) {
|
||||
return ms / 1000l;
|
||||
}
|
||||
|
||||
}
|
||||
37
src/org/solovyev/util/math/MathEntity.java
Normal file
37
src/org/solovyev/util/math/MathEntity.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package org.solovyev.util.math;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum MathEntity {
|
||||
|
||||
minus("-"),
|
||||
equals("="),
|
||||
factorial("!"),
|
||||
plus("+"),
|
||||
multiply("*"),
|
||||
divide("/"),
|
||||
power("^"),
|
||||
sin("sin"),
|
||||
asin("asin"),
|
||||
cos("cos"),
|
||||
acos("acos"),
|
||||
tg("tg"),
|
||||
atg("atg"),
|
||||
exp("exp"),
|
||||
log("log"),
|
||||
ln("ln"),
|
||||
mod("mod"),
|
||||
sqrt("sqrt");
|
||||
|
||||
@NotNull
|
||||
private final String text;
|
||||
|
||||
private MathEntity (@NotNull String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
57
src/org/solovyev/util/math/MathEntityType.java
Normal file
57
src/org/solovyev/util/math/MathEntityType.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package org.solovyev.util.math;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum MathEntityType {
|
||||
|
||||
digit,
|
||||
function,
|
||||
unary_operation,
|
||||
binary_operation,
|
||||
group_symbols,
|
||||
group_symbol;
|
||||
|
||||
private static final List<Character> unaryOperations = Arrays.asList('-', '=', '!');
|
||||
|
||||
private static final List<Character> binaryOperations = Arrays.asList('-', '+', '*', '/', '^' );
|
||||
|
||||
private static final List<String> functions = Arrays.asList("sin", "asin", "cos", "acos", "tg", "atg", "exp", "log", "ln", "mod", "sqrt");
|
||||
|
||||
private static final List<String> groupSymbols = Arrays.asList("[]", "()", "{}");
|
||||
|
||||
private static final List<Character> singleGroupSymbols = Arrays.asList('[', ']', '(', ')', '{', '}');
|
||||
|
||||
@Nullable
|
||||
public static MathEntityType getType( @NotNull String s ) {
|
||||
MathEntityType result = null;
|
||||
|
||||
if ( s.length() == 1 ) {
|
||||
char ch = s.charAt(0);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if ( result == null ) {
|
||||
if ( functions.contains(s) ) {
|
||||
result = MathEntityType.function;
|
||||
} else if ( groupSymbols.contains(s) ) {
|
||||
result = MathEntityType.group_symbols;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
39
src/org/solovyev/util/math/MathUtils.java
Normal file
39
src/org/solovyev/util/math/MathUtils.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.solovyev.util.math;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MathUtils {
|
||||
|
||||
public static float getDistance(@NotNull Point2d startPoint,
|
||||
@NotNull Point2d endPoint) {
|
||||
return getNorm(subtract(endPoint, startPoint));
|
||||
}
|
||||
|
||||
public static Point2d subtract(@NotNull Point2d p1, @NotNull Point2d p2) {
|
||||
return new Point2d(p1.getX() - p2.getX(), p1.getY() - p2.getY());
|
||||
}
|
||||
|
||||
public static Point2d sum(@NotNull Point2d p1, @NotNull Point2d p2) {
|
||||
return new Point2d(p1.getX() + p2.getX(), p1.getY() + p2.getY());
|
||||
}
|
||||
|
||||
public static float getNorm(@NotNull Point2d point) {
|
||||
return (float) Math.pow(
|
||||
Math.pow(point.getX(), 2) + Math.pow(point.getY(), 2), 0.5);
|
||||
}
|
||||
|
||||
public static float getAngle(@NotNull Point2d startPoint,
|
||||
@NotNull Point2d axisEndPoint, @NotNull Point2d endPoint) {
|
||||
final Point2d axisVector = subtract(axisEndPoint, startPoint);
|
||||
final Point2d vector = subtract(endPoint, startPoint);
|
||||
|
||||
double a_2 = Math.pow(getDistance(vector, axisVector), 2);
|
||||
double b = getNorm(vector);
|
||||
double b_2 = Math.pow(b, 2);
|
||||
double c = getNorm(axisVector);
|
||||
double c_2 = Math.pow(c, 2);
|
||||
|
||||
return (float) Math.acos((-a_2 + b_2 + c_2) / (2 * b * c));
|
||||
}
|
||||
|
||||
}
|
||||
37
src/org/solovyev/util/math/Point2d.java
Normal file
37
src/org/solovyev/util/math/Point2d.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package org.solovyev.util.math;
|
||||
|
||||
public class Point2d {
|
||||
|
||||
private float x = 0;
|
||||
|
||||
private float y = 0;
|
||||
|
||||
public Point2d() {
|
||||
}
|
||||
|
||||
public Point2d( float x, float y ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point2d [x=" + x + ", y=" + y + "]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user