示例#1
0
 public void setValue(Capacity capacity) {
   overAssignableWithoutLimitCheckbox.setChecked(capacity.isOverAssignableWithoutLimit());
   standardEffortPicker.setValue(capacity.getStandardEffort());
   extraEffortPicker.setValue(capacity.getAllowedExtraEffort());
   currentCapacity = capacity;
   updateExtraEffortDisability();
 }
示例#2
0
 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;
 }
示例#3
0
 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());
 }
示例#4
0
 @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;
    }
示例#6
0
  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();
  }
示例#7
0
 private void updateExtraEffortDisability() {
   extraEffortPicker.setDisabled(currentCapacity.isOverAssignableWithoutLimit());
 }
示例#8
0
 private static Share createNormalCapacityShare(Capacity each) {
   return new Share(-each.getStandardEffort().getSeconds());
 }