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; }
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; }
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; }
public Period getPeriod(String isoPeriod) { Period period = PeriodType.getPeriodFromIsoString(isoPeriod); if (period != null) { period = periodStore.getPeriod(period.getStartDate(), period.getEndDate(), period.getPeriodType()); } return period; }
@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()); }
@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()); }
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; }
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); } } }
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; }
/** * 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; } }