Java tutorial
/** * PureInfo Command * @(#)BySubjectStatistic.java 1.0 2007-7-26 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.reports.table.data.sci; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.commons.collections.map.HashedMap; import com.pureinfo.ark.content.ArkContentHelper; import com.pureinfo.dolphin.model.DolphinObject; import com.pureinfo.dolphin.model.IObjects; import com.pureinfo.dolphin.persister.IStatement; import com.pureinfo.dolphin.query.logic.ISQLLogic; import com.pureinfo.force.exception.PureException; import com.pureinfo.srm.product.domain.IProductMgr; import com.pureinfo.srm.product.model.Product; import com.pureinfo.srm.reports.table.data.institute.InstituteReportBase; /** * <P> * Created on 2007-7-26 21:12:01 <BR> * Last modified on 2007-7-26 * </P> * TODO describe BySubjectStatistic here ... * * @author elmar.chen * @version 1.0, 2007-7-26 * @since Command 1.0 */ public class SCIBySchoolStatistic extends InstituteReportBase { public static void main(String[] args) throws PureException { IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); IStatement stat = mgr.createQuery( "select count({this.id}) _NUM, {this.englishScience} AS _SUB from {this} group by _SUB", 0); IObjects nums = stat.executeQuery(false); DolphinObject num = null; Map map = new HashedMap(); while ((num = nums.next()) != null) { String subest = num.getStrProperty("_SUB"); if (subest == null || subest.trim().length() == 0) continue; String[] subs = subest.split(";"); int nNum = num.getIntProperty("_NUM", 0); for (int i = 0; i < subs.length; i++) { String sSub = subs[i].trim(); Integer odValue = (Integer) map.get(sSub); int sum = odValue == null ? nNum : (nNum + odValue.intValue()); map.put(sSub, new Integer(sum)); } } List l = new ArrayList(map.size()); for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { Map.Entry en = (Map.Entry) iter.next(); l.add(new Object[] { en.getKey(), en.getValue() }); } Collections.sort(l, new Comparator() { public int compare(Object _sO1, Object _sO2) { Object[] arr1 = (Object[]) _sO1; Object[] arr2 = (Object[]) _sO2; Comparable s1 = (Comparable) arr1[1]; Comparable s2 = (Comparable) arr2[01]; return s1.compareTo(s2); } }); for (Iterator iter = l.iterator(); iter.hasNext();) { Object[] arr = (Object[]) iter.next(); System.out.println(arr[0] + " = " + arr[1]); } } /** * @see com.pureinfo.srm.reports.table.data.institute.InstituteReportBase#getMyCondition() */ protected ISQLLogic getMyCondition() { if (1 == 1) throw new RuntimeException("unimpleted method."); return null; } /** * @see com.pureinfo.srm.reports.table.data.institute.InstituteReportBase#getSelects() */ protected Map getSelects() { if (1 == 1) throw new RuntimeException("unimpleted method."); return null; } /** * @see com.pureinfo.srm.reports.table.data.institute.InstituteReportBase#getTables() */ protected String[] getTables() { if (1 == 1) throw new RuntimeException("unimpleted method."); return null; } /** * @see com.pureinfo.srm.reports.table.data.institute.InstituteReportBase#getCols() */ protected LinkedHashMap getCols() { if (1 == 1) throw new RuntimeException("unimpleted method."); return null; } /** * @see com.pureinfo.srm.reports.table.data.institute.InstituteReportBase#myMakeCell(com.pureinfo.dolphin.model.DolphinObject, java.lang.String) */ protected Object myMakeCell(DolphinObject _sData, String _sColKey) throws PureException { if (1 == 1) throw new RuntimeException("unimpleted method."); return null; } /** * @see com.pureinfo.srm.reports.table.data.institute.IInstituteDataBuilder#getTitle() */ public String getTitle() { if (1 == 1) throw new RuntimeException("unimpleted method."); return null; } /** * @see com.pureinfo.srm.reports.table.data.institute.IInstituteDataBuilder#descParam() */ public ParamDesc descParam() { return new ParamDesc() { public String getDateProperty() { if (1 == 1) throw new RuntimeException("{this.publicationYear}"); return null; } public String getDateDesc() { return ""; } }; } }