public void setValue(Capacity capacity) { overAssignableWithoutLimitCheckbox.setChecked(capacity.isOverAssignableWithoutLimit()); standardEffortPicker.setValue(capacity.getStandardEffort()); extraEffortPicker.setValue(capacity.getAllowedExtraEffort()); currentCapacity = capacity; updateExtraEffortDisability(); }
private List<Share> createUnlimitedShares(Capacity[] capacities) { List<Share> result = new ArrayList<Share>(); for (Capacity each : capacities) { result.add(each.isOverAssignableWithoutLimit() ? new Share(0) : noSpaceAvailable()); } return result; }
private Share createOverloadShare(Capacity each, EffortDuration maxExtraEffort) { if (each.getAllowedExtraEffort() == null && !each.isOverAssignableWithoutLimit()) { return noSpaceAvailable(); } EffortDuration effort = each.getAllowedExtraEffort() != null ? each.getAllowedExtraEffort() : maxExtraEffort; return new Share(-effort.getSeconds()); }
@Override public Capacity getCapacityAt(Days day) { if (getBaseCalendar() == null) { return Capacity.zero(); } return getBaseCalendar().getCapacityConsideringCalendarDatasOn( selectedDate, day); }
/** * Makes a map of capacities with a list of {@link CalendarDayHoursDTO}. * * @param hoursPerDays * List<CalendarDayHoursDTO> to extract data from. * @return Map<Integer, Capacity> with the data that we want. * @throws ValidationException */ private Map<Integer, Capacity> getCapacitiesPerDays(List<CalendarDayHoursDTO> hoursPerDays) { Map<Integer, Capacity> result = new HashMap<>(); if (hoursPerDays != null) { for (CalendarDayHoursDTO hoursPerDayDTO : hoursPerDays) { try { if (hoursPerDayDTO.type == CalendarTypeDayDTO.DEFAULT) { continue; } Integer day = CalendarData.Days.valueOf(hoursPerDayDTO.day.toString()).ordinal(); Capacity capacity = Capacity.zero(); if (hoursPerDayDTO.type == CalendarTypeDayDTO.WORKING) { capacity = Capacity.create( EffortDuration.hours(hoursPerDayDTO.hours)).overAssignableWithoutLimit(); } else if (hoursPerDayDTO.type == CalendarTypeDayDTO.NOT_WORKING) { capacity = Capacity.create(EffortDuration.hours(hoursPerDayDTO.hours)); } result.put(day, capacity); } catch (IllegalArgumentException e) { throw new ValidationException("a day is not valid"); } catch (NullPointerException e) { throw new ValidationException("a day is null"); } } } return result; }
private EffortDuration getMaxExtraEffort(Capacity[] capacities) { if (capacities.length == 0) { return null; } Capacity max = Collections.max( Arrays.asList(capacities), new Comparator<Capacity>() { @Override public int compare(Capacity o1, Capacity o2) { if (o1.getAllowedExtraEffort() == o2.getAllowedExtraEffort()) { return 0; } else if (o1.getAllowedExtraEffort() == null) { return -1; } else if (o2.getAllowedExtraEffort() == null) { return 1; } return o1.getAllowedExtraEffort().compareTo(o2.getAllowedExtraEffort()); } }); return max.getAllowedExtraEffort(); }
private void updateExtraEffortDisability() { extraEffortPicker.setDisabled(currentCapacity.isOverAssignableWithoutLimit()); }
private static Share createNormalCapacityShare(Capacity each) { return new Share(-each.getStandardEffort().getSeconds()); }