Android project initiated

This commit is contained in:
serso
2011-06-24 01:09:13 +04:00
commit 7d66404d00
61 changed files with 1164 additions and 0 deletions

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

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

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

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

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

View 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 + "]";
}
}