Example usage for org.joda.time LocalDate compareTo

List of usage examples for org.joda.time LocalDate compareTo

Introduction

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

Prototype

public int compareTo(ReadablePartial partial) 

Source Link

Document

Compares this partial with another returning an integer indicating the order.

Usage

From source file:edu.harvard.med.screensaver.service.libraries.PlateUpdater.java

License:Open Source License

private void plateCreated(Plate plate, AdministrativeActivity updateActivity) {
    plate.setPlatedActivity(updateActivity);
    LocalDate datePlated = updateActivity.getDateOfActivity();
    plate.getCopy().setDatePlated(datePlated);
    LocalDate dateLibraryScreenable = plate.getCopy().getLibrary().getDateScreenable();
    if (dateLibraryScreenable == null || datePlated.compareTo(dateLibraryScreenable) < 0) {
        plate.getCopy().getLibrary().setDateScreenable(datePlated);
    }/* w  ww. j  a  v a 2s .c o  m*/
}

From source file:edu.harvard.med.screensaver.ui.arch.datatable.column.DateColumn.java

License:Open Source License

@Override
protected Comparator<R> getAscendingComparator() {
    return new NullSafeComparator<R>() {
        NullSafeComparator<LocalDate> _dateComparator = new NullSafeComparator<LocalDate>() {
            @Override/*from  w  w w  .jav a 2 s.  co  m*/
            protected int doCompare(LocalDate d1, LocalDate d2) {
                return d1.compareTo(d2);
            }
        };

        @Override
        protected int doCompare(R o1, R o2) {
            return _dateComparator.compare(getDate(o1), getDate(o2));
        }
    };
}

From source file:edu.harvard.med.screensaver.ui.screens.ScreenDetailViewer.java

License:Open Source License

public DataModel getBillingItemsDataModel() {
    ArrayList<BillingItem> billingItems = new ArrayList<BillingItem>();
    billingItems.addAll(getEntity().getBillingItems());
    Collections.sort(billingItems, new Comparator<BillingItem>() {
        public int compare(BillingItem bi1, BillingItem bi2) {
            LocalDate one = bi1.getDateSentForBilling();
            LocalDate two = bi2.getDateSentForBilling();
            if (one != null && two != null) {
                return one.compareTo(two);
            } else if (one != null) {
                return -1;
            } else if (two != null) {
                return 1;
            } else { // amount is guaranteed non-null, but still
                return bi1.getAmount().compareTo(bi2.getAmount());
            }//from w ww.j  av a 2s. c  o  m
        }
    });
    return new ListDataModel(billingItems);
}

From source file:edu.harvard.med.screensaver.ui.screens.ScreenDetailViewer.java

License:Open Source License

@Override
protected boolean validateEntity(Screen screen) {
    if (!_screenDao.isScreenFacilityIdUnique(screen)) {
        showMessage("duplicateEntity", "Screen ID");
        return false;
    }/*from w  w w .ja  v a 2s . c o  m*/

    LocalDate max = screen.getMaxAllowedDataPrivacyExpirationDate();
    LocalDate min = screen.getMinAllowedDataPrivacyExpirationDate();

    if (max != null && min != null) {
        if (max.compareTo(min) < 0) {
            showMessage("screens.dataPrivacyExpirationDateOrderError", min, max);
            return false;
        }
    }

    boolean valid = true;
    if (!getPerturbagenMolarConcentrationSelector().isEmpty()) {
        try {
            MolarConcentration.makeConcentration(
                    getPerturbagenMolarConcentrationSelector().getValue().toString(),
                    getPerturbagenMolarConcentrationSelector().getSelectorBean().getSelection());
        } catch (ArithmeticException e) {
            showFieldInputError(
                    "Molar Concentration: number format error: allowed range (>= 1.0 pM, < 10.0 M), in 1 pM increments",
                    e.getLocalizedMessage());
            valid = false;
        } catch (Exception e) {
            showFieldInputError("Molar Concentration",
                    StringUtils.isEmpty(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            valid = false;
        }
    }

    // At ICCB-L, the screen DSL 2 is not an option, so we hide it at the UI level; we maintain it in our model for consistency with the SM screen DSLs
    if (getApplicationProperties().isFacility(IccblScreensaverConstants.FACILITY_KEY)) {
        if (screen.getScreenType() == ScreenType.RNAI) {
            if (screen.getDataSharingLevel() == ScreenDataSharingLevel.MUTUAL_POSITIVES) {
                showMessage("screens.illegalDataSharingLevel", screen.getDataSharingLevel(),
                        "for RNAi screens");
                valid = false;
            }
        }
    }

    return valid && super.validateEntity(screen);
}

From source file:energy.usef.agr.pbcfeederimpl.PbcFeederService.java

License:Apache License

private void setObservedAndForecast(PbcStubDataDto pbcStubData, int ptuDuration, int dtuDuration,
        UdiPortfolioDto udiPortfolioDto, int currentPtuIndex) {

    LocalDate currentDate = DateTimeUtil.getCurrentDate();

    int dtusPerPtu = ptuDuration / dtuDuration;
    int ptuIndex = pbcStubData.getPtuContainer().getPtuIndex();
    int startDtu = ((ptuIndex - 1) * dtusPerPtu) + 1; // inclusive
    int endDtu = startDtu + dtusPerPtu - 1; // inclusive

    for (int dtuIndex = startDtu; dtuIndex <= endDtu; dtuIndex++) {
        PowerContainerDto powerContainerDto = udiPortfolioDto.getUdiPowerPerDTU().get(dtuIndex);
        if (powerContainerDto == null || powerContainerDto.getPeriod().toDateTimeAtStartOfDay().toDate()
                .compareTo(pbcStubData.getPtuContainer().getPtuDate()) != 0
                && powerContainerDto.getTimeIndex() != dtuIndex) {
            continue;
        }/*from   w  w  w . j a  va  2s . co m*/

        // only set observed if the ptuIndex and dtu period is equal to the previous ptu date and ptu index
        // ideally you only set observed valued for udi's with reporting capabilities
        if (currentPtuIndex == ptuIndex && currentDate.compareTo(powerContainerDto.getPeriod()) == 0) {
            updatePowerValue(powerContainerDto.getObserved(), pbcStubData.getPvLoadActual());
        } else {
            // only set forecast for future ptu indexes
            if (ptuIndex > currentPtuIndex || powerContainerDto.getPeriod().compareTo(currentDate) > 0) {
                updatePowerValue(powerContainerDto.getForecast(), pbcStubData.getPvLoadForecast());
            }
        }
    }
}

From source file:energy.usef.agr.workflow.step.AgrNonUdiReOptimizePortfolioStub.java

License:Apache License

private void calculatePortfolioForecast(
        Map<String, List<ConnectionPortfolioDto>> connectionPortfolioPerConnectionGroup,
        Map<String, Map<Integer, BigDecimal>> potentialFlexFactorPerPtuPerConnectionGroup, LocalDate ptuDate,
        LocalDate currentDate, final int currentPtuIndex) {
    boolean isAfterToday = ptuDate.compareTo(currentDate) > 0;
    connectionPortfolioPerConnectionGroup
            .forEach((connectionGroupId, connectionPortfolioList) -> connectionPortfolioList.stream()
                    .flatMap(connectionPortfolioDTO -> connectionPortfolioDTO.getConnectionPowerPerPTU()
                            .entrySet().stream())
                    .filter(entry -> isAfterToday || entry.getKey() >= currentPtuIndex).forEach(entry -> {
                        Integer ptuIndex = entry.getKey();
                        ForecastPowerDataDto forecastPowerData = entry.getValue().getForecast();

                        processxFlexIntoForecast(potentialFlexFactorPerPtuPerConnectionGroup, connectionGroupId,
                                ptuIndex, forecastPowerData);

                    }));/*  ww w  .j  a v a2s .c o  m*/
}

From source file:energy.usef.agr.workflow.step.AgrReOptimizePortfolioStub.java

License:Apache License

private void calculatePortfolioForecast(
        Map<String, List<ConnectionPortfolioDto>> connectionPortfolioPerConnectionGroup,
        Map<String, Map<Integer, BigDecimal>> potentialFlexFactorPerPtuPerConnectionGroup, LocalDate ptuDate,
        int currentPtuIndex, int ptuDuration) {
    final LocalDate currentDate = DateTimeUtil.getCurrentDate();
    connectionPortfolioPerConnectionGroup
            .forEach((connectionGroupId, connectionPortfolioList) -> potentialFlexFactorPerPtuPerConnectionGroup
                    .get(connectionGroupId).forEach((ptuIndex, factor) -> {
                        // only for future period / ptu indices
                        if ((ptuDate.compareTo(currentDate) > 0 || ptuIndex >= currentPtuIndex)
                                && factor.compareTo(BigDecimal.ZERO) != 0) {
                            connectionPortfolioList.forEach(connectionPortfolioDTO -> divideFlexOverUdis(
                                    connectionPortfolioDTO, factor, ptuIndex, ptuDuration));
                        }/*w w  w  .  ja  va  2 s .co  m*/
                    }));
}

From source file:fi.vm.sade.osoitepalvelu.kooste.route.dto.helpers.KoodistoDateHelper.java

License:EUPL

public static boolean isPaivaVoimassaValilla(LocalDate pvm, LocalDate voimassaAlkuPvm,
        LocalDate voimassaLoppuPvm) {
    if (voimassaAlkuPvm != null && voimassaLoppuPvm != null) {
        // Onko annettu pivmr aikavlill?
        return (pvm.compareTo(voimassaAlkuPvm) >= 0) && (pvm.compareTo(voimassaLoppuPvm) <= 0);
    } else if (voimassaAlkuPvm != null) {
        return (pvm.compareTo(voimassaAlkuPvm) >= 0);
    } else if (voimassaLoppuPvm != null) {
        return (pvm.compareTo(voimassaLoppuPvm) <= 0);
    } else {//  w ww . ja va 2  s . c om
        // Aina voimassa, koska rajoja ei ole asetettu
        return true;
    }
}

From source file:gg.db.datamodel.Period.java

License:Open Source License

/**
 * Is the specified period valid?//from www.ja va2s  . co  m
 * @param startDate Start date of the period
 * @param endDate End date of the period
 * @param periodType Type of the period
 * @return <B>true</B> if the period is valid (or if startDate=endDate=periodType=null), <B>false</B> otherwise<BR/>
 * To be valid, a period has to be a "full" period:
 * <UL>
 * <LI> For each type of period: Start date > End date</LI>
 * <LI> For DAY period: number of days between Start date and End date = 0<BR/>
 * Example: <I>From 12/30/2005 to 12/30/2005</I></LI>
 * <LI> For WEEK period: number of days between Start date and End date = 6<BR/>
 * The period has to start on MONDAY<BR/>
 * The period has to end on SUNDAY<BR/>
 * Example: <I>From 12/01/2005 to 12/18/2005</I></LI>
 * <LI> For MONTH period: number of month between Start date and End date = 0<BR/>
 * The period has to start on the first day of the month (05/01/2006)<BR/>
 * The period has to end on the last day of the month (05/31/2006)<BR/>
 * Number of months between Start date - 1 day and End date = 1<BR/>
 * Number of months between Start date and End date + 1 day = 1<BR/>
 * Example: <I>From 03/01/2005 to 03/31/2005</I></LI>
 * <LI> For YEAR period: number of years between Start date and End date = 0<BR/>
 * The period has to start on the first day of the first month (01/01/2006)<BR/>
 * The period has to end in December<BR/>
 * The period has to end on the last day of the last month (12/31/2006)<BR/>
 * Number of years between Start date - 1 day and End date = 1<BR/>
 * Number of years between Start date and End date + 1 day = 1<BR/>
 * Example: <I>From 01/01/2006 to 12/31/2006</I></LI>
 * </UL>
 */
private boolean isPeriodValid(LocalDate startDate, LocalDate endDate, PeriodType periodType) {
    boolean periodValid = true; // Is the period valid

    // Check if Start date < End date
    if (startDate != null && endDate != null && startDate.compareTo(endDate) > 0) {
        periodValid = false;
    }

    // Check if the period is a "full" period
    if (periodValid && startDate != null && endDate != null && periodType != null) {
        switch (periodType) {
        case DAY:
            // i.e. a DAY period: from 05/12/2006 to 05/12/2006
            if ((getNumberOfDays(startDate.minusDays(1), endDate) != 1) || // 12-11 = 1  (Nb of days = 1)
                    (getNumberOfDays(startDate, endDate) != 0) || // // 12-12 = 0 (Nb of days = 0)
                    (getNumberOfDays(startDate, endDate.plusDays(1)) != 1)) { // 13-12 = 1 (Nb of days = 1)
                periodValid = false;
            }
            break;
        case WEEK:
            // i.e. a WEEK period: from 05/12/2006 to 05/18/2006
            if ((startDate.toDateTimeAtStartOfDay().getDayOfWeek() != DateTimeConstants.MONDAY) || // the week has to begin on MONDAY
                    (getNumberOfWeeks(startDate.minusDays(1), endDate) != 1) || // 18-11 = 7 (Nb of weeks = 1)
                    (getNumberOfWeeks(startDate, endDate) != 0) || // 18-12 = 6 (Nb of weeks = 0)
                    (getNumberOfWeeks(startDate, endDate.plusDays(1)) != 1)) { // 19-12 = 7 (Nb of weeks = 1)
                periodValid = false;
            }
            break;
        case MONTH:
            // i.e. a MONTH period: from 05/01/2006 to 05/30/2006
            if ((startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the month
                    (getNumberOfMonths(startDate.minusDays(1), endDate) != 1) || // 5-4 = 1 (Nb of months = 1)
                    (getNumberOfMonths(startDate, endDate) != 0) || // 5-5 = 0 (Nb of months = 0)
                    (getNumberOfMonths(startDate, endDate.plusDays(1)) != 1)) { // 6-5 = 1 (Nb of months = 1)
                periodValid = false;
            }
            break;
        case YEAR:
            // i.e. a YEAR period: from 01/01/2006 to 12/31/2006
            if ((startDate.getMonthOfYear() != 1 || startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the first month
                    (endDate.getMonthOfYear() != 12) || // the month of the end date of the period has to be December
                    (getNumberOfYears(startDate.minusDays(1), endDate) != 1) || // 2006-2005 = 1 (Nb of years = 1)
                    (getNumberOfYears(startDate, endDate) != 0) || // 2006-2006 = 0 (Nb of years = 0)
                    (getNumberOfYears(startDate, endDate.plusDays(1)) != 1)) { // 2007-2006 = 1 (Nb of years = 1)
                periodValid = false;
            }
            break;
        case FREE:
            // There is no constraint on the number of units for FREE type of period
            break;
        default:
            // Should never happen
            throw new AssertionError("The PeriodType is unknown");
        }
    }

    return periodValid;
}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the list of Period between a start date and an end date<BR/><BR/>
 * Example:<BR/>//from   ww w. ja v  a2 s. co m
 * getListOfPeriod(new LocalDate(2006, 5, 20), new LocalDate(2006, 7, 2), PeriodType.MONTH) should create the following Period objects:
 * <UL>
 * <LI> From 05/01/2006 to 05/31/2006 (MONTH)</LI>
 * <LI> From 06/01/2006 to 06/30/2006 (MONTH)</LI>
 * <LI> From 07/01/2006 to 07/31/2006 (MONTH)</LI>
 * </UL>
 * @param start Start date of the whole period
 * @param end End date of the whole period
 * @param periodType Type of the Period to create
 * @return The list of computed Period
 */
private List<Period> getListOfPeriod(LocalDate start, LocalDate end, PeriodType periodType) {
    if (start == null || end == null || periodType == null) {
        throw new IllegalArgumentException(
                "One of the following parameters is null: 'start', 'end', 'periodType'");
    }

    // Adjust the start date to the start of the period's type (first day of the week, first day of the month, first day of the year depending on the type of the period to create)
    LocalDate startPeriods = getAdjustedStartDate(start, periodType);

    // Adjust the end date to the end of the period's type (last day of the week, last day of the month, last day of the year depending on the type of the period to create)
    LocalDate endPeriods = getAdjustedEndDate(end, periodType);

    assert (startPeriods != null && endPeriods != null);

    // Create the list of Period objects
    List<Period> listOfPeriod = new ArrayList<Period>(); // List of created Period (returned object)
    Period newPeriod;
    if (periodType == PeriodType.FREE) {
        // Create the Period object and add it to the list of Period
        newPeriod = new Period(start, end, PeriodType.FREE);
        listOfPeriod.add(newPeriod);
    } else {
        // Create all Period objects and add them to the list of Period
        while (startPeriods.compareTo(endPeriods) <= 0) {
            switch (periodType) {
            case DAY:
                // Create the DAY period
                newPeriod = new Period(startPeriods, startPeriods, PeriodType.DAY); // i.e. Day from 05/02/2006 to 05/02/2006
                startPeriods = startPeriods.plusDays(1); // Move to the next day
                break;
            case WEEK:
                // Create the WEEK period
                newPeriod = new Period(startPeriods, startPeriods.plusDays(6), PeriodType.WEEK); // i.e. Week from 05/01/2006 (MONDAY) to 05/07/2006 (SUNDAY)
                startPeriods = startPeriods.plusDays(7); // Move to the next week
                break;
            case MONTH:
                // Create the MONTH period
                newPeriod = new Period(startPeriods, startPeriods.plusMonths(1).minusDays(1), PeriodType.MONTH); // i.e. Month from 05/01/2006 to 05/31/2006
                startPeriods = startPeriods.plusMonths(1); // Move to the next month
                break;
            case YEAR:
                // Create the YEAR period
                newPeriod = new Period(startPeriods, startPeriods.plusYears(1).minusDays(1), PeriodType.YEAR); // i.e. Year from 01/01/2006 to 12/31/2006
                startPeriods = startPeriods.plusYears(1); // Move to the next year
                break;
            case FREE: // should never happen
                throw new AssertionError("The FREE PeriodType should not be handled in this switch statement");
            default: // should never happen
                throw new AssertionError("Unknown PeriodType");
            }
            assert (newPeriod != null);

            // Add the created period to the list of Period
            listOfPeriod.add(newPeriod);
        }
    }

    return listOfPeriod;
}