class Patch<T> {
  private List<Delta<T>> deltas = new LinkedList<>();

  /**
   * Apply this patch to the given target
   * @param target the list to patch
   * @return the patched text
   * @throws IllegalStateException if can't apply patch
   */
  public List<T> applyTo(List<T> target) throws IllegalStateException {<FILL_FUNCTION_BODY>}

  /**
   * Add the given delta to this patch
   * @param delta the given delta
   */
  public void addDelta(Delta<T> delta) {
    deltas.add(delta);
  }

  /**
   * Get the list of computed deltas
   * @return the deltas
   */
  public List<Delta<T>> getDeltas() {
    Collections.sort(deltas, DeltaComparator.INSTANCE);
    return deltas;
  }
}

    List<T> result = new LinkedList<>(target);
    ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size());
    while (it.hasPrevious()) {
      Delta<T> delta = it.previous();
      delta.applyTo(result);
    }
    return result;
  
<no_super_class>