java ArrayList 정렬 질문
아래 코드의 결과가
1.aaa
3.aaa
4.aaa
2.aaa
6.aaa
5.aaa
라고 했을 때 이를
1.aaa
2.aaa
3.aaa
4.aaa
5.aaa
6.aaa
으로 정렬 하여 출력 하고 싶습니다.
도와 주세요
------
package test_sum;
import java.io.*;
import java.util.*;
public class test_sum_process {
public static void main(String[] args) throws IOException,FileNotFoundException{
Scanner dateinput = new Scanner(System.in); // script parameter -- date values
String stat_date = dateinput.next();
ArrayList txtFiles= new ArrayList();
File f= new File("D:/AADEV_LGE/workspace/test_stat_sum/rsc"); // Log Dir
String tmpFile = f+"/tmp"; // Temp File
String result = f+"/result.txt"+"_"+stat_date; // Result File
if(!f.exists())
{
System.out.println("not found dir");
return;
}
File[] allFiles= f.listFiles();
for(File file : allFiles)
{
if(file.getName().startsWith(stat_date))
{
txtFiles.add(file);
}
}
for(File file : txtFiles)
{
String readFile = f+"/"+file.getName();
try {
BufferedReader in = new BufferedReader(new FileReader(readFile));
//System.out.println(readFile);
String line = "";
while ((line = in.readLine()) != null) {
if (line.indexOf(":") < 0)
continue;
// System.out.println(line);
String[] arr = line.split(":");
String codetmp = arr[0] ;
String cnttmp = arr[1] ;
String codename = codetmp.replaceAll("[- ]", "");
String codecnt = cnttmp.replaceAll("[^0-9.-]", "");
BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile,true));
StringBuffer str1 = new StringBuffer(codename);
StringBuffer str2 = new StringBuffer(codecnt);
out.write(str1 + " " + str2 + "\n");
out.flush();
}
in.close();
} catch (IOException e) {
System.out.println(e);
}
}
Scanner in2 = new Scanner(new File(tmpFile));
HashMap map = new HashMap();
HashMap map2 = new HashMap();
ArrayList order = new ArrayList();
ArrayList order2 = new ArrayList();
String cntname;
Double logcnt;
while (in2.hasNext()) {
cntname = in2.next();
logcnt = in2.nextDouble();
if (cntname.equals("FirstLog") || cntname.equals("LastLog")) {
System.out.println("");
}
else if (!cntname.equals("90%응답시간")) {
if (!map.containsKey(cntname)) {
LogList s = new LogList(cntname, logcnt);
order.add(s);
map.put(cntname, s); // 사용자를 기억해놓습니다
}
map.get(cntname).addScore(logcnt);
}
else if (cntname.equals("90%응답시간")) {
if (!map2.containsKey(cntname)) {
LogList2 s = new LogList2(cntname, logcnt);
order2.add(s);
map2.put(cntname, s); // 사용자를 기억해놓습니다
}
map2.get(cntname).addScore2(logcnt);
}
}
try {
PrintWriter out = new PrintWriter(new FileWriter(result, true));
for(LogList i : order ) // class 에서 리턴 시 번호를 붙임
out.println(i);
for(LogList2 i : order2 )
out.println(i);
out.close();
} catch (Exception e) {
if(e instanceof IOException) System.out.println("Input & Out Error ");
else System.out.println("Etc Error " + e.toString());
}
}
}
댓글 달기