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()) {
|
---|
14 | if (fileEntry.isDirectory()) {
|
---|
15 | listFilesForFolder(fileEntry,matchExt);
|
---|
16 | } else {
|
---|
17 | if (fileEntry.getName().toLowerCase().endsWith(matchExt)) {
|
---|
18 | fileList.add(fileEntry);
|
---|
19 | }
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | return fileList;
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 | public static Map<String, Integer> sortByComparator(Map<String, Integer> unsortMap)
|
---|
29 | {
|
---|
30 |
|
---|
31 | // Convert Map to List
|
---|
32 | List<Map.Entry<String, Integer>> list
|
---|
33 | = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet());
|
---|
34 |
|
---|
35 | // Sort list with comparator, to compare the Map values
|
---|
36 | Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
|
---|
37 | public int compare(Map.Entry<String, Integer> o1,
|
---|
38 | Map.Entry<String, Integer> o2) {
|
---|
39 | return (o2.getValue()).compareTo(o1.getValue());
|
---|
40 | }
|
---|
41 | });
|
---|
42 |
|
---|
43 | // Convert sorted map back to a Map
|
---|
44 | Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
|
---|
45 | for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
|
---|
46 | Map.Entry<String, Integer> entry = it.next();
|
---|
47 | sortedMap.put(entry.getKey(), entry.getValue());
|
---|
48 | }
|
---|
49 |
|
---|
50 | return sortedMap;
|
---|
51 | }
|
---|
52 | /*
|
---|
53 | public static void printMap(Map<String, Integer> map)
|
---|
54 | {
|
---|
55 | for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
---|
56 | out.println("[Key] : " + entry.getKey()
|
---|
57 | + " [Value] : " + entry.getValue() + "br />");
|
---|
58 | }
|
---|
59 | }
|
---|
60 | */
|
---|
61 |
|
---|
62 |
|
---|
63 | %>
|
---|
64 |
|
---|