Format and minor docs.

master
Ivan Olexyn 6 years ago
parent 7b018185c8
commit d43e79babd

@ -6,16 +6,20 @@ public class Artifacts {
Tools tools = new Tools(); Tools tools = new Tools();
/**
* @param file
* @return
*/
public MFile getMFile(File file) { public MFile getMFile(File file) {
MFile mfile = new MFile(); MFile mfile = new MFile();
mfile.file = file; mfile.file = file;
mfile.md5 = tools.getMd5(file.getPath()); mfile.md5 = tools.getMd5(file.getPath());
return mfile; return mfile;
} }
/**
*
*/
public class MFile { public class MFile {
public File file; public File file;
public String md5; public String md5;

@ -16,6 +16,9 @@ import java.util.Map;
import app.Artifacts.MFile; import app.Artifacts.MFile;
/***
* Controller class for JavaFX. Contains the application logic.
*/
public class Controller { public class Controller {

@ -7,7 +7,6 @@ public class Execute {
/** /**
*
* @param cmd an array representing a shell command * @param cmd an array representing a shell command
* @return <i>TwoBr</i> class, containing two BufferedReaders, * @return <i>TwoBr</i> class, containing two BufferedReaders,
* <i>output</i> and <i>error</i> * <i>output</i> and <i>error</i>

@ -13,10 +13,9 @@ import javafx.stage.Stage;
public class Main extends Application { public class Main extends Application {
static String foo;
@Override @Override
public void start(Stage primaryStage) throws Exception{ public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml")); Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));
Scene scene = new Scene(root, 300, 275); Scene scene = new Scene(root, 300, 275);

@ -10,6 +10,10 @@ public class QuicksortMd5 {
private int j; private int j;
private int p; private int p;
/**
* @param md5Pool
* @return a Map sorted by md5.
*/
public Map<Integer, MFile> quicksortMd5(Map<Integer, MFile> md5Pool) { public Map<Integer, MFile> quicksortMd5(Map<Integer, MFile> md5Pool) {
this.md5Pool = md5Pool; this.md5Pool = md5Pool;

@ -12,28 +12,24 @@ import app.Artifacts.MFile;
public class Routines { public class Routines {
Execute x;
Execute x = null; Tools tools;
Tools tools = new Tools();
Write write = new Write();
public Routines() { public Routines() {
this.x = new Execute(); this.x = new Execute();
this.tools = new Tools(); this.tools = new Tools();
} }
/** /**
* [1] Write output of <b>find srcdir</b> to <b>/tmp/find</b> <br> * [1] Write output of <b>find srcdir</b> to <b>/tmp/find</b> .<br>
* [2] Read <b>/tmp/find</b> into <b>List>String></b> <br> * [2] Read <b>/tmp/find</b> into <b>List< String /></b> .<br>
* [3] Add <b>List>String></b> entries to <b>Map>String,File></b> , where * [3] Add <b>List< String /></b> entries to <b>Map>String,File></b> , where
* <b>String</b> is an <b>int</b> key. <br> * <b>String</b> is an <b>int</b> key. <br>
* *
* @param srcdir * @param srcdir <i>String</i>
* @param type file OR directory * @param type <i>String</i> "file" OR "dir" , pick what type will be loaded.
* @return filepool * @return filepool
*/ */
public Map<Integer, File> loadPool(String srcdir, String type) { public Map<Integer, File> loadPool(String srcdir, String type) {
@ -51,7 +47,7 @@ public class Routines {
int j = 0; int j = 0;
for (int i = 0; i < lines.size(); i++) { for (int i = 0; i < lines.size(); i++) {
File file = new File(lines.get(i)); File file = new File(lines.get(i));
if (type == "directory" && file.isDirectory() || type == "file" && file.isFile()) { if (type == "dir" && file.isDirectory() || type == "file" && file.isFile()) {
filepool.put(j, file); filepool.put(j, file);
j++; j++;
} }
@ -59,7 +55,12 @@ public class Routines {
return filepool; return filepool;
} }
/**
* Calculate md5 for each file in <b>pool</b> .
*
* @param pool Map< Integer, File />
* @return Map< Integer , MFile />
*/
public Map<Integer, MFile> md5Pool(Map<Integer, File> pool) { public Map<Integer, MFile> md5Pool(Map<Integer, File> pool) {
Map<Integer, MFile> md5Pool = new HashMap<>(); Map<Integer, MFile> md5Pool = new HashMap<>();
for (int i = 0; i < pool.size(); i++) { for (int i = 0; i < pool.size(); i++) {
@ -69,7 +70,10 @@ public class Routines {
return md5Pool; return md5Pool;
} }
/**
* @param md5Pool Map< Integer, MFile /> , a map containing files and their md5.
* @return Map< Integer , MFile /> of duplicates contained in <b>md5Pool</b>
*/
public Map<Integer, MFile> doubles(Map<Integer, MFile> md5Pool) { public Map<Integer, MFile> doubles(Map<Integer, MFile> md5Pool) {
Map<Integer, MFile> doubles = new HashMap<>(); Map<Integer, MFile> doubles = new HashMap<>();
int d = 0; int d = 0;

@ -13,11 +13,12 @@ public class Tools {
/** /**
* @return Md5 of File at @param path * @param path <i>String</i>
* @return Md5 of File at <b>path</b>
*/ */
public String getMd5(String path) { public String getMd5(String path) {
// output of md5sum: "md5 filepath" // output of md5sum is "md5 filepath"
BufferedReader md5reader = x.execute(new String[] { "md5sum", path }).output; BufferedReader md5reader = x.execute(new String[]{"md5sum", path}).output;
String md5 = null; String md5 = null;
try { try {
md5 = md5reader.readLine().split(" ")[0]; md5 = md5reader.readLine().split(" ")[0];

@ -4,13 +4,16 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.Map; import java.util.Map;
import app.Artifacts.MFile; import app.Artifacts.MFile;
public class Write { public class Write {
/** /**
* writes <b>text</b> to file at <b>path</b> * Write <b>text</b> to file at <b>path</b> .
* <p> *
* @param path <i>String</i>
* @param text <i>StringBuilder</i>
*/ */
public void textFile(String path, StringBuilder text) { public void textFile(String path, StringBuilder text) {
try { try {
@ -24,11 +27,11 @@ public class Write {
/** /**
* append all elements of <b>pool</b> to StringBuilder and write to * Append all elements of <b>pool</b> to <i>StringBuilder</i>
* <b>/tmp/name</b> * and write to /tmp/<b>name</b> .
* <p>
* *
* @param pool * @param name <i>String</i>
* @param pool <i>Map< Integer, File /></i>
*/ */
public void textPool(String name, Map<Integer, File> pool) { public void textPool(String name, Map<Integer, File> pool) {
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
@ -40,11 +43,11 @@ public class Write {
/** /**
* append all elements of <b>md5Pool</b> to StringBuilder and write to * Append all elements of <b>pool</b> to <i>StringBuilder</i>
* <b>/tmp/name</b> * and write to /tmp/<b>name</b> .
* <p>
* *
* @param md5Pool * @param name <i>String</i>
* @param md5Pool <i>Map< Integer, MFile /></i>
*/ */
public void textMd5Pool(String name, Map<Integer, MFile> md5Pool) { public void textMd5Pool(String name, Map<Integer, MFile> md5Pool) {
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();

Loading…
Cancel
Save