Ejemplo n.º 1
0
  /**
   * @return the chronologically (based on result date) last result
   * @should get the most recent result given multiple results
   * @should get the result given a single result
   * @should get an empty result given an empty result
   * @should get the result with null result date
   */
  public Result latest() {
    if (isSingleResult()) {
      return this;
    }
    Result last = emptyResult();

    // default the returned result to the first item
    // in case all resultDates are null
    if (size() > 0) {
      last = get(0);
    }

    for (Result r : this) {
      if ((last.getResultDate() == null
          || (r.getResultDate() != null && r.getResultDate().after(last.getResultDate())))) {
        last = r;
      }
    }
    return last;
  }
Ejemplo n.º 2
0
  /**
   * @return the chronologically (based on result date) first result
   * @should get the first result given multiple results
   * @should get the result given a single result
   * @should get an empty result given an empty result
   * @should not get the result with null result date given other results
   * @should get one result with null result dates for all results
   */
  public Result earliest() {
    if (isSingleResult()) {
      return this;
    }

    Result first = emptyResult();

    // default the returned result to the first item
    // in case all resultDates are null
    if (size() > 0) {
      first = get(0);
    }

    for (Result r : this) {
      if (r != null
          && r.getResultDate() != null
          && (first.getResultDate() == null || r.getResultDate().before(first.getResultDate()))) {
        first = r;
      }
    }
    return first;
  }