// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/Composer.java
// public interface Composer {
// 
//     public Object compose(Map<String, Object> values) throws ComposerEvaluationException;
// 
//     public List<String> getDependencies();
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/DefaultComposer.java
// public class DefaultComposer implements Composer {
// 
//     private final Object context;
//     private final List<String> dependencies;
// 
//     public DefaultComposer(Object context) throws ComposerInstantiationException {
//         this(context, false);
//     }
// 
//     public DefaultComposer(Object context, boolean isAlreadyParsed) throws ComposerInstantiationException {
//         this.context = isAlreadyParsed ? context : parse(context);
//         this.dependencies = findDependencies(this.context);
//     }
// 
//     @Override
//     public Object compose(Map<String, Object> values) throws ComposerEvaluationException {
//         return evaluate(context, values);
//     }
// 
//     @Override
//     public List<String> getDependencies() {
//         return dependencies;
//     }
// 
//     private List<String> findDependencies(Object context) {
//         List<String> dependencies = new ArrayList<>();
//         if (context instanceof Expression) {
//             dependencies.addAll(((Expression) context).getDependencies());
//         } else if (context instanceof Map) {
//             Map mapContext = (Map) context;
//             for (Object value : mapContext.values()) {
//                 dependencies.addAll(findDependencies(value));
//             }
//         } else if (context instanceof List) {
//             List listContext = (List) context;
//             for (Object value : listContext) {
//                 dependencies.addAll(findDependencies(value));
//             }
//         }
// 
//         return dependencies;
//     }
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/exception/ComposerEvaluationException.java
// public class ComposerEvaluationException extends Exception {
// 
//     public ComposerEvaluationException() {
//         super();
//     }
// 
//     public ComposerEvaluationException(String message) {
//         super(message);
//     }
// 
//     public ComposerEvaluationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ComposerEvaluationException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/exception/ComposerInstantiationException.java
// public class ComposerInstantiationException extends Exception {
// 
//     public ComposerInstantiationException() {
//         super();
//     }
// 
//     public ComposerInstantiationException(String message) {
//         super(message);
//     }
// 
//     public ComposerInstantiationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ComposerInstantiationException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/exception/BadCallableException.java
// public class BadCallableException extends Exception {
// 
//     public BadCallableException() {
//         super();
//     }
// 
//     public BadCallableException(String message) {
//         super(message);
//     }
// 
//     public BadCallableException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public BadCallableException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/helpers/ReflectionHelper.java
// public static Constructor<? extends Callable> getFirstSingleArgConstructor(Class<? extends Callable> callableClass) throws NoSuchMethodException {
//     Constructor<?>[] declaredConstructors = callableClass.getDeclaredConstructors();
//     for (Constructor constructor : declaredConstructors) {
//         Class[] parameterTypes = constructor.getParameterTypes();
//         if (parameterTypes.length == 1) {
//             return constructor;
//         }
//     }
// 
//     throw new NoSuchMethodException("Unable to find a single argument constructor.");
// }


import com.flipkart.hydra.composer.Composer;
import com.flipkart.hydra.composer.DefaultComposer;
import com.flipkart.hydra.composer.exception.ComposerEvaluationException;
import com.flipkart.hydra.composer.exception.ComposerInstantiationException;
import com.flipkart.hydra.task.exception.BadCallableException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import static com.flipkart.hydra.task.helpers.ReflectionHelper.getFirstSingleArgConstructor;
/*
 * Copyright 2015 Flipkart Internet, pvt ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flipkart.hydra.task;




public class DefaultTask implements Task {

    protected final Class<? extends Callable> callableClass;
    protected final Composer composer;

    public DefaultTask(Class<? extends Callable> callableClass, Composer composer) {
        this.callableClass = callableClass;
        this.composer = composer;
    }

    public DefaultTask(Class<? extends Callable> callableClass, Object context) throws ComposerInstantiationException {
        this(callableClass, context, false);
    }

    public DefaultTask(Class<? extends Callable> callableClass, Object context, boolean isAlreadyParsed) throws ComposerInstantiationException {
        this.callableClass = callableClass;
        this.composer = new DefaultComposer(context, isAlreadyParsed);
    }

    @Override
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/Composer.java
// public interface Composer {
// 
//     public Object compose(Map<String, Object> values) throws ComposerEvaluationException;
// 
//     public List<String> getDependencies();
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/DefaultComposer.java
// public class DefaultComposer implements Composer {
// 
//     private final Object context;
//     private final List<String> dependencies;
// 
//     public DefaultComposer(Object context) throws ComposerInstantiationException {
//         this(context, false);
//     }
// 
//     public DefaultComposer(Object context, boolean isAlreadyParsed) throws ComposerInstantiationException {
//         this.context = isAlreadyParsed ? context : parse(context);
//         this.dependencies = findDependencies(this.context);
//     }
// 
//     @Override
//     public Object compose(Map<String, Object> values) throws ComposerEvaluationException {
//         return evaluate(context, values);
//     }
// 
//     @Override
//     public List<String> getDependencies() {
//         return dependencies;
//     }
// 
//     private List<String> findDependencies(Object context) {
//         List<String> dependencies = new ArrayList<>();
//         if (context instanceof Expression) {
//             dependencies.addAll(((Expression) context).getDependencies());
//         } else if (context instanceof Map) {
//             Map mapContext = (Map) context;
//             for (Object value : mapContext.values()) {
//                 dependencies.addAll(findDependencies(value));
//             }
//         } else if (context instanceof List) {
//             List listContext = (List) context;
//             for (Object value : listContext) {
//                 dependencies.addAll(findDependencies(value));
//             }
//         }
// 
//         return dependencies;
//     }
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/exception/ComposerEvaluationException.java
// public class ComposerEvaluationException extends Exception {
// 
//     public ComposerEvaluationException() {
//         super();
//     }
// 
//     public ComposerEvaluationException(String message) {
//         super(message);
//     }
// 
//     public ComposerEvaluationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ComposerEvaluationException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/exception/ComposerInstantiationException.java
// public class ComposerInstantiationException extends Exception {
// 
//     public ComposerInstantiationException() {
//         super();
//     }
// 
//     public ComposerInstantiationException(String message) {
//         super(message);
//     }
// 
//     public ComposerInstantiationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ComposerInstantiationException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/exception/BadCallableException.java
// public class BadCallableException extends Exception {
// 
//     public BadCallableException() {
//         super();
//     }
// 
//     public BadCallableException(String message) {
//         super(message);
//     }
// 
//     public BadCallableException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public BadCallableException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: hydra-task/src/main/java/com/flipkart/hydra/task/helpers/ReflectionHelper.java
// public static Constructor<? extends Callable> getFirstSingleArgConstructor(Class<? extends Callable> callableClass) throws NoSuchMethodException {
//     Constructor<?>[] declaredConstructors = callableClass.getDeclaredConstructors();
//     for (Constructor constructor : declaredConstructors) {
//         Class[] parameterTypes = constructor.getParameterTypes();
//         if (parameterTypes.length == 1) {
//             return constructor;
//         }
//     }
// 
//     throw new NoSuchMethodException("Unable to find a single argument constructor.");
// }


// Path: hydra-task/src/main/java/com/flipkart/hydra/task/DefaultTask.java
import com.flipkart.hydra.composer.Composer;
import com.flipkart.hydra.composer.DefaultComposer;
import com.flipkart.hydra.composer.exception.ComposerEvaluationException;
import com.flipkart.hydra.composer.exception.ComposerInstantiationException;
import com.flipkart.hydra.task.exception.BadCallableException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import static com.flipkart.hydra.task.helpers.ReflectionHelper.getFirstSingleArgConstructor;

/*
 * Copyright 2015 Flipkart Internet, pvt ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flipkart.hydra.task;




public class DefaultTask implements Task {

    protected final Class<? extends Callable> callableClass;
    protected final Composer composer;

    public DefaultTask(Class<? extends Callable> callableClass, Composer composer) {
        this.callableClass = callableClass;
        this.composer = composer;
    }

    public DefaultTask(Class<? extends Callable> callableClass, Object context) throws ComposerInstantiationException {
        this(callableClass, context, false);
    }

    public DefaultTask(Class<? extends Callable> callableClass, Object context, boolean isAlreadyParsed) throws ComposerInstantiationException {
        this.callableClass = callableClass;
        this.composer = new DefaultComposer(context, isAlreadyParsed);
    }

    @Override
    public Callable<Object> getCallable(Map<String, Object> values) throws BadCallableException {