In the following code sorting order to be highest to lowest number.
import java.io.*;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import javax.swing.text.html.HTMLDocument.Iterator;
public class new3 {
public static void main(String arg[]) throws Exception {
TreeMap tm = null;
HashMap hm = new HashMap();
String abc;
String delimiter = ",";
String lkeys = null;
String lval = null;
String j = "";
String s6[] = new String[11];
Set s3;
try {
String strLine;
String s[] = new String[10];
File f1 = new File("D:\\abc.txt");
f1.createNewFile();
FileWriter fw1 = new FileWriter(f1);
PrintWriter pw = new PrintWriter(fw1);
File f2 = new File("D:\\transtons1");
s6 = f2.list();
FileInputStream fib = null;
BufferedReader br = null;
for (int i = 0; i < s6.length; i++) {
File f3 = new File("D:/transtons1/" + s6[i]);
fib = new FileInputStream(f3);
br = new BufferedReader(new InputStreamReader(fib));
strLine = "";
tm = new TreeMap();
while ((strLine = br.readLine()) != null) {
String s1 = "";
String s2 = "";
if ((strLine.equals("SUCCESS"))) {
while ((strLine = br.readLine()) != null) {
if (!(strLine.equals("SUCCESS"))) {
if (!(strLine.trim().equalsIgnoreCase(""))) {
s2 = strLine.split(",")[0];
if (strLine.split(",")[1].contains("-")) {
s1 = "0";
}
String[] sp = strLine.split(",");
if (sp.length == 2) {
double d = Double.parseDouble(sp[1]) - 6.192;
if (d < 0) {
sp[1] = "0";
if (sp[1].contains("E-4")) {
sp[1] = "0";
}
} else {
sp[1] = new Double(d).toString();
}
}
tm.put(s2, new String[] { sp[1], s6[i] });
}
} else {
strLine = br.readLine();
}
}
}
}
Set set = tm.keySet();
java.util.Iterator itTm = set.iterator();
System.out.print(s6[i].substring(0, s6[i].indexOf(".log"))
+ ", ");
pw.append(s6[i].substring(0, s6[i].indexOf(".log")) + ", ");
String k = "";
String k1 = "";
while (itTm.hasNext()) {
String firstString = (String) itTm.next();
TreeMap tm1 = new TreeMap();
k = "";
if (((String[]) tm.get(firstString))[0]
.equalsIgnoreCase("0")) {
k1 = k1 + firstString + ", "
+ ((String[]) tm.get(firstString))[0] + ", ";
} else {
k = firstString + ", "
+ ((String[]) tm.get(firstString))[0] + ", ";
}
pw.append(k);
}
pw.append(k1);
}
pw.flush();
br.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Current output is like this:
i/p file:-SearchRequest
TransactionInformation.TransactionControlNumber: 1371010101300003
TransactionInformation.Priority: null
Data.Position: 1
Data.Position: 2
Data.Position: 3
Data.Position: 4
Data.Position: 5
Data.Position: 6
Data.Position: 7
Data.Position: 8
Data.Position: 9
Data.Position: 10
TargetGalleries:
SUCCESS
3173055107830001,200.0288532
3327030712630003,1.8967291
1306031007490001,1.3557106
3404094507580005,2.0373015
3328087009450002,1.9978973
3325104612680001,1008.6304734
The output should be in the follownig order for me:
1371010101300003, 3173055107830001, 1002.83685319999998, 3325104612680001, 193.4384734, 1306031007490001, 0, 3327030712630003, 0, 3328087009450002, 0, 3404094507580005, 0,