LIst 數據排序

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		System.out.println(44);
		List<CallRecordVo> list1 = createTestList();
		
		Collections.sort(list1, new Comparator<CallRecordVo>() {
			@SuppressWarnings({ "unused", "rawtypes" })
			@Override
			public int compare(CallRecordVo o1, CallRecordVo o2) {
				int flag = 0;
				int i = new Integer(o1.getVillageId()).compareTo(o2.getVillageId());
                if(i == 0){
                	Matcher matcher = Pattern.compile(
							"\\d+|[甲乙己丙丁]+|[一二三四五六七八九十]").matcher(
							o1.getDoorInfo());
					List listo1 = new ArrayList();
					while (matcher.find()) {
						// System.out.println(matcher.group());
						listo1.add(NumHelper.toLittleNum(matcher.group()));
					}
					Matcher matcher2 = Pattern.compile(
							"\\d+|[甲乙己丙丁]+|[一二三四五六七八九十]").matcher(
							o2.getDoorInfo());
					List listo2 = new ArrayList();
					while (matcher2.find()) {
						// System.out.println(matcher.group());
						listo2.add(NumHelper.toLittleNum(matcher2.group()));
					}
					if(listo1.size()>=1 && listo2.size() >=1){
						int j = new Integer((int) listo1.get(0)).compareTo(new Integer( (int) listo2.get(0)));
						if(j==0){
						  if(listo1.size()>=2 && listo2.size() >=2){
							  int k = new Integer((int) listo1.get(1)).compareTo(new Integer((int) listo2.get(1)));
							  if(k == 0){
								  if(listo1.size() >= 3 && listo2.size() >= 3 ){
									  int m = new Integer((int) listo1.get(2)).compareTo(new Integer((int) listo2.get(2)));
									  return m;
								  }
							  }
							  return k;
						  }
						}
						return j;
					}
                }
                return i;
                
			}
		});

		for (CallRecordVo param : list1) {

			System.out.println(param.toString());
		}
		
	}

  

/**
	  * 構造地區排序得字段
	  * @return
	  */
	private static List<CallRecordVo> createTestList() {
		List<CallRecordVo> list = new ArrayList<CallRecordVo>();
		CallRecordVo callVo = new CallRecordVo();
		callVo.setServerStationName("22");
		callVo.setVillageId(13);
		callVo.setVillageName("萬源里社區");
		callVo.setDoorInfo("44號樓一單元4號");
		list.add(callVo);
		CallRecordVo callVo1 = new CallRecordVo();
		callVo1.setServerStationName("22");
		callVo1.setVillageId(13);
		callVo1.setVillageName("萬源里社區");
		callVo1.setDoorInfo("32樓36單元5號");
		list.add(callVo1);

		CallRecordVo callVo2 = new CallRecordVo();
		callVo2.setServerStationName("22");
		callVo2.setVillageId(13);
		callVo2.setVillageName("萬源里社區");
		callVo2.setDoorInfo("46樓56單元4號");
		list.add(callVo2);
		
		CallRecordVo callVo3 = new CallRecordVo();
		callVo3.setServerStationName("22");
		callVo3.setVillageId(12);
		callVo3.setVillageName("梅源社區");
		callVo3.setDoorInfo("梅源裏9號樓2單元4號");
		list.add(callVo3);
		CallRecordVo callVo5 = new CallRecordVo();
		callVo5.setServerStationName("22");
		callVo5.setVillageId(12);
		callVo5.setVillageName("梅源社區");
		callVo5.setDoorInfo("梅源裏9號樓1單元48號");
		list.add(callVo5);
		CallRecordVo callVo6 = new CallRecordVo();
		callVo6.setServerStationName("22");
		callVo6.setVillageId(12);
		callVo6.setVillageName("梅源社區");
		callVo6.setDoorInfo("梅源裏9號樓2單元44號");
		list.add(callVo6);
		CallRecordVo callVo4 = new CallRecordVo();
		callVo4.setServerStationName("22");
		callVo4.setVillageId(12);
		callVo4.setVillageName("梅源社區");
		callVo4.setDoorInfo("四棟五單元十四號");
		list.add(callVo4);
		return list;
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章