public Collection<Period> namePeriods(Collection<Period> periods, I18nFormat format) { for (Period period : periods) { period.setName(format.formatPeriod(period)); } return periods; }
/** * Creates a new <code>Years</code> by parsing a string in the ISO8601 format 'PnY'. * * <p>The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the years * component may be non-zero. If any other component is non-zero, an exception will be thrown. * * @param periodStr the period string, null returns zero * @return the period in years * @throws IllegalArgumentException if the string format is invalid */ public static Years parseYears(String periodStr) { if (periodStr == null) { return Years.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Years.years(p.getYears()); }
/** * Creates a new <code>Hours</code> by parsing a string in the ISO8601 format 'PTnH'. * * <p>The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the hours * component may be non-zero. If any other component is non-zero, an exception will be thrown. * * @param periodStr the period string, null returns zero * @return the period in hours * @throws IllegalArgumentException if the string format is invalid */ public static Hours parseHours(String periodStr) { if (periodStr == null) { return Hours.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Hours.hours(p.getHours()); }
private void startPeriod(long startTime) { long endTime = startTime + m_strategy.getDuration(); Period period = new Period(startTime, endTime, m_analyzerManager, m_serverStateManager, m_logger); m_periods.add(period); period.start(); }
public boolean isRunning() { Period thePeriod = null; for (int i = 0; i < periods.size(); i++) { thePeriod = (Period) periods.get(i); if (thePeriod.getEndTime() == -1) return true; } return false; }
/** * Creates a new <code>Weeks</code> by parsing a string in the ISO8601 format 'PnW'. * * <p>The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the weeks * component may be non-zero. If any other component is non-zero, an exception will be thrown. * * @param periodStr the period string, null returns zero * @return the period in weeks * @throws IllegalArgumentException if the string format is invalid */ @FromString public static Weeks parseWeeks(String periodStr) { if (periodStr == null) { return Weeks.ZERO; } Period p = PARSER.parsePeriod(periodStr); return Weeks.weeks(p.getWeeks()); }
public void testAddPeriod() { Period period = new Period(); studySegment.addPeriod(period); assertEquals("wrong number of periods", 1, studySegment.getPeriods().size()); assertSame("wrong period present", period, studySegment.getPeriods().iterator().next()); assertEquals( "bidirectional relationship not maintained", studySegment, period.getStudySegment()); }
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 findPeriod(long timestamp) { for (Period period : m_periods) { if (period.isIn(timestamp)) { return period; } } return null; }
public void start() throws TaskException { if (getChildCount() > 0) throw new TaskException("If a task has subtasks you can only report on subtasks"); if (currentPeriod == null || currentPeriod.getEndTime() < System.currentTimeMillis()) { currentPeriod = new Period(); currentPeriod.setTask(this); addPeriod(currentPeriod); ApplicationEventDispatcher.fireEvent(new TaskStartedEvent(this)); } }
public Period getPeriod(String isoPeriod) { Period period = PeriodType.getPeriodFromIsoString(isoPeriod); if (period != null) { period = periodStore.getPeriod(period.getStartDate(), period.getEndDate(), period.getPeriodType()); } return period; }
public Task getRunningTask() { ArrayList thePeriods = getAllPeriods(); Period thePeriod = null; for (int i = 0; i < thePeriods.size(); i++) { thePeriod = (Period) thePeriods.get(i); if (thePeriod.getEndTime() == -1) { return thePeriod.getTask(); } } return null; }
private void endPeriod(long startTime) { int len = m_periods.size(); for (int i = 0; i < len; i++) { Period period = m_periods.get(i); if (period.isIn(startTime)) { period.finish(); m_periods.remove(i); break; } } }
public Set<Integer> getIntersectingPeriods(Collection<Period> periods) { periods = new HashSet<Period>(periods); Set<Integer> set = new HashSet<Integer>(); for (Period period : periods) { if (intersectingPeriods.containsKey(period.getId())) { set.addAll(intersectingPeriods.get(period.getId())); } } return set; }
public Set<Integer> getPeriodsBetween(Collection<Period> periods) { periods = new HashSet<Period>(periods); Set<Integer> set = new HashSet<Integer>(); for (Period period : periods) { if (periodsBetween.containsKey(period.getId())) { set.addAll(periodsBetween.get(period.getId())); } } return set; }
@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()); }
/** * 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; }
public boolean isEmpty() { return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (name == null || name.isEmpty()) && (type == null || type.isEmpty()) && (status == null || status.isEmpty()) && (activePeriod == null || activePeriod.isEmpty()) && (currency == null || currency.isEmpty()) && (balance == null || balance.isEmpty()) && (coveragePeriod == null || coveragePeriod.isEmpty()) && (subject == null || subject.isEmpty()) && (owner == null || owner.isEmpty()) && (description == null || description.isEmpty()); }
public static void main(String[] args) { // Attack the internals of a Period instance - Page 185 Date start = new Date(); Date end = new Date(); Period p = new Period(start, end); end.setYear(78); // Modifies internals of p! System.out.println(p); // Second attack on the internals of a Period instance - Page 186 start = new Date(); end = new Date(); p = new Period(start, end); p.end().setYear(78); // Modifies internals of p! System.out.println(p); }
public SupplyDispenseComponent copy(Supply e) { SupplyDispenseComponent dst = e.new SupplyDispenseComponent(); dst.identifier = identifier == null ? null : identifier.copy(); dst.status = status == null ? null : status.copy(); dst.type = type == null ? null : type.copy(); dst.quantity = quantity == null ? null : quantity.copy(); dst.suppliedItem = suppliedItem == null ? null : suppliedItem.copy(); dst.supplier = supplier == null ? null : supplier.copy(); dst.whenPrepared = whenPrepared == null ? null : whenPrepared.copy(); dst.whenHandedOver = whenHandedOver == null ? null : whenHandedOver.copy(); dst.destination = destination == null ? null : destination.copy(); dst.receiver = new ArrayList<ResourceReference>(); for (ResourceReference i : receiver) dst.receiver.add(i.copy()); return dst; }
public long getTimeReportedBetween(long aStartTime, long anEndTime) { long time = 0; ArrayList thePeriods = getPeriods(aStartTime, anEndTime); Period thePeriod = null; for (int i = 0; i < thePeriods.size(); i++) { thePeriod = (Period) thePeriods.get(i); long theStartTime = thePeriod.getStartTime(); long theEndTime = thePeriod.getEndTime(); if (theStartTime < aStartTime) theStartTime = aStartTime; if (theEndTime == -1) theEndTime = System.currentTimeMillis(); if (theEndTime > anEndTime) theEndTime = anEndTime; time += (theEndTime - theStartTime); } return time; }
public Coverage copy() { Coverage dst = new Coverage(); copyValues(dst); dst.issuer = issuer == null ? null : issuer.copy(); dst.bin = bin == null ? null : bin.copy(); dst.period = period == null ? null : period.copy(); dst.type = type == null ? null : type.copy(); dst.subscriberId = subscriberId == null ? null : subscriberId.copy(); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.group = group == null ? null : group.copy(); dst.plan = plan == null ? null : plan.copy(); dst.subPlan = subPlan == null ? null : subPlan.copy(); dst.dependent = dependent == null ? null : dependent.copy(); dst.sequence = sequence == null ? null : sequence.copy(); dst.subscriber = subscriber == null ? null : subscriber.copy(); dst.network = network == null ? null : network.copy(); if (contract != null) { dst.contract = new ArrayList<Reference>(); for (Reference i : contract) dst.contract.add(i.copy()); } ; return dst; }
public boolean isEmpty() { return super.isEmpty() && (code == null || code.isEmpty()) && (value == null || value.isEmpty()) && (exclude == null || exclude.isEmpty()) && (period == null || period.isEmpty()); }
public CareTeam copy() { CareTeam dst = new CareTeam(); copyValues(dst); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.status = status == null ? null : status.copy(); if (type != null) { dst.type = new ArrayList<CodeableConcept>(); for (CodeableConcept i : type) dst.type.add(i.copy()); } ; dst.name = name == null ? null : name.copy(); dst.subject = subject == null ? null : subject.copy(); dst.period = period == null ? null : period.copy(); if (participant != null) { dst.participant = new ArrayList<CareTeamParticipantComponent>(); for (CareTeamParticipantComponent i : participant) dst.participant.add(i.copy()); } ; dst.managingOrganization = managingOrganization == null ? null : managingOrganization.copy(); return dst; }
/** * 事件统计-趋势 * * @param siteId 网站ID * @param subsite 子站ID * @param offset 偏移 0=当天 -1=昨天 1=明天 -2 2 -3... * @param span 跨度 [day|week|month|year] * @param start 开始时间 ("yyyyMMddHHmmss") * @param end 结束时间 ("yyyyMMddHHmmss") * @return 事件统计-排行 {status:[true|false],data:[{name,num,rn,user,ru},...]} */ @RequestMapping("event/trend/{period:hour|day|week|month}") public Object eventTrend( @PathVariable int siteId, @PathVariable Period period, String subsite, Integer offset, Period span, Date start, Date end) { end = timeEnd(end, span, offset); start = timeStart(start, span, offset); String idsite = getIdSite(siteId, subsite); List<EventTrendValue> list = service.eventTrend(idsite, period, start, end); list = fulldata(list, period.getFormat(), period.getField(), start, end, EventTrendValue.class); return list; }
public boolean isEmpty() { return super.isEmpty() && (system == null || system.isEmpty()) && (value == null || value.isEmpty()) && (use == null || use.isEmpty()) && (rank == null || rank.isEmpty()) && (period == null || period.isEmpty()); }
public GroupMemberComponent copy() { GroupMemberComponent dst = new GroupMemberComponent(); copyValues(dst); dst.entity = entity == null ? null : entity.copy(); dst.period = period == null ? null : period.copy(); dst.inactive = inactive == null ? null : inactive.copy(); return dst; }
public void stop() throws TaskException { if (currentPeriod == null && !setRunningPeriod()) { throw new TaskException("This task was not yet started"); } currentPeriod.setEndTime(System.currentTimeMillis()); // addPeriod(currentPeriod); currentPeriod = null; }
public DocumentReferenceContextComponent copy(DocumentReference e) { DocumentReferenceContextComponent dst = e.new DocumentReferenceContextComponent(); dst.code = new ArrayList<CodeableConcept>(); for (CodeableConcept i : code) dst.code.add(i.copy()); dst.period = period == null ? null : period.copy(); dst.facilityType = facilityType == null ? null : facilityType.copy(); return dst; }
public CareTeamParticipantComponent copy() { CareTeamParticipantComponent dst = new CareTeamParticipantComponent(); copyValues(dst); dst.role = role == null ? null : role.copy(); dst.member = member == null ? null : member.copy(); dst.period = period == null ? null : period.copy(); return dst; }