*/
public enum StandardAttributeType {
BOOLEAN(Boolean.class, new BooleanFormatter()), //
- // TODO Also support INTEGER ?
+ INTEGER(Integer.class, new IntegerFormatter()), //
LONG(Long.class, new LongFormatter()), //
DOUBLE(Double.class, new DoubleFormatter()), //
+ // we do not support short and float, like recent additions to Java
+ // (e.g. optional primitives)
INSTANT(Instant.class, new InstantFormatter()), //
UUID(UUID.class, new UuidFormatter()), //
URI(URI.class, new UriFormatter()), //
public static Object parse(String str) {
if (str == null)
- return null;
+ throw new IllegalArgumentException("String cannot be null");
// order IS important
try {
if (str.length() == 4 || str.length() == 5)
} catch (IllegalArgumentException e) {
// silent
}
+ try {
+ return INTEGER.getFormatter().parse(str);
+ } catch (IllegalArgumentException e) {
+ // silent
+ }
try {
return LONG.getFormatter().parse(str);
} catch (IllegalArgumentException e) {
return STRING.getFormatter().parse(str);
}
- static class StringFormatter implements AttributeFormatter<String> {
-
- @Override
- public String parse(String str) {
- return str;
- }
-
- @Override
- public String format(String obj) {
- return obj;
- }
-
- }
-
static class BooleanFormatter implements AttributeFormatter<Boolean> {
/**
}
}
+ static class IntegerFormatter implements AttributeFormatter<Integer> {
+ @Override
+ public Integer parse(String str) throws NumberFormatException {
+ return Integer.parseInt(str);
+ }
+ }
+
static class LongFormatter implements AttributeFormatter<Long> {
@Override
public Long parse(String str) throws NumberFormatException {
}
}
+
+ static class StringFormatter implements AttributeFormatter<String> {
+
+ @Override
+ public String parse(String str) {
+ return str;
+ }
+
+ @Override
+ public String format(String obj) {
+ return obj;
+ }
+
+ }
+
}