Last active
August 29, 2015 14:06
-
-
Save welcor/3c43e4db2e545a5eaec8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HashMap<String, ArrayList<File>> fileList = new HashMap<>(); | |
... | |
//Her bliver der sorteret ud fra filtype og så bliver filen også smidt ind i en hashmap, hvis den ikke findes ellers lagt til en arrayList. | |
public void findFiles1(File dir) throws IOException, Exception { | |
File[] listOfFolder = dir.listFiles(); | |
//Folder | |
for (File file : listOfFolder) { | |
if (file.isDirectory()) { | |
findFiles1(file); | |
} else | |
{ | |
if (tifName.accept(dir, file.getName())) | |
{ | |
if (file.getName().endsWith(".tiff") || file.getName().endsWith(".tif")) | |
{ | |
String key = file.getName().split(sym)[0]; | |
if (fileList.containsKey(key)) { | |
fileList.get(key).add(file); | |
System.out.println("Old file found: " + file.getName().split(sym)[0] + " is old: " + fileList.get(key).add(file) + file.getAbsolutePath()); | |
// List mapValues = ArrayList(fileList.values()); | |
// fjern collections.sort - de er likegyldige her | |
// Collections.sort(fileList.get(key)); | |
} | |
else | |
{ | |
fileList.put(key, new ArrayList<File>()); | |
fileList.get(key).add(file); | |
System.out.println("New file found: " + file.getName().split(sym)[0] + " is new: " + fileList.get(key).add(file)); | |
System.out.println("Put new file i arrayList: " + fileList.put(key, new ArrayList<File>())); | |
System.out.println("File name: " + file.getName() + " and file location " + file.getAbsolutePath()); | |
String fil = file.getAbsolutePath(); | |
} | |
// } | |
// fjern collections.sort - de er likegyldige her | |
// List mapKeys = new ArrayList(fileList.keySet()); | |
// Collections.sort(mapKeys); | |
} | |
} | |
else | |
{ | |
System.err.println("This file : " + file.getName() + " not tif file."); | |
} | |
} | |
} | |
System.err.println("Done"); | |
} | |
//Her sker alt samling af tif filer, ud fra den liste man får fra hashmappen. | |
public void merg() throws IOException | |
{ | |
List<String> tifs = new ArrayList<String>(fileList.keySet()); | |
// her er det ok. Ikke inne i en rekursiv metode.. | |
Collections.sort(tifs); | |
for (String key: tifs) { | |
List<File> files = fileList.get(key); | |
// sorter når du har behov for at listen er sorteret, ikke mens du henter ud | |
Collections.sort(files); | |
for (File tifFile: files) { | |
// gør noget med denne tiff-fil. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment