Exemplo n.º 1
0
  /**
   * Method which returns the previous entry for the given entry
   *
   * @param entry The entry to fetch the previous entry for
   * @command The command to return the result to
   */
  protected void getPreviousEntry(LogEntry entry, Continuation command) {
    if (entry == entries[0]) {
      getPreviousEntry(
          new StandardContinuation(command) {
            public void receiveResult(Object o) {
              if (o instanceof CoalescedLogEntry) {
                LogEntry[] otherEntries = ((CoalescedLogEntry) o).getEntries();
                parent.receiveResult(otherEntries[otherEntries.length - 1]);
              } else {
                parent.receiveResult(o);
              }
            }
          });
    } else {
      for (int i = 1; i < entries.length; i++)
        if (entries[i] == entry) {
          command.receiveResult(entries[i - 1]);
          return;
        }

      if (entry == null) {
        command.receiveResult(entries[entries.length - 1]);
        return;
      }

      command.receiveException(
          new IllegalArgumentException("ERROR: Could not find previous entry for " + entry));
    }
  }