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