[29600] | 1 | <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*" %>
|
---|
| 2 | <%!
|
---|
| 3 | public int GCD(int a, int b) {
|
---|
| 4 | if (b==0) return a;
|
---|
| 5 | return GCD(b,a%b);
|
---|
| 6 | }
|
---|
| 7 |
|
---|
| 8 | ArrayList<File> listFilesForFolder(final File folder, String matchExt) {
|
---|
| 9 | ArrayList<File> fileList = new ArrayList<File>();
|
---|
| 10 |
|
---|
| 11 | for (final File fileEntry : folder.listFiles()) {
|
---|
[29621] | 12 | if (fileEntry.isFile()) {
|
---|
| 13 | if (fileEntry.getName().toLowerCase().endsWith(matchExt)) {
|
---|
| 14 | fileList.add(fileEntry);
|
---|
| 15 | }
|
---|
| 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | return fileList;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | ArrayList<File> listFilesForFolderRecursive(final File folder, String matchExt) {
|
---|
| 23 | ArrayList<File> fileList = new ArrayList<File>();
|
---|
| 24 |
|
---|
| 25 | for (final File fileEntry : folder.listFiles()) {
|
---|
[29600] | 26 | if (fileEntry.isDirectory()) {
|
---|
| 27 | listFilesForFolder(fileEntry,matchExt);
|
---|
| 28 | } else {
|
---|
| 29 | if (fileEntry.getName().toLowerCase().endsWith(matchExt)) {
|
---|
| 30 | fileList.add(fileEntry);
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | return fileList;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public static Map<String, Integer> sortByComparator(Map<String, Integer> unsortMap)
|
---|
| 39 | {
|
---|
| 40 |
|
---|
| 41 | // Convert Map to List
|
---|
| 42 | List<Map.Entry<String, Integer>> list
|
---|
| 43 | = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet());
|
---|
| 44 |
|
---|
| 45 | // Sort list with comparator, to compare the Map values
|
---|
| 46 | Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
|
---|
| 47 | public int compare(Map.Entry<String, Integer> o1,
|
---|
| 48 | Map.Entry<String, Integer> o2) {
|
---|
| 49 | return (o2.getValue()).compareTo(o1.getValue());
|
---|
| 50 | }
|
---|
| 51 | });
|
---|
| 52 |
|
---|
| 53 | // Convert sorted map back to a Map
|
---|
| 54 | Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
|
---|
| 55 | for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
|
---|
| 56 | Map.Entry<String, Integer> entry = it.next();
|
---|
| 57 | sortedMap.put(entry.getKey(), entry.getValue());
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | return sortedMap;
|
---|
| 61 | }
|
---|
| 62 | /*
|
---|
| 63 | public static void printMap(Map<String, Integer> map)
|
---|
| 64 | {
|
---|
| 65 | for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
---|
| 66 | out.println("[Key] : " + entry.getKey()
|
---|
| 67 | + " [Value] : " + entry.getValue() + "br />");
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | */
|
---|
| 71 | %>
|
---|