List of usage examples for org.joda.time LocalDate compareTo
public int compareTo(ReadablePartial partial)
From source file:org.libreplan.business.calendars.entities.BaseCalendar.java
License:Open Source License
public void newVersion(LocalDate startDate, LocalDate expiringDate, BaseCalendar parent) { CalendarData newCalendarData;// w w w . j a v a2 s . c om if (startDate != null && expiringDate != null) { if (startDate.compareTo(expiringDate) > 0) { throw new IllegalArgumentException("the start date must be lower than expiring date"); } if (calendarDataVersions.size() == 1) { BaseCalendar lastParent = getLastCalendarData().getParent(); newCalendarData = createLastVersion(startDate); CalendarData newLastVersion = createLastVersion(expiringDate); newLastVersion.setParent(lastParent); resetDefaultCapacities(newLastVersion); } else { newCalendarData = createNewVersionInsideIntersection(startDate, expiringDate); } } else if (startDate != null) { newCalendarData = createLastVersion(startDate); } else if (expiringDate != null) { newCalendarData = createFirstVersion(expiringDate); } else { throw new IllegalArgumentException("At least the start date must be specified"); } if (parent != null) { newCalendarData.setParent(parent); } else { newCalendarData.setParent(getLastCalendarData().getParent()); } resetDefaultCapacities(newCalendarData); }
From source file:org.libreplan.business.calendars.entities.BaseCalendar.java
License:Open Source License
public CalendarData getCalendarData(LocalDate date) { for (CalendarData calendarData : calendarDataVersions) { if (calendarData.getExpiringDate() == null) { return calendarData; } else {/* w ww .j av a 2 s .c o m*/ if (date.compareTo(calendarData.getExpiringDate()) < 0) { return calendarData; } } } throw new RuntimeException("Some work week should not be expired"); }
From source file:org.libreplan.business.calendars.entities.BaseCalendar.java
License:Open Source License
private void setExpiringDate(CalendarData calendarData, LocalDate expiringDate) { if (calendarData.getExpiringDate() == null) { throw new IllegalArgumentException( "Can not set the expiring date because of this is the last work week"); }/* w ww.j ava2 s . c o m*/ Integer index = calendarDataVersions.indexOf(calendarData); if (index > 0) { CalendarData previousCalendarData = calendarDataVersions.get(index - 1); if (expiringDate.compareTo(previousCalendarData.getExpiringDate()) <= 0) { throw new IllegalArgumentException( "This date must be greater than expiring date of previous calendars"); } } calendarData.setExpiringDate(expiringDate); }
From source file:org.libreplan.business.calendars.entities.BaseCalendar.java
License:Open Source License
@SuppressWarnings("unused") @AssertTrue(message = "dates must be sorted and cannot overlap") public boolean isDateCouldNotOverlapConstraint() { if (calendarDataVersions == null || calendarDataVersions.isEmpty()) { return true; }//from w ww .j a v a2 s.com if (this.getLastCalendarData().getExpiringDate() != null) { return false; } for (int i = 0; i < calendarDataVersions.size() - 2; i++) { LocalDate date1 = calendarDataVersions.get(i).getExpiringDate(); LocalDate date2 = calendarDataVersions.get(i + 1).getExpiringDate(); if ((date1 == null) || (date2 == null) || (date1.compareTo(date2) >= 0)) { return false; } } return true; }
From source file:org.libreplan.business.calendars.entities.CalendarAvailability.java
License:Open Source License
public void setStartDate(LocalDate startDate) { if (startDate == null) { throw new IllegalArgumentException("Start date must not be null"); }/*from w w w .j ava 2s. c o m*/ if (endDate != null && startDate.compareTo(endDate) > 0) { throw new IllegalArgumentException("End date must be greater or equal than start date"); } this.startDate = startDate; }
From source file:org.libreplan.business.planner.chart.ContiguousDaysLine.java
License:Open Source License
public ContiguousDaysLine<T> subInterval(LocalDate startInclusive, LocalDate endExclusive) { if (isNotValid() || startInclusive.compareTo(endExclusive) >= 0 || startInclusive.compareTo(getEndExclusive()) >= 0 || endExclusive.compareTo(getStart()) <= 0) { return invalid(); }/* w w w. j a v a 2s . co m*/ LocalDate newStart = max(this.startInclusive, startInclusive); Days days = Days.daysBetween(newStart, min(getEndExclusive(), endExclusive)); ContiguousDaysLine<T> result = new ContiguousDaysLine<T>(newStart, days.getDays()); for (OnDay<T> each : result) { result.set(each.getDay(), this.get(each.getDay())); } return result; }
From source file:org.libreplan.business.planner.entities.HoursCostCalculator.java
License:Open Source License
private SortedMap<LocalDate, BigDecimal> calculateHoursPerDay(Integer totalHours, SortedSet<AdvanceMeasurement> advanceMeasurements, LocalDate filterStartDate, LocalDate filterEndDate) { SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>(); for (AdvanceMeasurement advanceMeasurement : advanceMeasurements) { LocalDate day = advanceMeasurement.getDate(); if (((filterStartDate == null) || day.compareTo(filterStartDate) >= 0) && ((filterEndDate == null) || day.compareTo(filterEndDate) <= 0)) { BigDecimal cost = advanceMeasurement.getValue().setScale(2).multiply(new BigDecimal(totalHours)) .divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_UP)); result.put(day, cost);//w w w. ja v a2 s.com } } return result; }
From source file:org.libreplan.business.planner.entities.HoursCostCalculator.java
License:Open Source License
/** * BCWS values are calculating here.//from ww w. j av a 2 s . co m * MAX(BCWS) equals addition of all dayAssignments. */ @Override public SortedMap<LocalDate, BigDecimal> getEstimatedCost(Task task, LocalDate filterStartDate, LocalDate filterEndDate) { if (task.isSubcontracted()) { return getAdvanceCost(task); } SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>(); List<DayAssignment> dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED); if (dayAssignments.isEmpty()) { return result; } int additionOfAllAssignmentsMinutes = 0; for (DayAssignment dayAssignment : dayAssignments) { LocalDate day = dayAssignment.getDay(); if (((filterStartDate == null) || day.compareTo(filterStartDate) >= 0) && ((filterEndDate == null) || day.compareTo(filterEndDate) <= 0)) { String currentTime = dayAssignment.getDuration().toFormattedString(); SimpleDateFormat format1 = new SimpleDateFormat("hh:mm"); SimpleDateFormat format2 = new SimpleDateFormat("hh"); Date date = null; try { if (isParsableWithFormat1(currentTime)) { date = format1.parse(currentTime); } else if (isParsableWithFormat2(currentTime)) { date = format2.parse(currentTime); } } catch (ParseException e) { e.printStackTrace(); } assert date != null; LocalTime time = new LocalTime(date.getTime()); // Time time = new Time(date.getTime()); BigDecimal hours = new BigDecimal(time.getHourOfDay()); additionOfAllAssignmentsMinutes += time.getMinuteOfHour(); if (!result.containsKey(day)) { result.put(day, BigDecimal.ZERO); } /** * On last day assignment app will check addition of minutes of all assignments. * If it is between 30 and 60 - add 1 hour to the last value of result. * If it is more than 60 then divide on 60 and calculate hours. * E.G. 120 minutes / 60 = 2 hours. */ if (dayAssignment.equals(dayAssignments.get(dayAssignments.size() - 1))) { if (additionOfAllAssignmentsMinutes >= 30 && additionOfAllAssignmentsMinutes <= 60) hours = BigDecimal.valueOf(hours.intValue() + 1); if (additionOfAllAssignmentsMinutes > 60) hours = BigDecimal.valueOf(hours.intValue() + (additionOfAllAssignmentsMinutes / 60)); } result.put(day, result.get(day).add(hours)); } } return result; }
From source file:org.libreplan.business.planner.entities.ResourceAllocation.java
License:Open Source License
private static void checkStartLessOrEqualToEnd(LocalDate start, LocalDate end) { Validate.isTrue(start.compareTo(end) <= 0, "the end must be equal or posterior to the start"); }
From source file:org.libreplan.business.planner.entities.Task.java
License:Open Source License
public Integer getWorkableDaysFromLimitedByEndOfTheTask(LocalDate startInclusive, LocalDate endExclusive) { int result = 0; if (endExclusive.compareTo(this.getEndAsLocalDate()) > 0) { endExclusive = getIntraDayEndDate().asExclusiveEnd(); }/*ww w . j a v a2s . c o m*/ for (LocalDate current = startInclusive; current.compareTo(endExclusive) < 0; current = current .plusDays(1)) { if (isWorkable(current)) { result++; } } return result; }