// Path: ibuscachedfield/src/main/java/com/byoutline/ibuscachedfield/events/ResponseEventWithArg.java
// public interface ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> {
// 
//     /**
//      * @param value    response from server/or calculated value.
//      * @param argValue argument that was used to get value.
//      */
//     void setResponse(RETURN_TYPE value, ARG_TYPE argValue);
// }
// 
// Path: ibuscachedfield/src/main/java/com/byoutline/ibuscachedfield/internal/IBusErrorListenerWithArg.java
// public class IBusErrorListenerWithArg<ARG_TYPE> implements ErrorListenerWithArg<ARG_TYPE> {
// 
//     private final IBus bus;
//     private final ResponseEventWithArg<Exception, ARG_TYPE> event;
// 
//     public IBusErrorListenerWithArg(@Nonnull IBus bus, @Nullable ResponseEventWithArg<Exception, ARG_TYPE> event) {
//         this.bus = bus;
//         this.event = event;
//     }
// 
//     @Override
//     public void valueLoadingFailed(Exception ex, ARG_TYPE arg) {
//         if (event != null) {
//             event.setResponse(ex, arg);
//             bus.post(event);
//         }
//     }
// }
// 
// Path: ibuscachedfield/src/main/java/com/byoutline/ibuscachedfield/internal/IBusSuccessListenerWithArg.java
// public final class IBusSuccessListenerWithArg<RETURN_TYPE, ARG_TYPE> implements SuccessListenerWithArg<RETURN_TYPE, ARG_TYPE> {
// 
//     private final IBus bus;
//     private final ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> responseEvent;
// 
//     public IBusSuccessListenerWithArg(IBus bus, ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> responseEvent) {
//         this.bus = bus;
//         this.responseEvent = responseEvent;
//     }
// 
//     @Override
//     public void valueLoaded(RETURN_TYPE value, ARG_TYPE arg) {
//         responseEvent.setResponse(value, arg);
//         bus.post(responseEvent);
//     }
// 
// }


import com.byoutline.cachedfield.*;
import com.byoutline.ibuscachedfield.events.ResponseEventWithArg;
import com.byoutline.ibuscachedfield.internal.IBusErrorListenerWithArg;
import com.byoutline.ibuscachedfield.internal.IBusSuccessListenerWithArg;
import com.byoutline.ottoeventcallback.OttoIBus;
import javax.inject.Provider;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
package com.byoutline.ottocachedfield;



/**
 * {@link CachedField} implementation that posts calculated result on Otto bus.
 *
 * @param <RETURN_TYPE> Type of cached value.
 * @param <ARG_TYPE>    Type of argument that needs to be passed to calculate value.
 * @author Sebastian Kacprzak <sebastian.kacprzak at byoutline.com>
 */
public class OttoCachedFieldWithArg<RETURN_TYPE, ARG_TYPE> extends CachedFieldWithArgImpl<RETURN_TYPE, ARG_TYPE> {

    OttoCachedFieldWithArg(Provider<String> sessionIdProvider,
                           ProviderWithArg<RETURN_TYPE, ARG_TYPE> valueGetter,
                           ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> successEvent,
                           ResponseEventWithArg<Exception, ARG_TYPE> errorEvent, OttoIBus bus,
                           ExecutorService valueGetterExecutor, Executor stateListenerExecutor) {
        this(sessionIdProvider,
                valueGetter,
                new IBusSuccessListenerWithArg<RETURN_TYPE, ARG_TYPE>(bus, successEvent),
                new IBusErrorListenerWithArg<ARG_TYPE>(bus, errorEvent),
// Path: ibuscachedfield/src/main/java/com/byoutline/ibuscachedfield/events/ResponseEventWithArg.java
// public interface ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> {
// 
//     /**
//      * @param value    response from server/or calculated value.
//      * @param argValue argument that was used to get value.
//      */
//     void setResponse(RETURN_TYPE value, ARG_TYPE argValue);
// }
// 
// Path: ibuscachedfield/src/main/java/com/byoutline/ibuscachedfield/internal/IBusErrorListenerWithArg.java
// public class IBusErrorListenerWithArg<ARG_TYPE> implements ErrorListenerWithArg<ARG_TYPE> {
// 
//     private final IBus bus;
//     private final ResponseEventWithArg<Exception, ARG_TYPE> event;
// 
//     public IBusErrorListenerWithArg(@Nonnull IBus bus, @Nullable ResponseEventWithArg<Exception, ARG_TYPE> event) {
//         this.bus = bus;
//         this.event = event;
//     }
// 
//     @Override
//     public void valueLoadingFailed(Exception ex, ARG_TYPE arg) {
//         if (event != null) {
//             event.setResponse(ex, arg);
//             bus.post(event);
//         }
//     }
// }
// 
// Path: ibuscachedfield/src/main/java/com/byoutline/ibuscachedfield/internal/IBusSuccessListenerWithArg.java
// public final class IBusSuccessListenerWithArg<RETURN_TYPE, ARG_TYPE> implements SuccessListenerWithArg<RETURN_TYPE, ARG_TYPE> {
// 
//     private final IBus bus;
//     private final ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> responseEvent;
// 
//     public IBusSuccessListenerWithArg(IBus bus, ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> responseEvent) {
//         this.bus = bus;
//         this.responseEvent = responseEvent;
//     }
// 
//     @Override
//     public void valueLoaded(RETURN_TYPE value, ARG_TYPE arg) {
//         responseEvent.setResponse(value, arg);
//         bus.post(responseEvent);
//     }
// 
// }


// Path: ottocachedfield/src/main/java/com/byoutline/ottocachedfield/OttoCachedFieldWithArg.java
import com.byoutline.cachedfield.*;
import com.byoutline.ibuscachedfield.events.ResponseEventWithArg;
import com.byoutline.ibuscachedfield.internal.IBusErrorListenerWithArg;
import com.byoutline.ibuscachedfield.internal.IBusSuccessListenerWithArg;
import com.byoutline.ottoeventcallback.OttoIBus;
import javax.inject.Provider;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

package com.byoutline.ottocachedfield;



/**
 * {@link CachedField} implementation that posts calculated result on Otto bus.
 *
 * @param <RETURN_TYPE> Type of cached value.
 * @param <ARG_TYPE>    Type of argument that needs to be passed to calculate value.
 * @author Sebastian Kacprzak <sebastian.kacprzak at byoutline.com>
 */
public class OttoCachedFieldWithArg<RETURN_TYPE, ARG_TYPE> extends CachedFieldWithArgImpl<RETURN_TYPE, ARG_TYPE> {

    OttoCachedFieldWithArg(Provider<String> sessionIdProvider,
                           ProviderWithArg<RETURN_TYPE, ARG_TYPE> valueGetter,
                           ResponseEventWithArg<RETURN_TYPE, ARG_TYPE> successEvent,
                           ResponseEventWithArg<Exception, ARG_TYPE> errorEvent, OttoIBus bus,
                           ExecutorService valueGetterExecutor, Executor stateListenerExecutor) {
        this(sessionIdProvider,
                valueGetter,
                new IBusSuccessListenerWithArg<RETURN_TYPE, ARG_TYPE>(bus, successEvent),
                new IBusErrorListenerWithArg<ARG_TYPE>(bus, errorEvent),
                valueGetterExecutor, stateListenerExecutor);