예제 #1
0
  public TempReading getMinTemp(LocalDateTime userBeginDate, LocalDateTime userEndDate) {

    double tMin = MAX_TEMP;
    TempReading minTemp = new TempReading(MAX_TEMP);

    if (this.queEmpty()) return minTemp;

    LocalDateTime qBeginDate, qEndDate;
    qBeginDate = qTemp.getFirst().getTempTime();
    qEndDate = qTemp.getLast().getTempTime();

    // Test some end conditions
    if (userEndDate.isBefore(qBeginDate) || userBeginDate.isAfter(qEndDate)) {
      return minTemp;
    }
    TempReading tArray[] = this.toArray();
    int len = this.queSize();
    LocalDateTime tArrayValue;
    for (int i = 0; i < len; i++) {
      tArrayValue = tArray[i].getTempTime();
      if ((tArrayValue.isAfter(userBeginDate) || tArrayValue.equals(userBeginDate))
          && (tArrayValue.isBefore(userEndDate)
              || tArrayValue.equals(
                  userEndDate))) { // the test or "equals" is a bit overkill, but it made testing
        // easier
        if (tMin > tArray[i].getTemp()) {
          tMin = tArray[i].getTemp();
          minTemp = tArray[i];
        }
      }
    }
    return minTemp;
  }
예제 #2
0
 public Timespan(LocalDateTime start, LocalDateTime end) {
   if (start.isAfter(end)) {
     throw new IllegalArgumentException("requires start <= end");
   }
   this.start = start;
   this.end = end;
 }
예제 #3
0
 @Override
 public boolean userAgentNeedsUpdate(FacesContext fc) {
   // RFC2616 says related to If-Modified-Since header the following:
   //
   // "... The If-Modified-Since request-header field is used with a method
   // to make it conditional: if the requested variant has not been
   // modified since the time specified in this field, an entity will not
   // be returned from the server; instead, a 304 (not modified) response
   // will be returned without any message-body..."
   //
   // This method is called from ResourceHandlerImpl.handleResourceRequest
   // and if returns false send a 304 Not Modified response.
   if (!fc.isProjectStage(ProjectStage.Development)) {
     final Optional<String> ifModSinceHeader =
         Optional.ofNullable(
             fc.getExternalContext().getRequestHeaderMap().get("If-Modified-Since"));
     if (ifModSinceHeader.isPresent()) {
       LocalDateTime ifModifiedSince = convertIfModifiedSinceToDate(ifModSinceHeader.get());
       if (ifModifiedSince != null) return lastModified.isAfter(ifModifiedSince);
     }
   }
   // when in Development, or no if-modified-since header was found
   // (or couldn't be parsed),request a fresh resource
   return true;
 }
예제 #4
0
 public boolean overlap(TimeInterval other) {
   if (end.isEqual(other.start)) return false;
   if (end.isBefore(other.start)) return false;
   if (start.isEqual(other.end)) return false;
   if (start.isAfter(other.end)) return false;
   return true;
 }
예제 #5
0
  @Override
  protected void onBarClosed(BarHistory history, Bar bar) throws Exception {

    double close = bar.getClose();

    if (close <= 0) {
      throw new RuntimeException(
          String.format(
              "Negative close for [%s %2$tY-%2$tm-%2$td]: %3$f",
              bar.getSymbol(), bar.getDateTime(), bar.getClose()));
    }

    Status status = statuses_.get(bar.getSymbol());
    status.history = history;
    status.lastClose = bar.getClose();
    status.ts = bar.getDateTime();
    // Feed the indicators
    double roc = status.roc.add(close);
    status.returns.add(roc);

    LocalDateTime dateTime = bar.getDateTime();

    status.position = broker.getPosition(status.instrument).quantity;

    if (dateTime.isAfter(getTradingStart())) {

      status.longScores.clear();
      status.shortScores.clear();

      if (history.size() > minLen) {
        status.longScores.add(status.roc.last());
      }

      if (dateTime.isAfter(getTradingStop())) {
        Position pos = broker.getPosition(status.instrument);
        if (pos.quantity > 0) exitLong(bar.getSymbol());
        else if (pos.quantity < 0) exitShort(bar.getSymbol());
      }
    }
  }
예제 #6
0
  private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
      return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0
        && dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
      ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
      Object info = null;
      for (ZoneOffsetTransition trans : transArray) {
        info = findOffsetInfo(dt, trans);
        if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
          return info;
        }
      }
      return info;
    }

    // using historic rules
    int index = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
      // before first transition
      return wallOffsets[0];
    }
    if (index < 0) {
      // switch negative insert position to start of matched range
      index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1
        && savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
      // handle overlap immediately following gap
      index++;
    }
    if ((index & 1) == 0) {
      // gap or overlap
      LocalDateTime dtBefore = savingsLocalTransitions[index];
      LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
      ZoneOffset offsetBefore = wallOffsets[index / 2];
      ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
      if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
        // gap
        return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
      } else {
        // overlap
        return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
      }
    } else {
      // normal (neither gap or overlap)
      return wallOffsets[index / 2 + 1];
    }
  }
예제 #7
0
 public boolean contains(LocalDateTime now) {
   return now.equals(getStart())
       || now.equals(getEnd())
       || (now.isAfter(getStart()) && now.isBefore(getEnd()));
 }