Java记事本二

 
//下面代码为两组分类示例
private static void test13() {
		
		List<Object[]> mstamps = new ArrayList<>();
		Object[] o1 = {15,6,4};
		Object[] o2 = {15,6,4};
		Object[] o3 = {15,6,4};
		Object[] o4 = {21,7,4};
		Object[] o5 = {21,7,4};
		Object[] o6 = {21,7,4};
		Object[] o7 = {23,8,5};
		Object[] o8 = {23,9,5};
		Object[] o9 = {23,0,5};
		mstamps.add(o1);mstamps.add(o2);mstamps.add(o3);mstamps.add(o4);mstamps.add(o5);mstamps.add(o6);
		mstamps.add(o7);mstamps.add(o8);mstamps.add(o9);
		
		boolean hasMemStamp = false;
//		Map<Long, List<Long>> stampsList = null;
		Map<Long, Map<Long,List<Long>>> stampsList = null;
		if (null != mstamps && mstamps.size() > 0) {
			hasMemStamp = true;
			stampsList = new HashMap<>();
			Map<Long,List<Long>> map = new LinkedHashMap<>();
			List<Long> sList = new ArrayList<>();
			Long tempSCId = Long.valueOf(mstamps.get(0)[2] + "");
			Long tempMSCId = Long.valueOf(mstamps.get(0)[0] + "");
			for (int i = 0; i < mstamps.size(); i++) {
				Object[] o = mstamps.get(i);
				if (tempSCId.equals(Long.valueOf(o[2] + ""))) {
					if (tempMSCId.equals(Long.valueOf(o[0] + ""))) {
						sList.add(Long.valueOf(o[1] + ""));
					} else {
						map.put(tempMSCId, sList);
						tempMSCId = Long.valueOf(o[0] + "");
						sList = new ArrayList<>();
						sList.add(Long.valueOf(o[1] + ""));
					}
				} else {
					map.put(tempMSCId, sList);
					stampsList.put(tempSCId, map);
					tempMSCId = Long.valueOf(o[0] + "");
					tempSCId = Long.valueOf(o[2] + "");
					map = new LinkedHashMap<>();
					sList = new ArrayList<>();
					sList.add(Long.valueOf(o[1] + ""));
					map.put(tempMSCId, sList);
				}
			}
			stampsList.put(tempSCId, map);
		}
		System.out.println(stampsList);
		
		if (hasMemStamp && null != stampsList) {
			List<StampcardVo> sv = new ArrayList<>();
			Map<Long, List<Long>> map = stampsList.get(4l);
			Set<Entry<Long, List<Long>>> entrySet = map.entrySet();
			for (Entry<Long, List<Long>> entry : entrySet) {
				StampcardVo scv = new StampcardVo();
				scv.setStampcardid(entry.getKey());
				scv.setCollectedstamps(entry.getValue());
				sv.add(scv);
			}
			//s.getStampcards().addAll(sv);
			System.out.println(sv);
		}
	}

stampcardvo
public class StampcardVo extends BaseObject {

	private static final long serialVersionUID = -514301494989338883L;
	
	private Long stampcardid;
	
	private List<Long> collectedstamps = new ArrayList<>();

	public Long getStampcardid() {
		return stampcardid;
	}

	public void setStampcardid(Long stampcardid) {
		this.stampcardid = stampcardid;
	}

	public List<Long> getCollectedstamps() {
		return collectedstamps;
	}

	public void setCollectedstamps(List<Long> collectedstamps) {
		this.collectedstamps = collectedstamps;
	}
	
	
}
private final static List<Object[]> doData(List<Object[]> result) {
		if (null == result || result.size() < 0) {
			return result;
		}
		List<Object[]> ret = new ArrayList<Object[]>();
		sortTransation(result);
		Object[] temp = result.get(0);
		String firstSku = temp[4].toString();
		String firstInvoiceNo = temp[2].toString();
		int sum = 0;
		for (Object[] t : result) {
			String newSku = t[4].toString();
			String newInV = t[2].toString();
			if (firstSku.equals(newSku) && firstInvoiceNo.equals(newInV)) {
				temp = t;
				sum += (null == t[6] || "".equals(t[6].toString()) ? 0 : Integer.parseInt(t[6].toString()));
				temp[6] = sum;
				continue;
			} else {
				temp[6] = sum > 0 ? sum : (null == t[6] || "".equals(temp[6].toString()) ? 0 : Integer.parseInt(temp[6].toString()));
				sum = (null == t[6] || "".equals(t[6].toString()) ? 0 : Integer.parseInt(t[6].toString()));
				ret.add(temp);
				firstSku = t[4].toString();
				firstInvoiceNo = t[2].toString();
				temp = t;
			}
		}
		ret.add(temp);
		sortDate(ret);
		return ret;
	}

上面代码为单组分类示例

 ////////////////////////////////////

代码执行顺序

package com.dennis.test.init;

public class Test执行顺序 {
	private int abc = getABC();
	static {
		System.out.println("11111111111111111111");
	}
	private static int count1 = 3;
	private static int count0 = 6;
	private static Test执行顺序 tester = new Test执行顺序();//
	private static int count3 = getCount3();
	private int xxx = 112;
	private static int count2 = 2;
	{
		System.out.println("3333333333333333333333333");
	}
	static {
		System.out.println("00000000066666666666666666666666666");
	}
	public Test执行顺序() {
		count1++;count2++;count3++;
		System.out.println("4444444444444444444444444444\t" + count1 + "\t" + count2);
	}
	private int getABC() {
		System.out.println("22222222222222222222222222222");
		return 5;
	}
	private static int getCount3() {
		System.out.println("55555555555555555555555555");
		return 12;
	}
	private static Test执行顺序 getTester() {
		System.out.println("888888888888888888888888\t" + tester.count3);
		return tester;
	}
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		//Test执行顺序 tester = new Test执行顺序();
		System.out.println("7777777777777777777777\t" + count2);
		Test执行顺序.getTester();
		Class.forName("com.dennis.test.init.FinalClass");
		FinalClass f = (FinalClass) Class.forName("com.dennis.test.init.FinalClass").newInstance();
		f.print();
	}
	static {
		System.out.println("666666666666666666666666");
	}
}





//////////////////
11111111111111111111
22222222222222222222222222222
3333333333333333333333333
4444444444444444444444444444	4	1
55555555555555555555555555
00000000066666666666666666666666666
666666666666666666666666
7777777777777777777777	2
888888888888888888888888	12
===========ccc============26
===========dddd============
===========eeeee============6
FinalClass print method 9
//下面代码为两组分类示例
private static void test13() {
		
		List<Object[]> mstamps = new ArrayList<>();
		Object[] o1 = {15,6,4};
		Object[] o2 = {15,6,4};
		Object[] o3 = {15,6,4};
		Object[] o4 = {21,7,4};
		Object[] o5 = {21,7,4};
		Object[] o6 = {21,7,4};
		Object[] o7 = {23,8,5};
		Object[] o8 = {23,9,5};
		Object[] o9 = {23,0,5};
		mstamps.add(o1);mstamps.add(o2);mstamps.add(o3);mstamps.add(o4);mstamps.add(o5);mstamps.add(o6);
		mstamps.add(o7);mstamps.add(o8);mstamps.add(o9);
		
		boolean hasMemStamp = false;
//		Map<Long, List<Long>> stampsList = null;
		Map<Long, Map<Long,List<Long>>> stampsList = null;
		if (null != mstamps && mstamps.size() > 0) {
			hasMemStamp = true;
			stampsList = new HashMap<>();
			Map<Long,List<Long>> map = new LinkedHashMap<>();
			List<Long> sList = new ArrayList<>();
			Long tempSCId = Long.valueOf(mstamps.get(0)[2] + "");
			Long tempMSCId = Long.valueOf(mstamps.get(0)[0] + "");
			for (int i = 0; i < mstamps.size(); i++) {
				Object[] o = mstamps.get(i);
				if (tempSCId.equals(Long.valueOf(o[2] + ""))) {
					if (tempMSCId.equals(Long.valueOf(o[0] + ""))) {
						sList.add(Long.valueOf(o[1] + ""));
					} else {
						map.put(tempMSCId, sList);
						tempMSCId = Long.valueOf(o[0] + "");
						sList = new ArrayList<>();
						sList.add(Long.valueOf(o[1] + ""));
					}
				} else {
					map.put(tempMSCId, sList);
					stampsList.put(tempSCId, map);
					tempMSCId = Long.valueOf(o[0] + "");
					tempSCId = Long.valueOf(o[2] + "");
					map = new LinkedHashMap<>();
					sList = new ArrayList<>();
					sList.add(Long.valueOf(o[1] + ""));
					map.put(tempMSCId, sList);
				}
			}
			stampsList.put(tempSCId, map);
		}
		System.out.println(stampsList);
		
		if (hasMemStamp && null != stampsList) {
			List<StampcardVo> sv = new ArrayList<>();
			Map<Long, List<Long>> map = stampsList.get(4l);
			Set<Entry<Long, List<Long>>> entrySet = map.entrySet();
			for (Entry<Long, List<Long>> entry : entrySet) {
				StampcardVo scv = new StampcardVo();
				scv.setStampcardid(entry.getKey());
				scv.setCollectedstamps(entry.getValue());
				sv.add(scv);
			}
			//s.getStampcards().addAll(sv);
			System.out.println(sv);
		}
	}

stampcardvo
public class StampcardVo extends BaseObject {

	private static final long serialVersionUID = -514301494989338883L;
	
	private Long stampcardid;
	
	private List<Long> collectedstamps = new ArrayList<>();

	public Long getStampcardid() {
		return stampcardid;
	}

	public void setStampcardid(Long stampcardid) {
		this.stampcardid = stampcardid;
	}

	public List<Long> getCollectedstamps() {
		return collectedstamps;
	}

	public void setCollectedstamps(List<Long> collectedstamps) {
		this.collectedstamps = collectedstamps;
	}
	
	
}
private final static List<Object[]> doData(List<Object[]> result) {
		if (null == result || result.size() < 0) {
			return result;
		}
		List<Object[]> ret = new ArrayList<Object[]>();
		sortTransation(result);
		Object[] temp = result.get(0);
		String firstSku = temp[4].toString();
		String firstInvoiceNo = temp[2].toString();
		int sum = 0;
		for (Object[] t : result) {
			String newSku = t[4].toString();
			String newInV = t[2].toString();
			if (firstSku.equals(newSku) && firstInvoiceNo.equals(newInV)) {
				temp = t;
				sum += (null == t[6] || "".equals(t[6].toString()) ? 0 : Integer.parseInt(t[6].toString()));
				temp[6] = sum;
				continue;
			} else {
				temp[6] = sum > 0 ? sum : (null == t[6] || "".equals(temp[6].toString()) ? 0 : Integer.parseInt(temp[6].toString()));
				sum = (null == t[6] || "".equals(t[6].toString()) ? 0 : Integer.parseInt(t[6].toString()));
				ret.add(temp);
				firstSku = t[4].toString();
				firstInvoiceNo = t[2].toString();
				temp = t;
			}
		}
		ret.add(temp);
		sortDate(ret);
		return ret;
	}

上面代码为单组分类示例

 ////////////////////////////////////

代码执行顺序

package com.dennis.test.init;

public class Test执行顺序 {
	private int abc = getABC();
	static {
		System.out.println("11111111111111111111");
	}
	private static int count1 = 3;
	private static int count0 = 6;
	private static Test执行顺序 tester = new Test执行顺序();//
	private static int count3 = getCount3();
	private int xxx = 112;
	private static int count2 = 2;
	{
		System.out.println("3333333333333333333333333");
	}
	static {
		System.out.println("00000000066666666666666666666666666");
	}
	public Test执行顺序() {
		count1++;count2++;count3++;
		System.out.println("4444444444444444444444444444\t" + count1 + "\t" + count2);
	}
	private int getABC() {
		System.out.println("22222222222222222222222222222");
		return 5;
	}
	private static int getCount3() {
		System.out.println("55555555555555555555555555");
		return 12;
	}
	private static Test执行顺序 getTester() {
		System.out.println("888888888888888888888888\t" + tester.count3);
		return tester;
	}
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		//Test执行顺序 tester = new Test执行顺序();
		System.out.println("7777777777777777777777\t" + count2);
		Test执行顺序.getTester();
		Class.forName("com.dennis.test.init.FinalClass");
		FinalClass f = (FinalClass) Class.forName("com.dennis.test.init.FinalClass").newInstance();
		f.print();
	}
	static {
		System.out.println("666666666666666666666666");
	}
}





//////////////////
11111111111111111111
22222222222222222222222222222
3333333333333333333333333
4444444444444444444444444444	4	1
55555555555555555555555555
00000000066666666666666666666666666
666666666666666666666666
7777777777777777777777	2
888888888888888888888888	12
===========ccc============26
===========dddd============
===========eeeee============6
FinalClass print method 9

猜你喜欢

转载自xiaobo.iteye.com/blog/2406013