This commit is contained in:
madwasp79 2019-02-27 13:00:41 +02:00
parent f2d5e56ec8
commit cf74e1fd7d

View file

@ -599,7 +599,8 @@ public class Algorithms {
public static boolean isInt(String value) {
for (int i = 0; i < value.length(); i++) {
if (!Character.isDigit(value.charAt(i))) {
if ((i == 0 && value.charAt(i) != '-') || (value.length() == 1 && value.charAt(i) == '-') || i > 0 ) {
if ((i == 0 && value.charAt(i) != '-') || (value.length() == 1
&& value.charAt(i) == '-') || i > 0) {
return false;
}
}
@ -608,10 +609,28 @@ public class Algorithms {
}
public static boolean isFloat(String value) {
return value.matches("[-+]?[0-9]*\\.?[0-9]+");
int pointsCount = 0;
int length = value.length();
for (int i = 0; i < length; i++) {
if (!Character.isDigit(value.charAt(i))) {
if (length < 2) {
return false;
}
if (!(value.charAt(i) == '-' || value.charAt(i) == '.')) {
return false;
} else if (value.charAt(i) == '-' && i != 0) {
return false;
} else if ((value.charAt(i) == '.' && pointsCount >= 1) || (value.charAt(i) == '.'
&& i == length - 1)) {
return false;
} else if (value.charAt(i) == '.') {
pointsCount++;
}
}
}
return pointsCount == 1;
}
public static String formatDuration(int seconds, boolean fullForm) {
String sec;
if (seconds % 60 < 10) {