Fixes based on code review feedback
This commit is contained in:
parent
abcc39871b
commit
29edeabaae
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 9.0 KiB |
45
dirty-flag/etc/dirty-flag.ucls
Normal file
45
dirty-flag/etc/dirty-flag.ucls
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.2" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<class id="1" language="java" name="com.iluwatar.dirtyflag.App" project="dirty-flag"
|
||||
file="/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="266" y="188"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="2" language="java" name="com.iluwatar.dirtyflag.DataFetcher" project="dirty-flag"
|
||||
file="/dirty-flag/src/main/java/com/iluwatar/dirtyflag/DataFetcher.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="153" width="125" x="66" y="291"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="3" language="java" name="com.iluwatar.dirtyflag.World" project="dirty-flag"
|
||||
file="/dirty-flag/src/main/java/com/iluwatar/dirtyflag/World.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="379" y="366"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<association id="4">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="5" name="df"/>
|
||||
<multiplicity id="6" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</classifier-display>
|
||||
<association-display labels="true" multiplicity="true"/>
|
||||
</class-diagram>
|
@ -5,11 +5,11 @@
|
||||
<parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<version>1.19.0-SNAPSHOT</version>
|
||||
<version>1.20.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>dirty-flag</artifactId>
|
||||
<version>1.19.0-SNAPSHOT</version>
|
||||
<version>1.20.0-SNAPSHOT</version>
|
||||
<name>dirty-flag</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -24,10 +24,8 @@ package org.dirty.flag;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.iluwatar.dirtyflag.DataFetcher;
|
||||
@ -39,23 +37,16 @@ import com.iluwatar.dirtyflag.DataFetcher;
|
||||
*/
|
||||
public class DirtyFlagTest {
|
||||
|
||||
@BeforeEach
|
||||
public void reset() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
|
||||
Field instance = DataFetcher.class.getDeclaredField("df");
|
||||
instance.setAccessible(true);
|
||||
instance.set(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDirty() {
|
||||
DataFetcher df = DataFetcher.getInstance();
|
||||
DataFetcher df = new DataFetcher();
|
||||
List<String> countries = df.fetch();
|
||||
assertTrue(!countries.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotDirty() {
|
||||
DataFetcher df = DataFetcher.getInstance();
|
||||
DataFetcher df = new DataFetcher();
|
||||
df.fetch();
|
||||
List<String> countries = df.fetch();
|
||||
assertTrue(countries == null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user