My Java programm produces a lot of data, with wich I construct individual ResultObject. Because only certain ResultsObjects will be of interest, I populate an ObservableHashMap<> with my results. The CustomObject consists of a handful ints + doubles and one JSONObject. With this CustomObject I want to map similar ResultObjects(which have certain properties in common) to that one CustomObject.
While mapping and handling those results works as intended, I am pretty much helpless to populate a TableView with that ObservableHashMap<>.
My CustomObject (JSONObject simply to check, if two CustomObjects have the same properties):
public CustomObject(Simulation data) {
this.datapoint1 = data.datapoint1;
this.datapoint2 = data.datapoint2;
this.jsonCompareObject = new JSONObject()
.put("datapoint1", data.datapoint1)
.put("datapoint1", data.datapoint2);
}
My ObservableHashMap Object:
private ObservableMap <CustomObject, ObservableList<Simulation>> topResultsList;
public SomeObjectWithObservableMap(){
this.topResultsList = FXCollections.observableHashMap();
}
By using the following code, I check if there is a key with the corresponding datapoints already present to then add to its ObservableList (Value):
private boolean isKeyPresent(CustomObject newCustomObject, Simulation data) {
for (CustomObject oldCustomObject : this.topResultsList.keySet()) {
if (oldCustomObject.jsonCompareObject.toString().equals(newCustomObject.jsonCompareObject.toString())) {
this.topResultsList.get(oldCustomObject).add(data);
return true;
}
}
return false;
}
I populate some other TableView like this:
{
tableColumn.setCellValueFactory(new PropertyValueFactory<>("datapoint1"));
tableColumn.setCellFactory(TextFieldTableCell.<SomeObject, Double>forTableColumn(twoDigits));
tableView.setItems(someObject.getObservableList());
}
In the end I want some TableColumns to show properties from the CustomObject. Later on, I would want the individual mapped ObservableLists of a selected CustomObject to be shown in a seperate TableView.
I am pretty new to Java and JavaFX and I hope to have described my problem as professional as possible. Please let me know, if I missed anything.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…