AtomicReference<ObservableList<Person>> data = new AtomicReference<>
(FXCollections.observableArrayList(person ->
new Observable[]{
person.firstNameProperty(),
person.lastNameProperty(),
person.emailProperty(),
}));
Здесь начинается условие List
ObservableList<String> options =
FXCollections.observableArrayList(
"Save Last Names: A to C",
"Save Last Names: D to H",
"Save Last Names I to Z",
"Save All Friends"
);
final ComboBox comboBox = new ComboBox(options);
Button saveFile = new Button("Save File");
saveFile.setOnAction(e -> {
if ("Save Last Names: A to C" == comboBox.getValue()) {
ObservableList<Person> myList = persons.getItems();
try {
for (Person p: myList){
String lastName = p.getLastName();
char start = lastName.charAt(0);
if (start >= 'A' && start <= 'C' ){
p.writeToTextFile("FriendsA-C.txt", data.get());
}
}
System.out.println("Sucessfully wrote to file, named \"FriendsA-C.txt\"");
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (("Save Last Names: D to H")== comboBox.getValue()) {
ObservableList<Person> myList1 = persons.getItems();
try {
for (Person p : myList1) {
String lastName = p.getLastName();
char start = lastName.charAt(0);
if (start >= 'D' && start <= 'H' ) {
p.writeToTextFile("FriendsD-H.txt", data.get());
}
}
System.out.println("Sucessfully wrote to file, named \"FriendsD-H.txt\"");
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (("Save Last Names I to Z")== comboBox.getValue()) {
ObservableList<Person> myList2 = persons.getItems();
try {
for (Person p : myList2) {
String lastName = p.getLastName();
char start = lastName.charAt(0);
if (start >= 'A' && start <= 'C' ) {
p.writeToTextFile("FriendsI-Z.txt", data.get());
}
}
System.out.println("Sucessfully wrote to file, named \"FriendsI-Z.txt\"");
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (("Save All Friends").equals(comboBox.getValue())) {
ObservableList<Person> myList3 = persons.getItems();
try {
for (Person p: myList3) {
p.writeToTextFile("Friends.txt", data.get());
}
System.out.println("Sucessfully wrote to file, named \"Friends.txt\"");
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
saveFile.disableProperty().bind(comboBox.valueProperty().isNull());
В этом коде нет ошибок, но он не выполняется должным образом. Я гуглил некоторые предикаты, но не уверен, как их использовать: stream.filter()
или filtered()
.
Большое спасибо.