Exemplo n.º 1
0
  public Collection<Period> getInclusivePeriods(Period period, Collection<Period> periods) {
    Collection<Period> immutablePeriods = new ArrayList<Period>(periods);

    Iterator<Period> iterator = immutablePeriods.iterator();

    while (iterator.hasNext()) {
      Period iterated = iterator.next();

      if (!DateUtils.between(iterated.getStartDate(), period.getStartDate(), period.getEndDate())
          || !DateUtils.between(
              iterated.getEndDate(), period.getStartDate(), period.getEndDate())) {
        iterator.remove();
      }
    }

    return immutablePeriods;
  }
Exemplo n.º 2
0
  public Collection<Period> getBoundaryPeriods(Period period, Collection<Period> periods) {
    Collection<Period> immutablePeriods = new ArrayList<Period>(periods);

    Iterator<Period> iterator = immutablePeriods.iterator();

    while (iterator.hasNext()) {
      Period iterated = iterator.next();

      if (!DateUtils.strictlyBetween(
              period.getStartDate(), iterated.getStartDate(), iterated.getEndDate())
          && !DateUtils.strictlyBetween(
              period.getEndDate(), iterated.getStartDate(), iterated.getEndDate())) {
        iterator.remove();
      }
    }

    return immutablePeriods;
  }
Exemplo n.º 3
0
  public Collection<Period> getIntersectionPeriods(Collection<Period> periods) {
    Set<Period> intersecting = new HashSet<Period>();

    for (Period period : periods) {
      intersecting.addAll(getIntersectingPeriods(period.getStartDate(), period.getEndDate()));
    }

    return intersecting;
  }
Exemplo n.º 4
0
  public Period getPeriod(String isoPeriod) {
    Period period = PeriodType.getPeriodFromIsoString(isoPeriod);

    if (period != null) {
      period =
          periodStore.getPeriod(period.getStartDate(), period.getEndDate(), period.getPeriodType());
    }

    return period;
  }
Exemplo n.º 5
0
  @Test
  public void testCreatePeriod() {
    startDate = new DateTime(2009, 7, 1, 0, 0);
    endDate = new DateTime(2009, 8, 31, 0, 0);
    testDate = new DateTime(2009, 8, 15, 0, 0);

    Period period = periodType.createPeriod(testDate.toDate());

    assertEquals(startDate.toDate(), period.getStartDate());
    assertEquals(endDate.toDate(), period.getEndDate());

    startDate = new DateTime(2009, 3, 1, 0, 0);
    endDate = new DateTime(2009, 4, 30, 0, 0);
    testDate = new DateTime(2009, 3, 15, 0, 0);

    period = periodType.createPeriod(testDate.toDate());

    assertEquals(startDate.toDate(), period.getStartDate());
    assertEquals(endDate.toDate(), period.getEndDate());
  }
Exemplo n.º 6
0
  /**
   * Generates a list of all Periods between the given start and end date. The first period will
   * span the start date. The last period will span the end date.
   *
   * @param startDate the start date.
   * @param endDate the end date.
   * @return a list of Periods for the defined time span.
   */
  public List<Period> generatePeriods(Date startDate, Date endDate) {
    List<Period> periods = new ArrayList<>();

    Period period = createPeriod(startDate);

    Calendar calendar = getCalendar();

    while (period.getStartDate().before(endDate)) {
      periods.add(period);
      period = getNextPeriod(period, calendar);
    }

    return periods;
  }
Exemplo n.º 7
0
  @Test
  public void testGetPreviousPeriod() {
    testDate = new DateTime(2009, 8, 15, 0, 0);

    Period period = periodType.createPeriod(testDate.toDate());

    period = periodType.getPreviousPeriod(period);

    startDate = new DateTime(2009, 5, 1, 0, 0);
    endDate = new DateTime(2009, 6, 30, 0, 0);

    assertEquals(startDate.toDate(), period.getStartDate());
    assertEquals(endDate.toDate(), period.getEndDate());
  }
Exemplo n.º 8
0
  public PeriodHierarchy getPeriodHierarchy(Collection<Period> periods) {
    PeriodHierarchy hierarchy = new PeriodHierarchy();

    for (Period period : periods) {
      hierarchy
          .getIntersectingPeriods()
          .put(
              period.getId(),
              new HashSet<Integer>(
                  getIdentifiers(
                      Period.class,
                      getIntersectingPeriods(period.getStartDate(), period.getEndDate()))));
      hierarchy
          .getPeriodsBetween()
          .put(
              period.getId(),
              new HashSet<Integer>(
                  getIdentifiers(
                      Period.class,
                      getPeriodsBetweenDates(period.getStartDate(), period.getEndDate()))));
    }

    return hierarchy;
  }
Exemplo n.º 9
0
  private void populateJCombBox() {
    String item = "";

    for (Task t : this.session.getTasks()) {
      this.jComboBoxTask.addItem(t.getName());

      for (Period p : t.getPeriods()) {
        item =
            t.getName()
                + " | "
                + p.getStartDate().getTime()
                + " - "
                + p.getEndDate().getTime()
                + " | "
                + p.getElapsedTime();
        this.jComboBoxPeriod.addItem(item);
      }
    }
  }
Exemplo n.º 10
0
  public List<Period> getPeriods(Period lastPeriod, int historyLength) {
    List<Period> periods = new ArrayList<Period>(historyLength);

    lastPeriod = periodStore.reloadForceAddPeriod(lastPeriod);

    CalendarPeriodType periodType = (CalendarPeriodType) lastPeriod.getPeriodType();

    Period p = new Period();

    for (int i = 0; i < historyLength; ++i) {
      p = getPeriodFromDates(lastPeriod.getStartDate(), lastPeriod.getEndDate(), periodType);

      periods.add(p != null ? p : lastPeriod);

      lastPeriod = periodType.getPreviousPeriod(lastPeriod);
    }

    Collections.reverse(periods);

    return periods;
  }
Exemplo n.º 11
0
  /**
   * Finds and returns all the appointments that belong to the user identified by <code>loginName
   * </code> and which are in the specified <code>period</code>.
   *
   * @param loginName the login name of the user whose appointments you want to retrieve.
   * @param period the period in which the appointments you want should be.
   * @return a list with all the appointments that belong to the user identified by <code>loginName
   *     </code> and which are in the specified <code>period</code>.
   */
  public List<Appointment> findAppointmentsForPeriod(String loginName, Period period) {
    Connection conn = ConnectionManager.getInstance().getConnection();
    try {
      PreparedStatement findStatement =
          conn.prepareStatement(
              findForPeriodStatement(),
              ResultSet.TYPE_SCROLL_SENSITIVE,
              ResultSet.CONCUR_READ_ONLY);
      findStatement.setString(1, loginName);
      findStatement.setTimestamp(2, new java.sql.Timestamp(period.getStartDate().getTime()));
      findStatement.setTimestamp(3, new java.sql.Timestamp(period.getEndDate().getTime()));
      return genericFindAppointments(conn, findStatement);
    } catch (SQLException e) {
      try {
        conn.close();
      } catch (SQLException se) {
        System.out.println("An SQL exceptions occured: " + se.getMessage());
      }

      System.out.println("An SQL exceptions occured: " + e.getMessage());

      return null;
    }
  }
Exemplo n.º 12
0
 /**
  * Generates a list of Periods for a defined time span containing the given Period. E.g. if the
  * given Period is March 2007, and a monthly PeriodType generates for a year, all months in 2007
  * should be generated and returned in order.
  *
  * @param period the Period which touches the time span to generate Periods for.
  * @return a list of Periods for a defined time span.
  */
 public List<Period> generatePeriods(Period period) {
   return generatePeriods(period.getStartDate());
 }
Exemplo n.º 13
0
 @Override
 public Period getPreviousPeriod(Period period) {
   Calendar cal = createCalendarInstance(period.getStartDate());
   cal.add(Calendar.YEAR, -1);
   return createPeriod(cal);
 }
Exemplo n.º 14
0
 @Override
 public String getIsoDate(Period period) {
   Calendar cal = createCalendarInstance(period.getStartDate());
   int year = cal.get(Calendar.YEAR);
   return String.valueOf(year);
 }
 /**
  * Returns an iso8601 formatted string representation of the period
  *
  * @param period Period
  * @return the period as string
  */
 public String getIsoDate(Period period) {
   return getIsoDate(createLocalDateUnitInstance(period.getStartDate()));
 }