package editor.util;

import java.util.function.Supplier;

/**
 * This class represents an action that can be undone, which is done by simply
 * using two actions that are semantically supposed to be opposites.  Each
 * action can optionally return a value.
 * 
 * @param <R> information to be returned by the action
 * @param <U> information to be returned by the undone action
 * @author Alec Roelke
 */
public class UndoableAction<R, U>
{
    /**
     * "Forward" action that represents what was done.
     */
    private final Supplier<R> forward;
    /**
     * "Reverse" action that represents how to undo the forward action.
     */
    private final Supplier<U> reverse;

    /**
     * Create a new UndoableAction.
     * 
     * @param f "forward" action representing what was done
     * @param r "reverse" action representing how to undo it
     */
    public UndoableAction(final Supplier<R> f, final Supplier<U> r)
    {
        forward = f;
        reverse = r;
    }

    /**
     * Perform the action (or redo it if it has been undone).
     * 
     * @return a value containing information about the result of performing
     * the action.
     */
    public R redo()
    {
        return forward.get();
    }

    /**
     * Undo the action.
     * 
     * @return a value containing information about the result undoing the action.
     */
    public U undo()
    {
        return reverse.get();
    }
}
@@ -406,21 +406,25 @@
 %0Apublic 
-class
+interface
  Undoabl
@@ -458,62 +458,69 @@
   * 
-%22Forward%22 action that represents what was done
+Create a new undoable action from the given functions
 .%0A     *
 /%0A  
@@ -519,108 +519,42 @@
    *
-/
+ 
 %0A    
-private final Supplier%3CR%3E forward;%0A    /**%0A     * %22Reverse%22 action that represents how to undo
+ * @param %3CR%3E return type of
  the
@@ -572,109 +572,60 @@
 tion
-.
 %0A     *
-/%0A    private final Supplier%3CU%3E reverse;%0A%0A    /**%0A     * Create a new UndoableAction.%0A     * 
+ @param %3CU%3E return type of the reverse action
 %0A   
@@ -640,26 +640,30 @@
 am f
+orward
  
-%22
 forward
-%22
  action 
 repr
@@ -662,34 +662,18 @@
 ion 
-representing what was done
+to perform
 %0A   
@@ -688,26 +688,30 @@
 am r
+everse
  
-%22
 reverse
-%22
  action 
 repr
@@ -710,76 +710,125 @@
 ion 
-representing how to undo it%0A     */%0A    public UndoableAction(final 
+to perform%0A     * @return The new UndoableAction.%0A     */%0A    public static %3CR, U%3E UndoableAction%3CR, U%3E createAction(
 Supp
@@ -840,15 +840,15 @@
 R%3E f
-, final
+orward,
  Sup
@@ -857,16 +857,22 @@
 ier%3CU%3E r
+everse
 )%0A    %7B%0A
@@ -883,40 +883,165 @@
     
-forward = f;%0A        reverse = r
+return new UndoableAction%3C%3E()%0A        %7B%0A            public R redo() %7B return forward.get(); %7D%0A            public U undo() %7B return reverse.get(); %7D%0A        %7D
 ;%0A  
@@ -1231,31 +1231,24 @@
  */%0A    
-public 
 R redo()
 %0A    %7B%0A 
@@ -1243,50 +1243,9 @@
 do()
-%0A    %7B%0A        return forward.get();%0A    %7D
+;
 %0A%0A  
@@ -1377,31 +1377,24 @@
  */%0A    
-public 
 U undo()
 %0A    %7B%0A 
@@ -1389,48 +1389,7 @@
 do()
-%0A    %7B%0A        return reverse.get();%0A    %7D
+;
 %0A%7D

Make UndoableAction into an interface