Konečný kód je
public ArrayList<Text> getAllFields() {
return Arrays.stream(getClass().getDeclaredFields())
.filter(field -> !Modifier.isStatic(field.getModifiers()))
.map(this::getFieldValue)
.filter(field -> !field.isEmpty())
.map(field -> new Text(field))
.collect(Collectors.toCollection(ArrayList::new));
}
private String getFieldValue(final Field field) {
try {
if (field.get(this) == null) {
return "";
}
String value = field.get(this).toString();
if (value.matches("-?\\d+")) {
return field.getName() + " " + value;
} else if (value.equals(NAME)) {
return value;
} else {
return "";
}
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
}
}
S null to nijak nepůjde, NAME je field objektu a pro vypsání pod sebou, je nejlepší použít javafx.scene.layout.VBox. Ten však String nevezme. Proto je nutné to přetypovat na javafx.scene.text.Text.