40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
package at.ionas999.adressbook.repository;
|
|
|
|
import at.ionas999.adressbook.models.Contact;
|
|
import javafx.beans.property.SimpleIntegerProperty;
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.ObservableList;
|
|
|
|
public class AddressBook {
|
|
private static AddressBook instance;
|
|
private ObservableList<Contact> list;
|
|
|
|
private AddressBook() {
|
|
list = FXCollections.observableArrayList();
|
|
}
|
|
|
|
public static AddressBook getInstance() {
|
|
if (AddressBook.instance == null) {
|
|
AddressBook.instance = new AddressBook();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public ObservableList<Contact> getContacts() {
|
|
return FXCollections.unmodifiableObservableList(list);
|
|
}
|
|
|
|
public void addContact(Contact contact) {
|
|
list.add(contact);
|
|
}
|
|
|
|
public void removeContact(Contact contact) {
|
|
list.remove(contact);
|
|
}
|
|
|
|
public SimpleIntegerProperty getAmount() {
|
|
SimpleIntegerProperty amount = new SimpleIntegerProperty();
|
|
amount.bind(javafx.beans.binding.Bindings.size(list));
|
|
return amount;
|
|
}
|
|
} |