下面列出了java.sql.Time#compareTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int compare(Object o1, Object o2) {
if (o1 == o2) {
return 0;
}
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
Time d1 = convertFrom(o1);
Time d2 = convertFrom(o2);
return d1.compareTo(d2);
}
@Override
public int compare(Object o1, Object o2) {
if (o1 == o2) {
return 0;
}
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
Time d1 = convertFrom(o1);
Time d2 = convertFrom(o2);
return d1.compareTo(d2);
}
/**
* Compares SectionDecorators by the section's first meeting times.
*
* @param sortAscending
* @return
*/
public static final Comparator<SectionDecorator> getTimeComparator(final boolean sortAscending) {
return new Comparator<SectionDecorator>() {
public int compare(SectionDecorator section1, SectionDecorator section2) {
// First compare the category name, then compare the time
int categoryNameComparison = section1.getCategory().compareTo(section2.getCategory());
if(categoryNameComparison == 0) {
// These are in the same category, so compare by the first meeting time
List meetings1 = section1.getDecoratedMeetings();
List meetings2 = section2.getDecoratedMeetings();
MeetingDecorator meeting1 = (MeetingDecorator)meetings1.get(0);
MeetingDecorator meeting2 = (MeetingDecorator)meetings2.get(0);
Time startTime1 = meeting1.getStartTime();
Time startTime2 = meeting2.getStartTime();
if(startTime1 == null && startTime2 != null) {
return sortAscending? -1 : 1 ;
}
if(startTime2 == null && startTime1 != null) {
return sortAscending? 1 : -1 ;
}
if(startTime1 == null && startTime2 == null ||
startTime1.equals(startTime2)) {
return getTitleComparator(sortAscending).compare(section1, section2);
}
return sortAscending ? startTime1.compareTo(startTime2) : startTime2.compareTo(startTime1);
} else {
return categoryNameComparison;
}
}
};
}
/**
* Compares SectionDecorators by the section's first meeting times.
*
* @param sortAscending
* @return
*/
public static final Comparator<SectionDecorator> getTimeComparator(final boolean sortAscending) {
return new Comparator<SectionDecorator>() {
public int compare(SectionDecorator section1, SectionDecorator section2) {
// First compare the category name, then compare the time
int categoryNameComparison = section1.getCategory().compareTo(section2.getCategory());
if(categoryNameComparison == 0) {
// These are in the same category, so compare by the first meeting time
List meetings1 = section1.getDecoratedMeetings();
List meetings2 = section2.getDecoratedMeetings();
MeetingDecorator meeting1 = (MeetingDecorator)meetings1.get(0);
MeetingDecorator meeting2 = (MeetingDecorator)meetings2.get(0);
Time startTime1 = meeting1.getStartTime();
Time startTime2 = meeting2.getStartTime();
if(startTime1 == null && startTime2 != null) {
return sortAscending? -1 : 1 ;
}
if(startTime2 == null && startTime1 != null) {
return sortAscending? 1 : -1 ;
}
if(startTime1 == null && startTime2 == null ||
startTime1.equals(startTime2)) {
return getTitleComparator(sortAscending).compare(section1, section2);
}
return sortAscending ? startTime1.compareTo(startTime2) : startTime2.compareTo(startTime1);
} else {
return categoryNameComparison;
}
}
};
}