Example usage for java.time LocalDate compareTo

List of usage examples for java.time LocalDate compareTo

Introduction

In this page you can find the example usage for java.time LocalDate compareTo.

Prototype

@Override 
public int compareTo(ChronoLocalDate other) 

Source Link

Document

Compares this date to another date.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = LocalDate.of(2014, 7, 1);
    System.out.println(a.compareTo(b));
    System.out.println(a.compareTo(a));
    System.out.println(b.compareTo(a));
}

From source file:com.romeikat.datamessie.core.base.util.publishedDates.PublishedDateStrategy.java

private List<LocalDate> getPublishedDatesForProcessing(final SharedSessionContract ssc,
        final DocumentsFilterSettings dfs) {
    final LocalDate fromDate = dfs.getFromDate();
    final LocalDate toDate = dfs.getToDate();
    // Both dates provided => all dates in range (descending)
    if (fromDate != null && toDate != null) {
        return DateUtil.getLocalDatesBetween(toDate, fromDate);
    }/*from   w  ww. ja v a2s.  c  om*/
    // Otherwise => all published dates that actually exist (descending)
    else {
        final Set<LocalDate> allPublishedDates = getAllPublishedDates(ssc);
        final Predicate<LocalDate> publishedDatePredicate = new Predicate<LocalDate>() {
            @Override
            public boolean apply(final LocalDate publishedDate) {
                final boolean fromDateMatch = fromDate == null || publishedDate.compareTo(fromDate) >= 0;
                final boolean toDateMatch = toDate == null || publishedDate.compareTo(toDate) <= 0;
                return fromDateMatch && toDateMatch;
            }
        };
        final Collection<LocalDate> publishedDates = Collections2.filter(allPublishedDates,
                publishedDatePredicate);
        // Sort descending
        final List<LocalDate> publishedDatesSorted = Lists.newArrayList(publishedDates);
        Collections.sort(publishedDatesSorted);
        Collections.reverse(publishedDatesSorted);
        // Done
        return publishedDatesSorted;
    }
}