日期:2014-05-18 浏览次数:20886 次
public class AreaTerminalFinalModel {
private Integer mark;
private String levelMark;
private Double label;
private boolean check;
//构造器
public AreaTerminalFinalModel(Integer mark, String levelMark, Float label) {
//name 为 区域/品牌 名 ,
this.mark = mark;
this.levelMark = levelMark;
String a = String.valueOf(label);
BigDecimal bd = new BigDecimal(a);
this.label = bd.doubleValue();
this.setCheck(false);
}
public boolean levelSame(AreaTerminalFinalModel a) {
return this.getLevelMark().equals(a.getLevelMark());
}
}
package sn.utils;
import java.util.LinkedList;
import java.util.List;
import sn.model.AreaTerminalFinalModel;
public class TestList {
public static void main(String[] args) {
List<AreaTerminalFinalModel> list
= new LinkedList<AreaTerminalFinalModel>();
String[] name = {"标准C1","正规工具","测试代码","实验室","公关系统","航空交通","河流","道路","一心一意","PIC","无良商家","happy",};
Float[] num = {0.35f , 4f ,1.1f , 726f , 2.8f , 0f , -12f , 23f , 9f};
for (int i = 0 ; i < 36 ; i ++) {
list.add(new AreaTerminalFinalModel((int)(Math.random()*10),
name[(int)(Math.random()*12)],
num[(int)(Math.random()*num.length)]));
}
for (int i = 0 ; i < list.size() ; i ++) {
for (int j = i+1 ; j < list.size() ; j ++) {
if(list.get(i).getMark().intValue() ==
list.get(j).getMark().intValue()
&& list.get(i).levelSame(list.get(j)))
{
Double a = (list.get(i).getLabel()==null && !list.get(i).isCheck())?0.0:list.get(i).getLabel();
Double b = (list.get(j).getLabel()==null && !list.get(j).isCheck())?0.0:list.get(j).getLabel();
list.get(i).setLabel(a+b);
list.get(j).setCheck(true);
}
}
}
synchronized (list) {
for (int i = 0 ; i < list.size() ; i ++) {
if(list.get(i).isCheck()) {
list.remove(i);
}
}
}
for (int i = 0 ; i <list.size() ; i++) {
System.out.println(list.get(i).getMark()
+"---\t"+list.get(i).getLevelMark()
+"---\t"+list.get(i).isCheck());
}
}
}