Code duplicationDuplicated string literals in FXMLController.initialize
You're duplicating the names used by the enums:
propertyTypeList.addAll("String", "Integer", "Boolean", "Double",
"Float", "Long");
This is not good. As usual, if you make a change in one place, you have to remember to make the same change at the other too. It's fragile.
It would be better to iterate over the values of the enum, for example:
for (JavaDataType javaDataType : JavaDataType.values()) {
propertyTypeList.add(javaDataType.toString());
}
Or if you fancy Java 8:
propertyTypeList.addAll(Arrays.asList(JavaDataType.values()).stream()
.map(JavaDataType::toString)
.collect(Collectors.toList()));
Code duplicationDuplicated string literals in JavaDataType.fromString
Similar to the earlier point,
it's a pity to duplicate the string values of the enums in the case
statements.
Better build a static map from them and use it, without duplicating anything.
private static final Map<String, JavaDataType> STRING_TO_ENUM = new HashMap<>();
static {
for (JavaDataType javaDataType : values()) {
STRING_TO_ENUM.put(javaDataType.toString(), javaDataType);
}
}
public static JavaDataType fromString(String type) {
return STRING_TO_ENUM.get(type);
}
Hardcoded Java class names
Still about JavaDataType
...
Instead of hardcoding the class names of String
, Double
, ...,
how about using the real class types instead?
STRING(String.class),
INTEGER(Integer.class),
BOOLEAN(Boolean.class),
DOUBLE(Double.class),
FLOAT(Float.class),
LONG(Long.class);
private final String value;
JavaDataType(Class<?> klass) {
this.value = klass.getSimpleName();
}
Minor things
This javadoc comment is really pointless, especially on a private field:
/**
* String value
*/
private final String value;
to be continued...
TTGTB, will continue tomorrow morning, probably, unless others finish up first...