code: public void set(@NonNull final Object newTopKey) {
      move(new PendingTraversal() {
        @Override void doExecute() {
          if (newTopKey.equals(history.top())) {
            dispatch(history, Direction.REPLACE);
            return;
          }
  
          History.Builder builder = history.buildUpon();
          int count = 0;
          // Search backward to see if we already have newTop on the stack
          Object preservedInstance = null;
          for (Object entry : history.framesFromBottom()) {
            // If we find newTop on the stack, pop back to it.
            if (entry.equals(newTopKey)) {
              for (int i = 0; i < history.size() - count; i++) {
                preservedInstance = builder.pop();
              }
              break;
            } else {
              count++;
            }
          }
  
          History newHistory;
          if (preservedInstance != null) {
            // newTop was on the history. Put the preserved instance back on and dispatch.
            builder.push(preservedInstance);
            newHistory = builder.build();
            dispatch(newHistory, Direction.BACKWARD);
          } else {
            // newTop was not on the history. Push it on and dispatch.
            builder.push(newTopKey);
            newHistory = builder.build();
            dispatch(newHistory, Direction.FORWARD);
          }
        }
      });
    }
docs: Updates the history such that the given key is at the top and dispatches the updated
  history.
  
  If newTopKey is already at the top of the history, the history will be unchanged, but it will
  be dispatched with direction {@link Direction#REPLACE}.
  
  If newTopKey is already on the history but not at the top, the stack will pop until newTopKey
  is at the top, and the dispatch direction will be {@link Direction#BACKWARD}.
  
  If newTopKey is not already on the history, it will be pushed and the dispatch direction will
  be {@link Direction#FORWARD}.
  
  Objects' equality is always checked using {@link Object#equals(Object)}.