Fixes based on code review feedback
This commit is contained in:
@ -57,7 +57,7 @@ public class App {
|
||||
executorService.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
World world = World.getInstance();
|
||||
World world = new World();
|
||||
List<String> countries = world.fetch();
|
||||
System.out.println("Our world currently has the following countries:-");
|
||||
for (String country : countries) {
|
||||
|
@ -15,23 +15,11 @@ import java.util.List;
|
||||
*/
|
||||
public class DataFetcher {
|
||||
|
||||
private static DataFetcher df;
|
||||
private final String filename = "world.txt";
|
||||
private long lastFetched = -1;
|
||||
private long lastFetched;
|
||||
|
||||
private DataFetcher() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*
|
||||
* @return DataFetcher instance
|
||||
*/
|
||||
public static DataFetcher getInstance() {
|
||||
if (df == null) {
|
||||
df = new DataFetcher();
|
||||
}
|
||||
return df;
|
||||
public DataFetcher() {
|
||||
this.lastFetched = -1;
|
||||
}
|
||||
|
||||
private boolean isDirty(long fileLastModified) {
|
||||
@ -66,6 +54,6 @@ public class DataFetcher {
|
||||
return data;
|
||||
}
|
||||
|
||||
return null;
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
|
@ -12,22 +12,12 @@ import java.util.List;
|
||||
*/
|
||||
public class World {
|
||||
|
||||
private static World world;
|
||||
private static List<String> countries = new ArrayList<String>();
|
||||
private List<String> countries;
|
||||
private DataFetcher df;
|
||||
|
||||
private World() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*
|
||||
* @return World instance
|
||||
*/
|
||||
public static World getInstance() {
|
||||
if (world == null) {
|
||||
world = new World();
|
||||
}
|
||||
return world;
|
||||
public World() {
|
||||
this.countries = new ArrayList<String>();
|
||||
this.df = new DataFetcher();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,10 +27,9 @@ public class World {
|
||||
* @return List of strings
|
||||
*/
|
||||
public List<String> fetch() {
|
||||
DataFetcher df = DataFetcher.getInstance();
|
||||
List<String> data = df.fetch();
|
||||
|
||||
countries = data == null ? countries : data;
|
||||
countries = data.isEmpty() ? countries : data;
|
||||
|
||||
return countries;
|
||||
}
|
||||
|
Reference in New Issue
Block a user