diff --git a/src/com/olexyn/ensync/Flow.java b/src/com/olexyn/ensync/Flow.java index 68a7a97..7dea000 100644 --- a/src/com/olexyn/ensync/Flow.java +++ b/src/com/olexyn/ensync/Flow.java @@ -17,31 +17,18 @@ public class Flow implements Runnable{ + initialize(); - for (Map.Entry mapEntry : Main.sync.syncMaps.entrySet()) { - SyncMap syncMap = mapEntry.getValue(); - state = syncMap.toString(); - - for (Map.Entry entry : syncMap.syncDirectories.entrySet()) { - SyncDirectory syncDirectory = entry.getValue(); - String path = syncDirectory.path; - String stateFilePath = syncDirectory.stateFilePath(path); - if (new File(stateFilePath).exists()) { - state = "READ-STATE-FILE-"+ - syncDirectory.readStateFile(); - } else { - syncDirectory.writeStateFile(path); - } - } + for (var syncMapEntry : Main.SYNC.entrySet()) { while (true) { - for (Map.Entry entry : mapEntry.getValue().syncDirectories.entrySet()) { + for (var syncDirectoryEntry : syncMapEntry.getValue().syncDirectories.entrySet()) { - SyncDirectory syncDirectory = entry.getValue(); + SyncDirectory syncDirectory = syncDirectoryEntry.getValue(); String path = syncDirectory.path; @@ -56,18 +43,14 @@ public class Flow implements Runnable{ syncDirectory.doDelete(); syncDirectory.doModify(); - syncDirectory.writeStateFile(path); - - - } try { System.out.println("Pausing..."); - Main.flowThread.sleep(2000); - } catch (InterruptedException e) { + Thread.sleep(2000); + } catch (InterruptedException ignored) { } } @@ -78,4 +61,29 @@ public class Flow implements Runnable{ public String getState() { return state==null ? "NONE" : state; } + + + /** + * For every single SyncDirectory try to read it's StateFile.

+ * If the StateFile is missing, then create a StateFile. + */ + private void initialize(){ + for (var syncMapEntry : Main.SYNC.entrySet()) { + SyncMap syncMap = syncMapEntry.getValue(); + state = syncMap.toString(); + + for (var stringSyncDirectoryEntry : syncMap.syncDirectories.entrySet()) { + SyncDirectory syncDirectory = stringSyncDirectoryEntry.getValue(); + String path = syncDirectory.path; + String stateFilePath = syncDirectory.stateFilePath(path); + + if (new File(stateFilePath).exists()) { + state = "READ-STATE-FILE-" + syncDirectory.readStateFile(); + } else { + syncDirectory.writeStateFile(path); + } + } + + } + } } diff --git a/src/com/olexyn/ensync/Main.java b/src/com/olexyn/ensync/Main.java index a33e784..18a033c 100644 --- a/src/com/olexyn/ensync/Main.java +++ b/src/com/olexyn/ensync/Main.java @@ -1,26 +1,16 @@ package com.olexyn.ensync; -import com.olexyn.ensync.artifacts.Sync; import com.olexyn.ensync.artifacts.SyncMap; import com.olexyn.ensync.ui.UI; -import javafx.application.Application; -import javafx.collections.ObservableList; -import javafx.fxml.FXMLLoader; -import javafx.scene.Node; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.TextField; -import javafx.scene.layout.AnchorPane; -import javafx.stage.Stage; -import javafx.stage.Window; + +import java.util.HashMap; +import java.util.Map; public class Main{ - final public static Sync sync = new Sync(); @@ -28,13 +18,13 @@ public class Main{ final public static Thread flowThread = new Thread(new Flow(), "flow"); - + final public static Map SYNC = new HashMap<>(); public static void main(String[] args) { - sync.syncMaps.put("test", new SyncMap("test")); + SYNC.put("test", new SyncMap("test")); diff --git a/src/com/olexyn/ensync/artifacts/Sync.java b/src/com/olexyn/ensync/artifacts/Sync.java deleted file mode 100644 index 08caaee..0000000 --- a/src/com/olexyn/ensync/artifacts/Sync.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.olexyn.ensync.artifacts; - -import java.util.HashMap; -import java.util.Map; - -public class Sync { - - - - public Map syncMaps = new HashMap<>(); -} diff --git a/src/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/com/olexyn/ensync/artifacts/SyncDirectory.java index 6f9bec9..a22818b 100644 --- a/src/com/olexyn/ensync/artifacts/SyncDirectory.java +++ b/src/com/olexyn/ensync/artifacts/SyncDirectory.java @@ -111,7 +111,6 @@ public class SyncDirectory { * Compare the OLD and NEW pools. * List is cleared and created each time. * - * @return */ public void makeListDeleted() { listDeleted = new ArrayList<>(); @@ -127,7 +126,6 @@ public class SyncDirectory { * Compare the OLD and NEW pools. * List is cleared and created each time. * - * @return */ public void makeListModified() { diff --git a/src/com/olexyn/ensync/artifacts/SyncMap.java b/src/com/olexyn/ensync/artifacts/SyncMap.java index c201aee..e016516 100644 --- a/src/com/olexyn/ensync/artifacts/SyncMap.java +++ b/src/com/olexyn/ensync/artifacts/SyncMap.java @@ -8,8 +8,9 @@ import java.util.HashMap; import java.util.Map; /** - * A SyncMap is a collection of SyncDirectories, - * that are supposed to be kept in sync. + * What is a SyncMap? + * A SyncDirectory is an occurrence of a particular directory somewhere across the filesystems. + * A SyncMap is the set of such SyncDirectories. The purpose of the SyncMap is to help syncronize the SyncDirectories. */ public class SyncMap { @@ -27,11 +28,10 @@ public class SyncMap { } /** - * Creates a new Syncdirectory. - *

+ * Creates a new Syncdirectory.

* Adds the created SyncDirectory to this SyncMap. * - * @param realPath the path from which the Syncdirectory is created. + * @param realPath the path from which the SyncDirectory is created. * @see SyncDirectory */ public void addDirectory(String realPath) { @@ -45,8 +45,4 @@ public class SyncMap { } - - - - } diff --git a/src/com/olexyn/ensync/ui/Controller.java b/src/com/olexyn/ensync/ui/Controller.java index 0b5b578..3fbf0fe 100644 --- a/src/com/olexyn/ensync/ui/Controller.java +++ b/src/com/olexyn/ensync/ui/Controller.java @@ -64,7 +64,7 @@ public class Controller implements Initializable { pathTextField.setDisable(true); // TODO for now there is only one SyncMap "test". - Main.sync.syncMaps.get("test").addDirectory(dir.getAbsolutePath()); + Main.SYNC.get("test").addDirectory(dir.getAbsolutePath()); TextField stateTextField = new TextField(); stateTextField.setText("STATE"); @@ -161,7 +161,7 @@ public class Controller implements Initializable { try { Main.flowThread.wait(); } catch (InterruptedException e){ - Main.sync.syncMaps.get("test").removeDirectory(path); + Main.SYNC.get("test").removeDirectory(path); Main.flowThread.notify(); break; }