객체 정렬

1267 단어
1. 자바를 실현한다.util.Comparator 인터페이스, int compare(Object o1, Object o2) 다시 쓰기 방법
public class CompareUtil implements Comparator<Object> {
	/**
	 *  , complexity , 
	 */
	@Override
	public int compare(Object o1, Object o2) {
		OwerProjectVO s1 = (OwerProjectVO) o1;
		OwerProjectVO s2 = (OwerProjectVO) o2;
		if (s1.getComplexity() < s2.getComplexity()) {
			return 1;
		}
		if (s1.getComplexity() > s2.getComplexity()) {
			return -1;
		}
		return 0;
	}

}

2. Ower ProjectVO 클래스 코드
public class OwerProjectVO {
	/**
	 *  
	 */
	private String name;
	/**
	 *  
	 */
	private double complexity;
	/**
	 *  
	 */
	private List<String> projectList;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getComplexity() {
		return complexity;
	}

	public void setComplexity(double complexity) {
		this.complexity = complexity;
	}

	public List<String> getProjectList() {
		return projectList;
	}

	public void setProjectList(List<String> projectList) {
		this.projectList = projectList;
	}

}

3. 호출하여 정렬하기
Collections.sort(owerProjectVOList, new CompareUtil());

좋은 웹페이지 즐겨찾기