Example usage for org.joda.time LocalDate plusDays

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

Introduction

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

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:org.libreplan.business.planner.entities.ResourceAllocation.java

License:Open Source License

private List<? extends T> withoutAlreadyPresent(Collection<? extends T> assignments) {
    if (assignments.isEmpty()) {
        return Collections.emptyList();
    }/*from  ww w. jav  a  2  s. c  o  m*/

    LocalDate min = Collections.min(assignments, DayAssignment.byDayComparator()).getDay();
    LocalDate max = Collections.max(assignments, DayAssignment.byDayComparator()).getDay();
    Set<LocalDate> daysPresent = DayAssignment.byDay(getAssignments(min, max.plusDays(1))).keySet();

    List<T> result = new ArrayList<>();
    for (T each : assignments) {
        if (!daysPresent.contains(each.getDay())) {
            result.add(each);
        }
    }
    return result;
}

From source file:org.libreplan.business.planner.entities.SigmoidFunction.java

License:Open Source License

private void apply(ResourceAllocation<?> resourceAllocation, LocalDate start, LocalDate end, int totalHours) {

    final LocalDate previousEndDate = resourceAllocation.getEndDate();

    EffortDuration capacity;//  w  w w .  j  a v  a 2s.c o m
    BaseCalendar calendar = resourceAllocation.getTask().getCalendar();
    int daysDuration = daysWithAllocatedHours(resourceAllocation).size();

    // Calculate hours per day and round values
    BigDecimal[] hoursToAllocatePerDay = generateHoursToAllocateFor(daysDuration, totalHours);
    hoursToAllocatePerDay = roundValues(hoursToAllocatePerDay, HOUR_FRAGMENTATION);

    // Calculate reminder (difference between totalHours and sum of hours calculated)
    BigDecimal totalHoursToAllocate = sumHoursPerDay(hoursToAllocatePerDay);
    assert (totalHoursToAllocate.compareTo(BigDecimal.valueOf(totalHours)) <= 0);
    BigDecimal remindingHours = BigDecimal.valueOf(totalHours).subtract(totalHoursToAllocate);
    allocateRemindingHours(hoursToAllocatePerDay, remindingHours);
    avoidZeroHoursInDays(hoursToAllocatePerDay);

    assert (hoursToAllocatePerDay.length == daysDuration);

    // Starting from startDate do allocation, one slot of hours per day in resource
    LocalDate day = new LocalDate(start);
    EffortDuration hours = EffortDuration.zero();
    int i = 0;
    while (i < hoursToAllocatePerDay.length) {
        hours = EffortDuration.fromHoursAsBigDecimal(hoursToAllocatePerDay[i]);
        capacity = calendar.getCapacityOn(PartialDay.wholeDay(day));
        if (!EffortDuration.zero().equals(capacity)) {
            allocate(resourceAllocation, day, hours);
            i++;
        }
        day = day.plusDays(1);
    }
    Validate.isTrue(resourceAllocation.getEndDate().equals(previousEndDate));
}

From source file:org.libreplan.business.planner.entities.SigmoidFunction.java

License:Open Source License

private List<BigDecimal> daysWithAllocatedHours(ResourceAllocation<?> resourceAllocation) {

    List<BigDecimal> result = new ArrayList<BigDecimal>();
    LocalDate day = new LocalDate(resourceAllocation.getStartDate());
    final LocalDate end = resourceAllocation.getEndDate();

    while (day.isBefore(end)) {
        int hoursAllocated = resourceAllocation.getAssignedHours(day, day.plusDays(1));
        if (hoursAllocated != 0) {
            result.add(new BigDecimal(hoursAllocated));
        }/*from   w  w w.  ja v a 2  s.  c  o m*/
        day = day.plusDays(1);
    }
    return result;
}

From source file:org.libreplan.business.planner.entities.SigmoidFunction.java

License:Open Source License

private void allocate(ResourceAllocation<?> resourceAllocation, LocalDate day, EffortDuration hours) {
    final LocalDate nextDay = day.plusDays(1);
    resourceAllocation.withPreviousAssociatedResources().onInterval(day, nextDay).allocate(hours);
}

From source file:org.libreplan.business.planner.entities.Stretch.java

License:Open Source License

protected static Stretch fromConsolidatedProgress(ResourceAllocation<?> resourceAllocation) {

    List<? extends DayAssignment> consolidated = resourceAllocation.getConsolidatedAssignments();
    if (consolidated.isEmpty()) {
        return null;
    }//from  w ww.  j a  v  a2s  .  c o  m

    final Task task = resourceAllocation.getTask();
    final LocalDate consolidatedEnd = lastDay(consolidated);

    return Stretch.create(consolidatedEnd.plusDays(1), resourceAllocation, task.getAdvancePercentage());
}

From source file:org.libreplan.business.planner.entities.Task.java

License:Open Source License

public IntraDayDate getFirstDayNotConsolidated() {
    if (consolidation != null) {

        LocalDate until = consolidation.getConsolidatedUntil();
        if (until != null) {
            return IntraDayDate.startOfDay(until.plusDays(1));
        }/*w  w  w. jav  a  2s  .com*/
    }

    return getIntraDayStartDate();
}

From source file:org.libreplan.business.templates.entities.OrderElementTemplate.java

License:Open Source License

private Date plusDays(Date date, Integer days) {
    LocalDate localDate = new LocalDate(date);

    return localDate.plusDays(days).toDateTimeAtStartOfDay().toDate();
}

From source file:org.libreplan.business.test.planner.entities.DayAssignmentMatchers.java

License:Open Source License

public static ListDayAssignmentsMatcher consecutiveDays(final int days) {
    return new ListDayAssignmentsMatcher() {

        @Override// w w  w .j a v a  2s  .  c  o  m
        public boolean matches(List<DayAssignment> assignments) {
            if (assignments.size() != days) {
                return false;
            }
            if (days == 0) {
                return true;
            }

            LocalDate current = assignments.get(0).getDay();

            for (DayAssignment d : assignments) {
                if (!d.getDay().equals(current)) {
                    return false;
                }
                current = current.plusDays(1);
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("it must have " + days + " days consecutive ");
        }
    };
}

From source file:org.libreplan.web.calendars.BaseCalendarModel.java

License:Open Source License

@Override
public void createNewVersion(LocalDate startDate, LocalDate expiringDate, BaseCalendar baseCalendar) {
    if (getBaseCalendar() != null) {
        if (expiringDate != null) {
            expiringDate = expiringDate.plusDays(1);
        }/*from ww w  .  j ava 2  s .  c  o m*/
        getBaseCalendar().newVersion(startDate, expiringDate, baseCalendar);
    }
}

From source file:org.libreplan.web.calendars.BaseCalendarModel.java

License:Open Source License

@Override
public void createCalendarAvailability() {
    if (getBaseCalendar() != null) {
        LocalDate startDate = new LocalDate();
        CalendarAvailability lastCalendarAvailability = getBaseCalendar().getLastCalendarAvailability();
        if (lastCalendarAvailability != null) {
            if (lastCalendarAvailability.getEndDate() == null) {
                startDate = lastCalendarAvailability.getStartDate();
            } else {
                startDate = lastCalendarAvailability.getEndDate();
            }//from   www.  j  av  a  2 s  . c o  m
            startDate = startDate.plusDays(1);
        }

        CalendarAvailability calendarAvailability = CalendarAvailability.create(startDate, null);
        calendarAvailability.setCode("");
        getBaseCalendar().addNewCalendarAvailability(calendarAvailability);
    }
}