Exemplo n.º 1
0
  public Collection<Period> namePeriods(Collection<Period> periods, I18nFormat format) {
    for (Period period : periods) {
      period.setName(format.formatPeriod(period));
    }

    return periods;
  }
Exemplo n.º 2
0
 /**
  * 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());
 }
Exemplo n.º 3
0
 /**
  * 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());
 }
Exemplo n.º 4
0
  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();
  }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 /**
  * 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());
 }
Exemplo n.º 7
0
 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());
 }
Exemplo n.º 8
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.º 9
0
  public Period findPeriod(long timestamp) {
    for (Period period : m_periods) {
      if (period.isIn(timestamp)) {
        return period;
      }
    }

    return null;
  }
Exemplo n.º 10
0
 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));
   }
 }
Exemplo n.º 11
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.º 12
0
 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;
 }
Exemplo n.º 13
0
  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;
  }
Exemplo n.º 16
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.º 17
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;
  }
 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());
 }
Exemplo n.º 19
0
  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);
  }
Exemplo n.º 20
0
 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;
 }
Exemplo n.º 21
0
 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;
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 public boolean isEmpty() {
   return super.isEmpty()
       && (code == null || code.isEmpty())
       && (value == null || value.isEmpty())
       && (exclude == null || exclude.isEmpty())
       && (period == null || period.isEmpty());
 }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
 /**
  * 事件统计-趋势
  *
  * @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());
 }
Exemplo n.º 27
0
 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;
 }
Exemplo n.º 28
0
 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;
 }
Exemplo n.º 29
0
 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;
 }
Exemplo n.º 30
0
 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;
 }