package com.blueland.bpm.identity.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.blueland.bpm.identity.model.Org;

public class ComparatorOrg implements Comparator<Org>{

	@Override
	public int compare(Org org1, Org org2) {
		Integer val1=0;
		Integer val2=0;
		if(org1==null||org1.getOrgSort()==null){
			return val2;
		}
		if(org2==null||org2.getOrgSort()==null){
			return val1;
		}
		val1=org1.getOrgSort();
		val2=org2.getOrgSort();
		return val1.compareTo(val2);
	}
	public static void main(String[] args) {
		List<Org> ts=new ArrayList<Org>();
		Org t1=new Org();
		t1.setOrgId("o1");t1.setOrgSort(3);
		Org t2=new Org();
		t2.setOrgId("o2");t2.setOrgSort(2);
		Org t3=new Org();
		t3.setOrgId("o3");t3.setOrgSort(1);
		ts.add(t1);ts.add(t2);ts.add(t3);
		
		
		System.out.println("before----");
		for (Org t : ts) {
			System.out.println(t.getOrgId());
		}
	
		Collections.sort(ts,new ComparatorOrg());
		System.out.println("after----");
		for (Org t : ts) {
			System.out.println(t.getOrgId());
		}
	}
	
	

}

