I have a predefined list of phone numbers to block in my application, the list is being created based on a file input in PhoneListFilter constructor.
I need to be able to add and remove items from this list without restarting the application. I was thinking about implementing FileWatcher which could start a thread and check the file for any changes every 5 minutes or so and update the list. Is it a good approach or should I do it differently?
PhoneListFilter.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class PhoneListFilter {
private List<String> phoneList;
public PhoneListFilter() {
phoneList = new ArrayList<>();
try {
Scanner s = new Scanner(new File("PhonesToBlockList"));
while (s.hasNext()) {
phoneList.add(s.next());
}
s.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
public boolean shouldBlock(PhoneRequest phoneRequest) {
if (phoneList.contains(phoneRequest.getPhoneNumber())) {
return true;
}
return false;
}
}