// Path: src/main/java/com/optimaize/command4j/ExecutionContext.java
// public interface ExecutionContext {
// 
//     /**
//      * @return the mode that was supplied to the initial invocation.
//      */
//     @NotNull
//     Mode getMode();
// 
//     /**
//      * @return the global cache to store/retrieve objects to/from.
//      */
//     @NotNull
//     ExecutorCache getCache();
// 
//     /**
//      * Overloaded method that uses the same <code>mode</code> as supplied
//      * to the parent invocation.
//      *
//      * @see #execute(Command, Mode, com.google.common.base.Optional)
//      */
//     @NotNull
//     <A, R> Optional<R> execute(@NotNull Command<A, R> task, Optional<A> arg) throws Exception;
// 
//     /**
//      * Runs the given <code>command</code> using the given <code>mode</code>.
//      *
//      * <p>This method is for commands that want to execute yet another command.
//      * One example is an auto-retry extension that executes the command again.
//      * </p>
//      */
//     @NotNull
//     <A, R> Optional<R> execute(@NotNull Command<A, R> task, @NotNull Mode mode, Optional<A> arg) throws Exception;
// 
// }


import com.google.common.base.Optional;
import com.optimaize.command4j.ExecutionContext;
import org.jetbrains.annotations.NotNull;
package com.optimaize.command4j.commands;


/**
 * Counts each execution and returns the current number of calls (including the current).
 *
 * @author Fabian Kessler
 */
public class CallCounter extends BaseCommand<Void, Integer> {

    public static class Counter {
        private volatile int i;
        public synchronized int incrementAndGet() {
            i++;
            return i;
        }
        public int get() {
            return i;
        }
    }

    private final Counter counter;
    public CallCounter(@NotNull Counter counter) {
        this.counter = counter;
    }

    @Override
// Path: src/main/java/com/optimaize/command4j/ExecutionContext.java
// public interface ExecutionContext {
// 
//     /**
//      * @return the mode that was supplied to the initial invocation.
//      */
//     @NotNull
//     Mode getMode();
// 
//     /**
//      * @return the global cache to store/retrieve objects to/from.
//      */
//     @NotNull
//     ExecutorCache getCache();
// 
//     /**
//      * Overloaded method that uses the same <code>mode</code> as supplied
//      * to the parent invocation.
//      *
//      * @see #execute(Command, Mode, com.google.common.base.Optional)
//      */
//     @NotNull
//     <A, R> Optional<R> execute(@NotNull Command<A, R> task, Optional<A> arg) throws Exception;
// 
//     /**
//      * Runs the given <code>command</code> using the given <code>mode</code>.
//      *
//      * <p>This method is for commands that want to execute yet another command.
//      * One example is an auto-retry extension that executes the command again.
//      * </p>
//      */
//     @NotNull
//     <A, R> Optional<R> execute(@NotNull Command<A, R> task, @NotNull Mode mode, Optional<A> arg) throws Exception;
// 
// }


// Path: src/test/java/com/optimaize/command4j/commands/CallCounter.java
import com.google.common.base.Optional;
import com.optimaize.command4j.ExecutionContext;
import org.jetbrains.annotations.NotNull;

package com.optimaize.command4j.commands;


/**
 * Counts each execution and returns the current number of calls (including the current).
 *
 * @author Fabian Kessler
 */
public class CallCounter extends BaseCommand<Void, Integer> {

    public static class Counter {
        private volatile int i;
        public synchronized int incrementAndGet() {
            i++;
            return i;
        }
        public int get() {
            return i;
        }
    }

    private final Counter counter;
    public CallCounter(@NotNull Counter counter) {
        this.counter = counter;
    }

    @Override
    public Integer call(@NotNull Optional<Void> arg, @NotNull ExecutionContext ec) throws Exception {