|
分類:[Java]
以下のソース(書ききれない為クラス、エラー等端折ってます・・・)を拡張for文、Generics の表記をせずに(5.0以前?の書き方に)書き直したいんですがどうすればいいですか?教えて下さい! BufferedReader br = new BufferedReader(new FileReader(f)); String line; line = br.readLine(); String[] headitems = line.split(","); headsize = headitems.length;
articles = new ArrayList<String>(); for (int i = 1; i < headsize; i++) { articles.add(headitems[i]); } while ((line = br.readLine()) != null) { String[] items = line.split(","); } Result r = new Result(articles, items);// 1行の結果 for (String art : articles) {// 科目毎の合計 Integer val = totals.get(art); if (val == null) { val = 0; } totals.put(art, val + r.getResult().get(art)); } total += r.getTotal();// トータル合計 results.add(r); } br.close(); Collections.sort(results);// 全部読んだ後ソート }
public void writedown(File f) {
BufferedWriter bw = new BufferedWriter(new FileWriter(f)); // フォーマットして書き出し bw.write(format()); bw.close(); } private String format() { StringBuffer buf = new StringBuffer(); buf.append("順位\t名前\t"); for (String art : articles) { buf.append(art).append("\t"); } buf.append("合計\n"); int rank = 1; for (Result res : results) { buf.append(rank).append("\t"); buf.append(res.getName()).append("\t"); for (String art : articles) { buf.append(res.getResult().get(art)).append("\t"); } buf.append(res.getTotal()).append("\n"); rank++; } buf.append("\t\t");//総計 for (String art : articles) { buf.append(totals.get(art)).append("\t"); } buf.append(total).append("\n"); return buf.toString(); } public void reset() {/*集計に使う入れ物を洗う*/ headsize = 0; articles = new ArrayList<String>(); results = new ArrayList<Result>(); totals = new HashMap<String, Integer>(); total = 0; } private int headsize; private List<String> articles; private List<Result> results; private Map<String, Integer> totals; private Integer total; }
|