日期:2014-05-16 浏览次数:20507 次
/** * * 这里填写类说明 * @author Juz * Mar 30, 2012 */ @Deprecated public class SortListTools implements Comparator{ private String key; //property public void doSortkey (String key) { this.key = key; } public int compare(Object arg0, Object arg1) { Map m1 = (Map) arg0; Map m2 = (Map) arg1; int flag = 0; float id1 = Float.parseFloat(m1.get(key).toString()); float id2 = Float.parseFloat(m2.get(key).toString()); if ( id2 > id1) { flag = 1; }else if (id1 < id2) { flag = -1; } return flag; } }
/** * List指定列排名. * @param liinfo list:{[map][map][map]....} * @param string key 指定排序map的key * @param string minckey 指定输出排序的key * @return List * @author Juz */ public List rankList(List liinfo, String key, String minckey) { // TODO Auto-generated method stub int thisv = 1; int nextv = 0; float sscore =0; float tscore =0; Map thism =null; Map nextm = null; SortListTools st = new SortListTools(); st.doSortkey(key); Collections.sort(liinfo, st); for(int i=0;i<liinfo.size();i++){ ((Map)liinfo.get(i)).put(minckey, i+1); } for(int i=0;i<liinfo.size();i++){ if(i<liinfo.size()-1){ thism = (Map)liinfo.get(i); thisv = Integer.parseInt(thism.get(minckey).toString()); sscore = Float.parseFloat(thism.get(key).toString()); nextm = (Map)liinfo.get(i+1); tscore = Float.parseFloat(nextm.get(key).toString()); if(sscore-tscore<0.0001){ nextm.put(minckey, thisv); }else{ nextm.put(minckey, thisv+1); } } } return liinfo; }