package com.blueland.ebpm.util;

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

import org.activiti.bpmn.model.ExpandProperty;
import org.activiti.engine.impl.pvm.process.TransitionImpl;

import com.blueland.bpm.engine.util.ComparatorTransition;
import com.blueland.ebpm.bean.ActivityDefinitionBean;


public class ComparatorActivity  implements Comparator<ActivityDefinitionBean>{

	@Override
	public int compare(ActivityDefinitionBean pvm1, ActivityDefinitionBean pvm2) {
		Integer val1=pvm1.getActDefOrder();
		Integer val2=pvm2.getActDefOrder();
		if(val1==null){
			val1=99;
		}
		if(val2==null){
			val2=99;
		}
		return val1.compareTo(val2);
	}
	public static void main(String[] args) {
		List<TransitionImpl> ts=new ArrayList<TransitionImpl>();
		TransitionImpl t1=new TransitionImpl("r1",null);
		TransitionImpl t2=new TransitionImpl("r2",null);
		TransitionImpl t3=new TransitionImpl("r3",null);
		ts.add(t1);
		ts.add(t2);
		ts.add(t3);
			ExpandProperty expandProperty1=new ExpandProperty();
			expandProperty1.setId("TRANSITION_DISPLAY_ORDER");
			expandProperty1.setValue("3");
			List aa=new ArrayList();
			aa.add(expandProperty1);
		//t1.setExpandPropertys(aa);
			ExpandProperty expandProperty2=new ExpandProperty();
			expandProperty2.setId("TRANSITION_DISPLAY_ORDER");
			expandProperty2.setValue("1");
			List aa2=new ArrayList();
			aa2.add(expandProperty2);
		t2.setExpandPropertys(aa2);
		
			ExpandProperty expandProperty3=new ExpandProperty();
			expandProperty3.setId("TRANSITION_DISPLAY_ORDER");
			expandProperty3.setValue("2");
			List aa3=new ArrayList();
			aa3.add(expandProperty3);
		t3.setExpandPropertys(aa3);
		
		System.out.println("before----");
		for (TransitionImpl t : ts) {
			System.out.println(t.getId());
		}
	
		Collections.sort(ts,new ComparatorTransition());
		System.out.println("after----");
		for (TransitionImpl t : ts) {
			System.out.println(t.getId());
		}
	}
	
	

}
