Esempio n. 1
0
 public Vec2 convertCoordinateSystem(Vec2 event) {
   Optional<Drawing> drawing = this.find(Drawing.drawing, both()).findFirst();
   return drawing
       .map(x -> x.windowSystemToDrawingSystem(event))
       .orElseThrow(
           () ->
               new IllegalArgumentException(
                   " cant mouse around something without drawing support (to provide coordinate system)"));
 }
  /**
   * @param payObjects покупки, текст о которых нужно составить
   * @return сгрупированный текст о всех переданных покупок
   */
  public String getTextPayObjects(List<PayObject> payObjects) {
    Optional<String> optional =
        payObjects.stream().map(PayObject::toString).reduce((s1, s2) -> s1 + "\n\n" + s2);

    return optional.orElse("");
  }
  /**
   * @param payObjects покупки, суммарную стоимость которых нужно посчитать
   * @return суммарное колличество стоимости покупок
   */
  public Integer getSumPrice(List<PayObject> payObjects) {
    Optional<Integer> optional =
        payObjects.stream().map(PayObject::getPrice).reduce((s1, s2) -> s1 + s2);

    return optional.orElse(0);
  }
  public void update(List<Client> clientSet, List<Payment> payments) {
    Object[] columnNames =
        new Object[] {
          "#Cliente",
          "Nombre",
          "Apellido",
          "Celular",
          "Inscripción",
          "Domicilio",
          "Correo electrónico",
          "Próxima cuota"
        };

    Map<Integer, List<Payment>> paymentsByIds = new HashMap<>(clientSet.size());
    for (Payment payment : payments) {
      paymentsByIds.getOrDefault(payment.getClientId(), new ArrayList<>()).add(payment);

      List<Payment> idPayments = paymentsByIds.get(payment.getClientId());
      if (idPayments == null) {
        idPayments = new ArrayList<>();
        paymentsByIds.put(payment.getClientId(), idPayments);
      }
      idPayments.add(payment);
    }

    Object[][] data = new Object[clientSet.size()][columnNames.length];
    int i = 0;
    for (Client client : clientSet) {
      data[i][COLUMN_CLIENT] = client;
      data[i][COLUMN_FIRSTNAME] = client.getFirstName();
      data[i][COLUMN_LASTNAME] = client.getLastName();
      data[i][COLUMN_PHONENUMBER] = client.getPhoneNumber();
      data[i][COLUMN_INSCRIPTIONDATE] = client.getInscriptionDate().format(Utils.DATE_FORMATTER);
      data[i][COLUMN_HOMEADDRESS] = client.getHomeAddress();
      data[i][COLUMN_MAIL] = client.getMail();

      String finalString = "Nunca";
      Optional<Payment> lastPayment = getClientLastPayment(client, paymentsByIds);
      if (lastPayment.isPresent()) {
        LocalDate nextMonthToPay = lastPayment.get().getMonthDate().plusMonths(1);
        Period periodBetweenNowAndNextMonthToPay = Period.between(LocalDate.now(), nextMonthToPay);
        finalString = readablePeriod(periodBetweenNowAndNextMonthToPay);
      }
      data[i][COLUMN_NEXTPAYMENT] = finalString;
      i++;
    }
    TableModel tableModel = new DefaultTableModel(data, columnNames);
    setModel(tableModel);

    RowFilter<Object, Object> filter =
        new RowFilter<Object, Object>() {
          @Override
          public boolean include(Entry entry) {
            Client client = (Client) entry.getValue(COLUMN_CLIENT);
            if (!inactiveClientsVisible && client.isInactive()) {
              return false;
            }

            if (filteringWords == null) {
              return true;
            }

            for (String word : filteringWords) {
              if (!entryContainsWord(entry, word)) {
                return false;
              }
            }
            return true;
          }
        };

    TableRowSorter<TableModel> sorter = new TableRowSorter<>(tableModel);
    sorter.setRowFilter(filter);
    setRowSorter(sorter);
  }