比对的一个工具类

package study.corejava.string;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestUtil {
	public static void main(String[] args) {
		Map<String, String> a0 = new HashMap<String, String>();
		a0.put("test", "1234561");
		Map<String, String> a1 = new HashMap<String, String>();
		a1.put("test", "1234561");
		Map<String, String> a2 = new HashMap<String, String>();
		a2.put("test", "1234562");
		Map<String, String> a3 = new HashMap<String, String>();
		a3.put("test", "1234563");
		Map<String, String> a4 = new HashMap<String, String>();
		a4.put("test", "1234564");
		Map<String, String> a5 = new HashMap<String, String>();
		a5.put("test", "1234564");
		Map<String, String> a6 = new HashMap<String, String>();
		a6.put("test", "1234563");
		Map<String, String> a7= new HashMap<String, String>();
		a7.put("test", "1234562");
		Map<String, String> a8 = new HashMap<String, String>();
		a8.put("test", "1234561");
		Map<String, String> a9 = new HashMap<String, String>();
		a9.put("test", "1234561");
		List<Map<String, String>> param = new ArrayList<Map<String, String>>();
		param.add(a0);
		param.add(a1);
		param.add(a2);
		param.add(a3);
		param.add(a4);
		param.add(a5);
		param.add(a6);
		param.add(a7);
		param.add(a8);
		param.add(a9);
		List<List<Integer>> result = new ArrayList();
		String demp = "";
		for (int i = 0; i < param.size(); i++) {
			String[] demps = demp.split(",");
			if (breakFor(demps, i)) {
				continue;
			}
			List<Integer> result_ = new ArrayList();
			String startTemp = param.get(i).get("test");
			if (startTemp == null || startTemp.length() <= 0) {
				continue;
			}
			result_.add(i);
			for (int j = i + 1; j < param.size(); j++) {
				if (breakFor(demps, j)) {
					continue;
				}
				String endTemp = param.get(j).get("test");
				if (startTemp.equals(endTemp)) {
					result_.add(j);
					demp += (j + ",");
				}
			}
			if (result_.size() > 1) {
				result.add(result_);
				
			}
		}
		for (List<Integer> test : result) {
			for (Integer i : test) {
				System.out.print(i + ",");
			}
			System.out.println();
		}
	}

	public static boolean breakFor(String[] strs, int i) {
		for (String s : strs) {
			if (s.equals(String.valueOf(i))) {
				return true;
			}
		}
		return false;
	}
}

你可能感兴趣的:(java)