티스토리 뷰
import java.util.Collections;
import java.util.ArrayList;
import java.util.Comparator;
public class Movie implements Comparable<Movie>
{
public Movie(String t, String d, Integer r){
title = t;
director = d;
rating = r;
}
public int compareTo(Movie m){
return title.compareTo(m.getTitle());
}
public String getTitle(){
return title;
}
public String getDirector(){
return director;
}
public Integer getRating(){
return rating;
}
private String title;
private String director;
private Integer rating;
}
class MovieSortTest
{
public static void main(String[] args){
ArrayList<Movie> arr = new ArrayList<Movie>();
arr.add( new Movie("atitle", "cdirector1", new Integer("3")));
arr.add( new Movie("ztitle", "adirector2", new Integer("2")));
arr.add( new Movie("ytitle", "bdirector3", new Integer("1")));
for(Movie m : arr){
System.out.println("initial value \t\t" + m.getTitle());
}
Collections.sort(arr);
for(Movie a : arr){
System.out.println( "sorted by compareTo - Title : " + a.getTitle());
}
MovieTitleCompare mtitleComp = new MovieTitleCompare();
Collections.sort(arr, mtitleComp);
for(Movie a : arr){
System.out.println( "sorted by compare-Title : " + a.getTitle() + "\t\t" + a.getDirector() + ":" + a.getRating());
}
MovieDirectorCompare direcComp = new MovieDirectorCompare();
Collections.sort(arr, direcComp);
for(Movie a : arr){
System.out.println( "sorted by compare - Director : " + a.getDirector()+ "\t\t" + a.getTitle() + ":" + a.getRating());
}
MovieRatingCompare rateComp = new MovieRatingCompare();
Collections.sort(arr, rateComp);
for(Movie a : arr){
System.out.println( "sorted by compare - Rating : " + a.getRating()+ "\t\t" + a.getTitle() + ":" + a.getDirector());
}
}
}
class MovieTitleCompare implements Comparator<Movie>
{
public int compare(Movie m1, Movie m2){
return m1.getTitle().compareTo(m2.getTitle());
}
}
class MovieDirectorCompare implements Comparator<Movie>
{
public int compare(Movie m1, Movie m2){
return m1.getDirector().compareTo(m2.getDirector());
}
}
class MovieRatingCompare implements Comparator<Movie>
{
public int compare(Movie m1, Movie m2){
return m1.getRating().compareTo(m2.getRating());
}
}
- Total
- Today
- Yesterday
- MSSQL
- 셋업
- 아이프레임
- 프로시져
- 정규식
- 배열 변환
- 오라클
- 연차
- 리사이즈
- NSIS
- 프로시저
- 이벤트 상속
- ajax
- SQL
- 팝업
- scrollHeight
- unique
- 디비링크
- Setup
- 윈도우 인증
- width
- 스크립트
- DB링크
- height
- 이벤트
- 문자열
- 크롬
- 에누리
- 제약조건
- onblur
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |