code: public void flatten(final boolean reverse) {
          if (!isBuilt) {
              build();
          }
  
          root = new ItemsNodeInterval();
          for (final Item item : items) {
              Preconditions.checkState(item.getAction() == ItemAction.ADD);
              root.addExistingItem(new ItemsNodeInterval(root, new Item(item, reverse ? ItemAction.CANCEL : ItemAction.ADD)));
          }
          items.clear();
          isBuilt = false;
      }
docs: Flattens the tree so its depth only has one level below root -- becomes a list.
  <p>
  If the tree was not built, it is first built. The list of items is cleared and the state is now reset to unbuilt.
  
  @param reverse whether to reverse the existing items (recurring items now show up as CANCEL instead of ADD)