MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / toNumber

Method toNumber

src/main/java/field/utility/Options.java:101–122  ·  view source on GitHub ↗

checks to see if this can be made an Integer, a Long, a Float, or a Double (in that order) returns null on failure; We often want Number representations of command line things rather than string representations

(Object s)

Source from the content-addressed store, hash-verified

99 * We often want Number representations of command line things rather than string representations
100 */
101 static public Number toNumber(Object s) {
102 if (s instanceof Number) return ((Number) s);
103 if (s instanceof Boolean) return ((Boolean) s).booleanValue() ? 1 : 0;
104 try {
105 return Integer.parseInt("" + s);
106 } catch (NumberFormatException e) {
107 try {
108 return Long.parseLong("" + s);
109 } catch (NumberFormatException e2) {
110 try {
111
112 return Float.parseFloat("" + s);
113 } catch (NumberFormatException e3) {
114 try {
115 return Double.parseDouble("" + s);
116 } catch (NumberFormatException e4) {
117 return null;
118 }
119 }
120 }
121 }
122 }
123
124 private static boolean isValidIdentifier(String x) {
125 if (x.length() == 0) return false;

Callers 1

parseCommandLineMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected