name:
src/main/java/io/protobase/f7/utils/Filters.java
-rw-r--r--
1285
1package io.protobase.f7.utils;
2
3public class Filters {
4 /**
5 * Used to filter lists to values that are numeric: they are a Boolean, or a Double.
6 *
7 * @param value - to check
8 * @return - true if value is instance of Double, or Boolean. Otherwise false.
9 */
10 public static boolean isNumeric(Object value) {
11 return value instanceof Double || value instanceof Boolean;
12 }
13
14 /**
15 * Is the value a numeric value (Double or Boolean) or a coercable string?
16 *
17 * @param value - to check
18 * @return - true if value is instance of Double, or Boolean, or is a String that can be converted to Double.
19 */
20 public static boolean isCoercableToNumeric(Object value) {
21 return isNumeric(value) || isCoercableString(value);
22 }
23
24 public static boolean isLiteralNumber(Object value) {
25 return value instanceof Double;
26 }
27
28 /**
29 * Can we coerce this string to a number value?
30 *
31 * @param value - to test.
32 * @return true if we can get a Double from this value.
33 */
34 public static boolean isCoercableString(Object value) {
35 if (value instanceof String) {
36 try {
37 Double.parseDouble(Converters.castAsString(value));
38 return true;
39 } catch (NumberFormatException e) {
40 return false;
41 }
42 }
43 return false;
44 }
45}