Esempio n. 1
0
  private void storeGraph(Graph graph) {
    if (numPatternsToStore < 1) return;

    if (topGraphs.isEmpty() || score > topGraphs.first().getScore()) {
      Graph graphCopy = new EdgeListGraphSingleConnections(graph);

      topGraphs.add(new ScoredGraph(graphCopy, score));

      if (topGraphs.size() > getNumPatternsToStore()) {
        topGraphs.remove(topGraphs.first());
      }
    }
  }
Esempio n. 2
0
  private void bes(Graph graph) {
    TetradLogger.getInstance().log("info", "** BACKWARD EQUIVALENCE SEARCH");

    initializeArrowsBackward(graph);

    while (!sortedArrows.isEmpty()) {
      Arrow arrow = sortedArrows.first();
      sortedArrows.remove(arrow);

      Node x = arrow.getX();
      Node y = arrow.getY();

      clearArrow(x, y);

      if (!validDelete(arrow.getHOrT(), arrow.getNaYX(), graph)) {
        continue;
      }

      List<Node> h = arrow.getHOrT();
      double bump = arrow.getBump();

      delete(x, y, h, graph, bump);
      score += bump;
      rebuildPattern(graph);

      storeGraph(graph);

      initializeArrowsBackward(
          graph); // Rebuilds Arrows from scratch each time. Fast enough for backwards.
    }
  }
Esempio n. 3
0
  public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Date startTime = new Date();
    String fname = "p079_keylog.txt";
    FileReader fr = new FileReader(fname);
    BufferedReader br = new BufferedReader(fr);
    SortedSet<String> slines = new TreeSet<String>();
    String line = "";

    while ((line = br.readLine()) != null) {
      slines.add(line);
    }

    String start = slines.first().split("")[0];

    String ans = "";

    for (String l : slines) {
      // System.out.println(l);
      for (String l2 : slines) {
        if (l2.contains(start) && l2.indexOf(start) > 0) start = l2.split("")[0];
      }
    }
    ans += start;
    // System.out.println(ans);
    for (int i = 0; i < 10; i++) {
      start = (getNext(slines, start));
      if (start == null) break;
      ans += start;
      // System.out.println(ans);
    }
    Date endTime = new Date();
    System.out.println(ans + " in " + (endTime.getTime() - startTime.getTime()) + " ms.");
  }
Esempio n. 4
0
 /**
  * The earliest start date of this research staff.
  *
  * @return the active date
  */
 @Transient
 public Date getActiveDate() {
   SortedSet<Date> dates = new TreeSet<Date>();
   for (SiteResearchStaff srs : this.getSiteResearchStaffs()) {
     Date activeDate = srs.getActiveDate();
     if (activeDate != null) dates.add(activeDate);
   }
   if (dates.size() > 0) return dates.first();
   else return null;
 }
Esempio n. 5
0
    @Override
    public int nextTab(int position) {
      int tabStop = Integer.MAX_VALUE;

      // Search for the first tab stop after the given position...
      SortedSet<Integer> tailSet = myTabStops.tailSet(position + 1);
      if (!tailSet.isEmpty()) {
        tabStop = tailSet.first();
      }

      // Don't go beyond the end of the line...
      return Math.min(tabStop, (myWidth - 1));
    }
Esempio n. 6
0
 /** @tests java.util.TreeSet#TreeSet(java.util.Comparator) */
 public void test_ConstructorLjava_util_Comparator() {
   // Test for method java.util.TreeSet(java.util.Comparator)
   SortedSet myTreeSet = db.createTreeSet("test", new ReversedIntegerComparator(), null);
   assertTrue("Did not construct correct TreeSet", myTreeSet.isEmpty());
   myTreeSet.add(new Integer(1));
   myTreeSet.add(new Integer(2));
   assertTrue(
       "Answered incorrect first element--did not use custom comparator ",
       myTreeSet.first().equals(new Integer(2)));
   assertTrue(
       "Answered incorrect last element--did not use custom comparator ",
       myTreeSet.last().equals(new Integer(1)));
 }
Esempio n. 7
0
  /**
   * Forward equivalence search.
   *
   * @param graph The graph in the state prior to the forward equivalence search.
   */
  private void fes(Graph graph, List<Node> nodes) {
    TetradLogger.getInstance().log("info", "** FORWARD EQUIVALENCE SEARCH");

    lookupArrows = new HashMap<OrderedPair, Set<Arrow>>();

    initializeArrowsForward(nodes);

    while (!sortedArrows.isEmpty()) {
      Arrow arrow = sortedArrows.first();
      sortedArrows.remove(arrow);

      Node x = arrow.getX();
      Node y = arrow.getY();

      clearArrow(x, y);

      if (graph.isAdjacentTo(x, y)) {
        continue;
      }

      if (!validInsert(x, y, arrow.getHOrT(), arrow.getNaYX(), graph)) {
        continue;
      }

      List<Node> t = arrow.getHOrT();
      double bump = arrow.getBump();

      Set<Edge> edges = graph.getEdges();

      insert(x, y, t, graph, bump);
      score += bump;
      rebuildPattern(graph);

      // Try to avoid duplicating scoring calls. First clear out all of the edges that need to be
      // changed,
      // then change them, checking to see if they're already been changed. I know, roundabout, but
      // there's
      // a performance boost.
      for (Edge edge : graph.getEdges()) {
        if (!edges.contains(edge)) {
          reevaluateForward(graph, nodes, edge.getNode1(), edge.getNode2());
        }
      }

      storeGraph(graph);
    }
  }
Esempio n. 8
0
 /**
  * Tests if a specific relation type is defined.
  *
  * <p>Note that this routine returns false both when a snumber/dnumber are swapped, and when a
  * typecombo does not exist - it is not possible to derive whether one or the other has occurred.
  *
  * <p>
  *
  * @param n1 The source type number.
  * @param n2 The destination type number.
  * @param r The relation definition (role) number, or -1 if the role does not matter r can only be
  *     -1 if virtual is <code>true</code>
  * @param restriction if {@link #STRICT}, contains only returns true if the typerel occurs as-is
  *     in the database. if {@link #INCLUDE_DESCENDANTS}, contains returns true if the typerel
  *     occurs as a virtual (derived) node, where source or destination may also be descendants of
  *     the specified type. if {@link #INCLUDE_PARENTS}, contains returns true if the typerel
  *     occurs as a virtual (derived) node, where source or destination may also be parents of the
  *     specified type. if {@link #INCLUDE_PARENTS_AND_DESCENDANTS}, contains returns true if the
  *     typerel occurs as a virtual (derived) node, where source or destination may also be
  *     descendants or parents of the specified type.
  * @return <code>true</code> when the relation exists, false otherwise.
  * @since MMBase-1.6.2
  */
 public boolean contains(int n1, int n2, int r, int restriction) {
   switch (restriction) {
     case INCLUDE_DESCENDANTS:
       return typeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r));
     case INCLUDE_PARENTS:
       return parentTypeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r));
     case INCLUDE_PARENTS_AND_DESCENDANTS:
       return typeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r))
           || parentTypeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r));
     case STRICT:
       SortedSet<MMObjectNode> existingNodes = typeRelNodes.getBySourceDestinationRole(n1, n2, r);
       return (existingNodes.size() > 0 && !existingNodes.first().isVirtual());
     default:
       log.error("Unknown restriction " + restriction);
       return false;
   }
 }
Esempio n. 9
0
 /** @tests java.util.TreeSet#TreeSet(java.util.SortedSet) */
 public void test_ConstructorLjava_util_SortedSet() {
   // Test for method java.util.TreeSet(java.util.SortedSet)
   ReversedIntegerComparator comp = new ReversedIntegerComparator();
   SortedSet myTreeSet = db.createTreeSet("test", comp, null);
   for (int i = 0; i < objArray.length; i++) myTreeSet.add(objArray[i]);
   SortedSet anotherTreeSet = db.getTreeSet("test");
   anotherTreeSet.addAll(myTreeSet);
   assertTrue("TreeSet is not correct size", anotherTreeSet.size() == objArray.length);
   for (int counter = 0; counter < objArray.length; counter++)
     assertTrue(
         "TreeSet does not contain correct elements", anotherTreeSet.contains(objArray[counter]));
   assertEquals(
       "TreeSet does not answer correct comparator",
       anotherTreeSet.comparator().getClass(),
       comp.getClass());
   assertEquals(
       "TreeSet does not use comparator", anotherTreeSet.first(), objArray[objArray.length - 1]);
 }
Esempio n. 10
0
  public static String getNext(SortedSet<String> slines, String num) {
    String nxt = "";
    SortedSet<String> candidates = new TreeSet<String>();
    for (String s : slines) {
      if (s.contains(num) && s.indexOf(num) < s.length() - 1) {
        candidates.add(s.split("")[s.indexOf(num) + 1]);
      }
    }
    // System.out.println(candidates);
    if (candidates.size() == 0) return null;
    nxt = candidates.first();
    for (String s : slines) {
      for (String c : candidates) {
        if (s.contains(c) && s.contains(nxt) && s.indexOf(c) < s.indexOf(nxt)) nxt = c;
      }
    }

    return nxt;
  }
Esempio n. 11
0
 public static void main(String[] args) {
   SortedSet<String> sortedSet = new TreeSet<String>();
   Collections.addAll(sortedSet, "one two three four five six seven eight".split(" "));
   print(sortedSet);
   String low = sortedSet.first();
   String high = sortedSet.last();
   print(low);
   print(high);
   Iterator<String> it = sortedSet.iterator();
   for (int i = 0; i <= 6; i++) {
     if (i == 3) low = it.next();
     if (i == 6) high = it.next();
     else it.next();
   }
   print(low);
   print(high);
   print(sortedSet.subSet(low, high));
   print(sortedSet.headSet(high));
   print(sortedSet.tailSet(low));
 }
 /**
  * 遍历时间触发器,如果已经达到执行时间,那么就执行任务回调
  *
  * @param now
  * @return
  */
 public List<TaskTrigger> acquireNextTriggers(long now) {
   List<TaskTrigger> taskTriggerList = null;
   try {
     if (timeTriggers.size() > 0) {
       // 获取离当前时间最近要执行的
       Long time = timeTriggers.first();
       if (time != null) {
         // 与当前时间比对,如果到达执行时间点
         if (time <= now) {
           timeTriggers.remove(time);
           taskTriggerList = triggerMap.get(time);
           triggerMap.remove(time);
         }
       }
     }
   } catch (Exception e) {
     logger.error("acquireNextTriggers error", e);
   }
   return taskTriggerList;
 }
 long getStartTime() {
   if (output_set.isEmpty()) return 0;
   return output_set.first().getStartTime();
 }
Esempio n. 14
0
 public Object firstElement() {
   // Return the appropriate element
   return m_Models.first();
 }
Esempio n. 15
0
  /** @tests java.util.TreeSet#first() */
  public void test_first() {

    // Test for method java.lang.Object java.util.TreeSet.first()
    assertEquals("Returned incorrect first element", ts.first(), objArray[0]);
  }
  public Date getTimeAfter(Date afterTime) {

    // Computation is based on Gregorian year only.
    Calendar cl = new java.util.GregorianCalendar(getTimeZone());

    // move ahead one second, since we're computing the time *after* the
    // given time
    afterTime = new Date(afterTime.getTime() + 1000);
    // CronTrigger does not deal with milliseconds
    cl.setTime(afterTime);
    cl.set(Calendar.MILLISECOND, 0);

    boolean gotOne = false;
    // loop until we've computed the next time, or we've past the endTime
    while (!gotOne) {

      // if (endTime != null && cl.getTime().after(endTime)) return null;
      if (cl.get(Calendar.YEAR) > 2999) { // prevent endless loop...
        return null;
      }

      SortedSet<Integer> st = null;
      int t = 0;

      int sec = cl.get(Calendar.SECOND);
      int min = cl.get(Calendar.MINUTE);

      // get second.................................................
      st = seconds.tailSet(sec);
      if (st != null && st.size() != 0) {
        sec = st.first();
      } else {
        sec = seconds.first();
        min++;
        cl.set(Calendar.MINUTE, min);
      }
      cl.set(Calendar.SECOND, sec);

      min = cl.get(Calendar.MINUTE);
      int hr = cl.get(Calendar.HOUR_OF_DAY);
      t = -1;

      // get minute.................................................
      st = minutes.tailSet(min);
      if (st != null && st.size() != 0) {
        t = min;
        min = st.first();
      } else {
        min = minutes.first();
        hr++;
      }
      if (min != t) {
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MINUTE, min);
        setCalendarHour(cl, hr);
        continue;
      }
      cl.set(Calendar.MINUTE, min);

      hr = cl.get(Calendar.HOUR_OF_DAY);
      int day = cl.get(Calendar.DAY_OF_MONTH);
      t = -1;

      // get hour...................................................
      st = hours.tailSet(hr);
      if (st != null && st.size() != 0) {
        t = hr;
        hr = st.first();
      } else {
        hr = hours.first();
        day++;
      }
      if (hr != t) {
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.DAY_OF_MONTH, day);
        setCalendarHour(cl, hr);
        continue;
      }
      cl.set(Calendar.HOUR_OF_DAY, hr);

      day = cl.get(Calendar.DAY_OF_MONTH);
      int mon = cl.get(Calendar.MONTH) + 1;
      // '+ 1' because calendar is 0-based for this field, and we are
      // 1-based
      t = -1;
      int tmon = mon;

      // get day...................................................
      boolean dayOfMSpec = !daysOfMonth.contains(NO_SPEC);
      boolean dayOfWSpec = !daysOfWeek.contains(NO_SPEC);
      if (dayOfMSpec && !dayOfWSpec) { // get day by day of month rule
        st = daysOfMonth.tailSet(day);
        if (lastdayOfMonth) {
          if (!nearestWeekday) {
            t = day;
            day = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));
            day -= lastdayOffset;
            if (t > day) {
              mon++;
              if (mon > 12) {
                mon = 1;
                tmon = 3333; // ensure test of mon != tmon further below fails
                cl.add(Calendar.YEAR, 1);
              }
              day = 1;
            }
          } else {
            t = day;
            day = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));
            day -= lastdayOffset;

            java.util.Calendar tcal = java.util.Calendar.getInstance(getTimeZone());
            tcal.set(Calendar.SECOND, 0);
            tcal.set(Calendar.MINUTE, 0);
            tcal.set(Calendar.HOUR_OF_DAY, 0);
            tcal.set(Calendar.DAY_OF_MONTH, day);
            tcal.set(Calendar.MONTH, mon - 1);
            tcal.set(Calendar.YEAR, cl.get(Calendar.YEAR));

            int ldom = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));
            int dow = tcal.get(Calendar.DAY_OF_WEEK);

            if (dow == Calendar.SATURDAY && day == 1) {
              day += 2;
            } else if (dow == Calendar.SATURDAY) {
              day -= 1;
            } else if (dow == Calendar.SUNDAY && day == ldom) {
              day -= 2;
            } else if (dow == Calendar.SUNDAY) {
              day += 1;
            }

            tcal.set(Calendar.SECOND, sec);
            tcal.set(Calendar.MINUTE, min);
            tcal.set(Calendar.HOUR_OF_DAY, hr);
            tcal.set(Calendar.DAY_OF_MONTH, day);
            tcal.set(Calendar.MONTH, mon - 1);
            Date nTime = tcal.getTime();
            if (nTime.before(afterTime)) {
              day = 1;
              mon++;
            }
          }
        } else if (nearestWeekday) {
          t = day;
          day = daysOfMonth.first();

          java.util.Calendar tcal = java.util.Calendar.getInstance(getTimeZone());
          tcal.set(Calendar.SECOND, 0);
          tcal.set(Calendar.MINUTE, 0);
          tcal.set(Calendar.HOUR_OF_DAY, 0);
          tcal.set(Calendar.DAY_OF_MONTH, day);
          tcal.set(Calendar.MONTH, mon - 1);
          tcal.set(Calendar.YEAR, cl.get(Calendar.YEAR));

          int ldom = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));
          int dow = tcal.get(Calendar.DAY_OF_WEEK);

          if (dow == Calendar.SATURDAY && day == 1) {
            day += 2;
          } else if (dow == Calendar.SATURDAY) {
            day -= 1;
          } else if (dow == Calendar.SUNDAY && day == ldom) {
            day -= 2;
          } else if (dow == Calendar.SUNDAY) {
            day += 1;
          }

          tcal.set(Calendar.SECOND, sec);
          tcal.set(Calendar.MINUTE, min);
          tcal.set(Calendar.HOUR_OF_DAY, hr);
          tcal.set(Calendar.DAY_OF_MONTH, day);
          tcal.set(Calendar.MONTH, mon - 1);
          Date nTime = tcal.getTime();
          if (nTime.before(afterTime)) {
            day = daysOfMonth.first();
            mon++;
          }
        } else if (st != null && st.size() != 0) {
          t = day;
          day = st.first();
          // make sure we don't over-run a short month, such as february
          int lastDay = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));
          if (day > lastDay) {
            day = daysOfMonth.first();
            mon++;
          }
        } else {
          day = daysOfMonth.first();
          mon++;
        }

        if (day != t || mon != tmon) {
          cl.set(Calendar.SECOND, 0);
          cl.set(Calendar.MINUTE, 0);
          cl.set(Calendar.HOUR_OF_DAY, 0);
          cl.set(Calendar.DAY_OF_MONTH, day);
          cl.set(Calendar.MONTH, mon - 1);
          // '- 1' because calendar is 0-based for this field, and we
          // are 1-based
          continue;
        }
      } else if (dayOfWSpec && !dayOfMSpec) { // get day by day of week rule
        if (lastdayOfWeek) { // are we looking for the last XXX day of
          // the month?
          int dow = daysOfWeek.first(); // desired
          // d-o-w
          int cDow = cl.get(Calendar.DAY_OF_WEEK); // current d-o-w
          int daysToAdd = 0;
          if (cDow < dow) {
            daysToAdd = dow - cDow;
          }
          if (cDow > dow) {
            daysToAdd = dow + (7 - cDow);
          }

          int lDay = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));

          if (day + daysToAdd > lDay) { // did we already miss the
            // last one?
            cl.set(Calendar.SECOND, 0);
            cl.set(Calendar.MINUTE, 0);
            cl.set(Calendar.HOUR_OF_DAY, 0);
            cl.set(Calendar.DAY_OF_MONTH, 1);
            cl.set(Calendar.MONTH, mon);
            // no '- 1' here because we are promoting the month
            continue;
          }

          // find date of last occurrence of this day in this month...
          while ((day + daysToAdd + 7) <= lDay) {
            daysToAdd += 7;
          }

          day += daysToAdd;

          if (daysToAdd > 0) {
            cl.set(Calendar.SECOND, 0);
            cl.set(Calendar.MINUTE, 0);
            cl.set(Calendar.HOUR_OF_DAY, 0);
            cl.set(Calendar.DAY_OF_MONTH, day);
            cl.set(Calendar.MONTH, mon - 1);
            // '- 1' here because we are not promoting the month
            continue;
          }

        } else if (nthdayOfWeek != 0) {
          // are we looking for the Nth XXX day in the month?
          int dow = daysOfWeek.first(); // desired
          // d-o-w
          int cDow = cl.get(Calendar.DAY_OF_WEEK); // current d-o-w
          int daysToAdd = 0;
          if (cDow < dow) {
            daysToAdd = dow - cDow;
          } else if (cDow > dow) {
            daysToAdd = dow + (7 - cDow);
          }

          boolean dayShifted = false;
          if (daysToAdd > 0) {
            dayShifted = true;
          }

          day += daysToAdd;
          int weekOfMonth = day / 7;
          if (day % 7 > 0) {
            weekOfMonth++;
          }

          daysToAdd = (nthdayOfWeek - weekOfMonth) * 7;
          day += daysToAdd;
          if (daysToAdd < 0 || day > getLastDayOfMonth(mon, cl.get(Calendar.YEAR))) {
            cl.set(Calendar.SECOND, 0);
            cl.set(Calendar.MINUTE, 0);
            cl.set(Calendar.HOUR_OF_DAY, 0);
            cl.set(Calendar.DAY_OF_MONTH, 1);
            cl.set(Calendar.MONTH, mon);
            // no '- 1' here because we are promoting the month
            continue;
          } else if (daysToAdd > 0 || dayShifted) {
            cl.set(Calendar.SECOND, 0);
            cl.set(Calendar.MINUTE, 0);
            cl.set(Calendar.HOUR_OF_DAY, 0);
            cl.set(Calendar.DAY_OF_MONTH, day);
            cl.set(Calendar.MONTH, mon - 1);
            // '- 1' here because we are NOT promoting the month
            continue;
          }
        } else {
          int cDow = cl.get(Calendar.DAY_OF_WEEK); // current d-o-w
          int dow = daysOfWeek.first(); // desired
          // d-o-w
          st = daysOfWeek.tailSet(cDow);
          if (st != null && st.size() > 0) {
            dow = st.first();
          }

          int daysToAdd = 0;
          if (cDow < dow) {
            daysToAdd = dow - cDow;
          }
          if (cDow > dow) {
            daysToAdd = dow + (7 - cDow);
          }

          int lDay = getLastDayOfMonth(mon, cl.get(Calendar.YEAR));

          if (day + daysToAdd > lDay) { // will we pass the end of
            // the month?
            cl.set(Calendar.SECOND, 0);
            cl.set(Calendar.MINUTE, 0);
            cl.set(Calendar.HOUR_OF_DAY, 0);
            cl.set(Calendar.DAY_OF_MONTH, 1);
            cl.set(Calendar.MONTH, mon);
            // no '- 1' here because we are promoting the month
            continue;
          } else if (daysToAdd > 0) { // are we swithing days?
            cl.set(Calendar.SECOND, 0);
            cl.set(Calendar.MINUTE, 0);
            cl.set(Calendar.HOUR_OF_DAY, 0);
            cl.set(Calendar.DAY_OF_MONTH, day + daysToAdd);
            cl.set(Calendar.MONTH, mon - 1);
            // '- 1' because calendar is 0-based for this field,
            // and we are 1-based
            continue;
          }
        }
      } else { // dayOfWSpec && !dayOfMSpec
        throw new UnsupportedOperationException(
            "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.");
      }
      cl.set(Calendar.DAY_OF_MONTH, day);

      mon = cl.get(Calendar.MONTH) + 1;
      // '+ 1' because calendar is 0-based for this field, and we are
      // 1-based
      int year = cl.get(Calendar.YEAR);
      t = -1;

      // test for expressions that never generate a valid fire date,
      // but keep looping...
      if (year > MAX_YEAR) {
        return null;
      }

      // get month...................................................
      st = months.tailSet(mon);
      if (st != null && st.size() != 0) {
        t = mon;
        mon = st.first();
      } else {
        mon = months.first();
        year++;
      }
      if (mon != t) {
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.DAY_OF_MONTH, 1);
        cl.set(Calendar.MONTH, mon - 1);
        // '- 1' because calendar is 0-based for this field, and we are
        // 1-based
        cl.set(Calendar.YEAR, year);
        continue;
      }
      cl.set(Calendar.MONTH, mon - 1);
      // '- 1' because calendar is 0-based for this field, and we are
      // 1-based

      year = cl.get(Calendar.YEAR);
      t = -1;

      // get year...................................................
      st = years.tailSet(year);
      if (st != null && st.size() != 0) {
        t = year;
        year = st.first();
      } else {
        return null; // ran out of years...
      }

      if (year != t) {
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.DAY_OF_MONTH, 1);
        cl.set(Calendar.MONTH, 0);
        // '- 1' because calendar is 0-based for this field, and we are
        // 1-based
        cl.set(Calendar.YEAR, year);
        continue;
      }
      cl.set(Calendar.YEAR, year);

      gotOne = true;
    } // while( !done )

    return cl.getTime();
  }