| 39 | | DSU.sort(a, new SortKey<String,String>() { |
| 40 | | public String getValue(String s) { |
| 41 | | c.increment(); |
| 42 | | return s.toLowerCase(); |
| | 39 | if (count) { |
| | 40 | DSU.sort(words, new SortKey<String,String>() { |
| | 41 | public String getValue(String s) { |
| | 42 | c.increment(); |
| | 43 | return s.toLowerCase(); |
| | 44 | } |
| | 45 | }); |
| | 46 | } else { |
| | 47 | DSU.sort(words, new SortKey<String,String>() { |
| | 48 | public String getValue(String s) { |
| | 49 | return s.toLowerCase(); |
| | 50 | } |
| | 51 | }); |
| | 52 | } |
| | 53 | long t2 = System.currentTimeMillis(); |
| | 54 | if (log) { |
| | 55 | System.out.println("DSU"); |
| | 56 | if (count) { |
| | 57 | System.out.println("called " + c.i + " times"); |
| | 58 | } else { |
| | 59 | System.out.println((t2 - t1) + "ms"); |
| 58 | | Collections.sort(a, new Comparator<String>() { |
| 59 | | public int compare(String s1, String s2) { |
| 60 | | c.increment(); |
| 61 | | return s1.toLowerCase().compareTo(s2.toLowerCase()); |
| | 68 | if (count) { |
| | 69 | Collections.sort(words, new Comparator<String>() { |
| | 70 | public int compare(String s1, String s2) { |
| | 71 | c.increment(); |
| | 72 | return s1.toLowerCase().compareTo(s2.toLowerCase()); |
| | 73 | } |
| | 74 | }); |
| | 75 | } else { |
| | 76 | Collections.sort(words, new Comparator<String>() { |
| | 77 | public int compare(String s1, String s2) { |
| | 78 | return s1.toLowerCase().compareTo(s2.toLowerCase()); |
| | 79 | } |
| | 80 | }); |
| | 81 | } |
| | 82 | long t2 = System.currentTimeMillis(); |
| | 83 | if (log) { |
| | 84 | System.out.println("Collections.sort with Comparator"); |
| | 85 | if (count) { |
| | 86 | System.out.println("called " + c.i + " times"); |
| | 87 | } else { |
| | 88 | System.out.println((t2 - t1) + "ms"); |
| 74 | | dsu(args[0]); |
| 75 | | withComparator(args[0]); |
| | 94 | int DSU = 0; |
| | 95 | int COMPARATOR = 1; |
| | 96 | int which = DSU; |
| | 97 | boolean count = false; |
| | 98 | boolean outputWords = false; |
| | 99 | if (args.length < 1) { |
| | 100 | System.err.println("usage: DSUExample2 OPTIONS FILENAME"); |
| | 101 | System.exit(1); |
| | 102 | } |
| | 103 | for (int i = 0; i < args.length - 1; i++) { |
| | 104 | if (args[i].equals("-dsu")) { |
| | 105 | which = DSU; |
| | 106 | } |
| | 107 | if (args[i].equals("-comparator")) { |
| | 108 | which = COMPARATOR; |
| | 109 | } |
| | 110 | if (args[i].equals("-count")) { |
| | 111 | count = true; |
| | 112 | } |
| | 113 | if (args[i].equals("-words")) { |
| | 114 | outputWords = true; |
| | 115 | } |
| | 116 | } |
| | 117 | List<String> words = readWords(args[args.length - 1]); |
| | 118 | if (which == DSU) { |
| | 119 | dsu(words, count, !outputWords); |
| | 120 | } else if (which == COMPARATOR) { |
| | 121 | collectionsSortWithComparator(words, count, !outputWords); |
| | 122 | } |
| | 123 | if (outputWords) { |
| | 124 | for (String s : words) { |
| | 125 | System.out.println(s); |
| | 126 | } |
| | 127 | } |