Java Code Examples for java.sql.Time#compareTo()

The following examples show how to use java.sql.Time#compareTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeType.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: TimeType.java    From tddl with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: SectionDecorator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
                }
        }
    };
}
 
Example 4
Source File: SectionDecorator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * 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;
                }
        }
    };
}