From 6942061f70a0377d9d9310ec329a16551a04ae80 Mon Sep 17 00:00:00 2001 From: Ivan Olexyn Date: Mon, 21 Dec 2020 00:05:00 +0100 Subject: [PATCH] ready to launch --- src/main/java/com/olexyn/ensync/App.java | 13 ----- src/main/java/com/olexyn/ensync/Flow.java | 51 +++++++++---------- src/main/java/com/olexyn/ensync/Main.java | 25 --------- .../ensync/artifacts/SyncDirectory.java | 10 +--- .../com/olexyn/ensync/artifacts/SyncFile.java | 20 ++------ .../com/olexyn/ensync/artifacts/SyncMap.java | 3 +- src/main/java/com/olexyn/ensync/ui/UI.java | 14 +---- .../ensync/ui => resources/fxml}/layout.fxml | 0 8 files changed, 34 insertions(+), 102 deletions(-) delete mode 100644 src/main/java/com/olexyn/ensync/App.java rename src/main/{java/com/olexyn/ensync/ui => resources/fxml}/layout.fxml (100%) diff --git a/src/main/java/com/olexyn/ensync/App.java b/src/main/java/com/olexyn/ensync/App.java deleted file mode 100644 index c659c27..0000000 --- a/src/main/java/com/olexyn/ensync/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.olexyn.ensync; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/src/main/java/com/olexyn/ensync/Flow.java b/src/main/java/com/olexyn/ensync/Flow.java index 1c06c65..1ff7fa2 100644 --- a/src/main/java/com/olexyn/ensync/Flow.java +++ b/src/main/java/com/olexyn/ensync/Flow.java @@ -4,6 +4,9 @@ import com.olexyn.ensync.artifacts.SyncDirectory; import com.olexyn.ensync.artifacts.SyncMap; import java.io.File; +import java.util.Map; +import java.util.Map.Entry; + import static com.olexyn.ensync.Main.MAP_OF_SYNCMAPS; public class Flow implements Runnable { @@ -17,48 +20,42 @@ public class Flow implements Runnable { public void run() { - while (true) { - synchronized (MAP_OF_SYNCMAPS) { - readOrMakeStateFile(); - - for (var syncMapEntry : MAP_OF_SYNCMAPS.entrySet()) { + readOrMakeStateFile(); - for (var SDEntry : syncMapEntry.getValue().syncDirectories.entrySet()) { - - SyncDirectory SD = SDEntry.getValue(); - - state = "READ"; - SD.readFreshState(); - - SD.listCreated = SD.makeListCreated(); - SD.listDeleted = SD.makeListDeleted(); - SD.listModified = SD.makeListModified(); + for (Entry syncMapEntry : MAP_OF_SYNCMAPS.entrySet()) { - SD.doCreate(); - SD.doDelete(); - SD.doModify(); + for (Entry SDEntry : syncMapEntry.getValue().syncDirectories.entrySet()) { - SD.writeStateFile(SD.path); + doSyncDirectory(SDEntry.getValue()); } - - } } - - try { long pause = 2000; - System.out.println("Pausing... for "+pause+ "ms."); + System.out.println("Pausing... for " + pause + "ms."); Thread.sleep(pause); - } catch (InterruptedException ignored) { + } catch (InterruptedException ignored) {} + } + } - } - } + private void doSyncDirectory(SyncDirectory SD) { + state = "READ"; + SD.readFreshState(); + + SD.listCreated = SD.makeListCreated(); + SD.listDeleted = SD.makeListDeleted(); + SD.listModified = SD.makeListModified(); + + SD.doCreate(); + SD.doDelete(); + SD.doModify(); + + SD.writeStateFile(SD.path); } diff --git a/src/main/java/com/olexyn/ensync/Main.java b/src/main/java/com/olexyn/ensync/Main.java index 00ea739..085db53 100644 --- a/src/main/java/com/olexyn/ensync/Main.java +++ b/src/main/java/com/olexyn/ensync/Main.java @@ -8,38 +8,13 @@ import java.util.HashMap; public class Main{ - - - - - final public static Thread UI_THREAD = new Thread(new UI(), "ui"); - final public static Thread FLOW_THREAD = new Thread(new Flow(), "flow"); - final public static HashMap MAP_OF_SYNCMAPS = new HashMap<>(); - - public static void main(String[] args) { - - - - UI_THREAD.start(); - FLOW_THREAD.start(); - - - - - - - } - - - - } diff --git a/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java index acb38c8..bd1c786 100644 --- a/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java +++ b/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java @@ -10,7 +10,7 @@ import java.util.List; import java.util.Map; /** - * A SyncDirectory is an occurrence of a particular directory somewhere across the filesystems. + * A SyncDirectory is a singular occurrence of a directory in the filesystems. */ public class SyncDirectory { @@ -18,7 +18,7 @@ public class SyncDirectory { private SyncDirectory thisSD = this; - private SyncMap syncMap; + private final SyncMap syncMap; public String path = null; public Map listCreated = new HashMap<>(); @@ -59,11 +59,7 @@ public class SyncDirectory { filemap.put(filePath, file); } - - return filemap; - - } @@ -86,9 +82,7 @@ public class SyncDirectory { filemap.put(sFilePath, sfile); } - return filemap; - } diff --git a/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java b/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java index 224fc7c..e69e504 100644 --- a/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java +++ b/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java @@ -10,34 +10,26 @@ public class SyncFile extends File { public long timeModifiedFromStateFile = 0; public String relativePath; - private SyncDirectory sd; + private final SyncDirectory sd; - - - public SyncFile(SyncDirectory sd , String pathname) { + public SyncFile(SyncDirectory sd, String pathname) { super(pathname); this.sd = sd; relativePath = this.getPath().replace(sd.path, ""); } - - - - - public void setTimeModifiedFromStateFile(long value){ + public void setTimeModifiedFromStateFile(long value) { timeModifiedFromStateFile = value; } - - public long getTimeModifiedFromStateFile(){ + public long getTimeModifiedFromStateFile() { SyncFile record = sd.readStateFile().get(this.getPath()); return record == null ? 0 : record.timeModifiedFromStateFile; } - /** * If File exists on Disk get the TimeModified from there. * Else try to read it from StateFile. @@ -54,10 +46,6 @@ public class SyncFile extends File { if (sd.readStateFile().get(this.getPath())!=null){ return getTimeModifiedFromStateFile(); } - - return 0; } - - } diff --git a/src/main/java/com/olexyn/ensync/artifacts/SyncMap.java b/src/main/java/com/olexyn/ensync/artifacts/SyncMap.java index 1e36c8d..bec044c 100644 --- a/src/main/java/com/olexyn/ensync/artifacts/SyncMap.java +++ b/src/main/java/com/olexyn/ensync/artifacts/SyncMap.java @@ -8,7 +8,8 @@ import java.util.HashMap; import java.util.Map; /** - * A SyncMap is the set of such SyncDirectories. The purpose of the SyncMap is to help syncronize the SyncDirectories. + * A SyncMap is a map of SyncDirectories.
+ * It synchronizes the SyncDirectories it contains. */ public class SyncMap { diff --git a/src/main/java/com/olexyn/ensync/ui/UI.java b/src/main/java/com/olexyn/ensync/ui/UI.java index 9df73d6..7f24ca3 100644 --- a/src/main/java/com/olexyn/ensync/ui/UI.java +++ b/src/main/java/com/olexyn/ensync/ui/UI.java @@ -9,27 +9,17 @@ import javafx.stage.Stage; public class UI extends Application implements Runnable { - - - - @Override public void start(Stage primaryStage) throws Exception { - Parent root = FXMLLoader.load(getClass().getResource("layout.fxml")); + // in IDEA add ";?.fxml;?.css" to File|Settings|Compiler settings + Parent root = FXMLLoader.load(getClass().getResource("/fxml/layout.fxml")); Scene scene = new Scene(root, 500, 500); - - - - primaryStage.setTitle("EnSync"); primaryStage.setScene(scene); primaryStage.show(); } - - - @Override public void run() { UI.launch(); diff --git a/src/main/java/com/olexyn/ensync/ui/layout.fxml b/src/main/resources/fxml/layout.fxml similarity index 100% rename from src/main/java/com/olexyn/ensync/ui/layout.fxml rename to src/main/resources/fxml/layout.fxml