org.xson.web.util.NumberUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xco-web Show documentation
Show all versions of xco-web Show documentation
xco-web is an easy to use control layer framework, is part of the SOA system, using xml language to describe the controller.
The newest version!
package org.xson.web.util;
import java.util.regex.Pattern;
public class NumberUtils {
public static boolean isNumber(String var) {
return var.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
}
public static boolean isInteger(String var) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(var).matches();
}
public static Object parseNumber(String var) {
Object value = null;
if (var.indexOf(".") == -1) {
try {
value = Integer.parseInt(var);
} catch (NumberFormatException e) {
value = Long.parseLong(var);
}
} else {
try {
value = Float.parseFloat(var);
} catch (NumberFormatException e) {
value = Double.parseDouble(var);
}
}
return value;
}
public static boolean randomSuccess() {
int x = (int) (Math.random() * 100);
return x > 10;
}
public static boolean randomFailure() {
return !randomSuccess();
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println(randomSuccess());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy