// 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-expression/src/main/java/com/flipkart/hydra/expression/DefaultExpression.java
// public class DefaultExpression implements Expression {
// 
//     private final String expression;
//     private final List operands;
//     private final List<String> dependencies;
//     private final boolean isOptional;
// 
//     public DefaultExpression(String expression) throws ExpressionParseException {
//         expression = expression.replaceAll("\\s", "");
// 
//         this.isOptional = expression.startsWith("#");
//         this.expression = expression.substring(isOptional ? 1 : 0);
//         this.operands = parse(this.expression);
//         this.dependencies = findDependencies(operands);
//     }
// 
//     @Override
//     public Object calculate(Map<String, Object> values) throws ExpressionEvaluationException {
//         Object value = evaluate(operands, values);
//         if (!isOptional && value == null) {
//             throw new ExpressionEvaluationException("Null value found for non-optional expression - " + expression);
//         }
// 
//         return value;
//     }
// 
//     @Override
//     public List<String> getDependencies() {
//         return dependencies;
//     }
// 
//     private List<String> findDependencies(List operands) {
//         List<String> dependencies = new ArrayList<>();
//         for (Object value : operands) {
//             if (value instanceof List) {
//                 dependencies.addAll(findDependencies((List) value));
//             } else if (value instanceof String) {
//                 String stringValue = (String) value;
//                 if (stringValue.startsWith("$") && !stringValue.startsWith("$__")) {
//                     dependencies.add(stringValue.substring(1));
//                 }
//             }
//         }
// 
//         return dependencies;
//     }
// }
// 
// Path: hydra-expression/src/main/java/com/flipkart/hydra/expression/exception/ExpressionParseException.java
// public class ExpressionParseException extends Exception {
// 
//     public ExpressionParseException() {
//         super();
//     }
// 
//     public ExpressionParseException(String message) {
//         super(message);
//     }
// 
//     public ExpressionParseException(String expression, String expected, char found, int position) {
//         this(expression, expected, "" + found, position);
//     }
// 
//     public ExpressionParseException(String expression, String expected, String found, int position) {
//         super("Expected " + expected + ", Found '" + found + "' at position " + position + ". (Expression = " + expression + ")");
//     }
// 
//     public ExpressionParseException(String expression, String subExpression, int position) {
//         super("Unable to parse sub-expression '" + subExpression + "' starting at position " + position + ". (Expression = " + expression + ")");
//     }
// 
//     public ExpressionParseException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ExpressionParseException(Throwable cause) {
//         super(cause);
//     }
// }


import com.flipkart.hydra.composer.exception.ComposerInstantiationException;
import com.flipkart.hydra.expression.DefaultExpression;
import com.flipkart.hydra.expression.exception.ExpressionParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * 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.composer.utils;



public class CompositionParser {

    public static Object parse(Object context) throws ComposerInstantiationException {
        if (context instanceof String) {
            String stringContext = (String) context;
            if (stringContext.startsWith("{{") && stringContext.endsWith("}}")) {
                String varString = stringContext.substring(2, stringContext.length() - 2);
                try {
                    return new DefaultExpression(varString);
// 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-expression/src/main/java/com/flipkart/hydra/expression/DefaultExpression.java
// public class DefaultExpression implements Expression {
// 
//     private final String expression;
//     private final List operands;
//     private final List<String> dependencies;
//     private final boolean isOptional;
// 
//     public DefaultExpression(String expression) throws ExpressionParseException {
//         expression = expression.replaceAll("\\s", "");
// 
//         this.isOptional = expression.startsWith("#");
//         this.expression = expression.substring(isOptional ? 1 : 0);
//         this.operands = parse(this.expression);
//         this.dependencies = findDependencies(operands);
//     }
// 
//     @Override
//     public Object calculate(Map<String, Object> values) throws ExpressionEvaluationException {
//         Object value = evaluate(operands, values);
//         if (!isOptional && value == null) {
//             throw new ExpressionEvaluationException("Null value found for non-optional expression - " + expression);
//         }
// 
//         return value;
//     }
// 
//     @Override
//     public List<String> getDependencies() {
//         return dependencies;
//     }
// 
//     private List<String> findDependencies(List operands) {
//         List<String> dependencies = new ArrayList<>();
//         for (Object value : operands) {
//             if (value instanceof List) {
//                 dependencies.addAll(findDependencies((List) value));
//             } else if (value instanceof String) {
//                 String stringValue = (String) value;
//                 if (stringValue.startsWith("$") && !stringValue.startsWith("$__")) {
//                     dependencies.add(stringValue.substring(1));
//                 }
//             }
//         }
// 
//         return dependencies;
//     }
// }
// 
// Path: hydra-expression/src/main/java/com/flipkart/hydra/expression/exception/ExpressionParseException.java
// public class ExpressionParseException extends Exception {
// 
//     public ExpressionParseException() {
//         super();
//     }
// 
//     public ExpressionParseException(String message) {
//         super(message);
//     }
// 
//     public ExpressionParseException(String expression, String expected, char found, int position) {
//         this(expression, expected, "" + found, position);
//     }
// 
//     public ExpressionParseException(String expression, String expected, String found, int position) {
//         super("Expected " + expected + ", Found '" + found + "' at position " + position + ". (Expression = " + expression + ")");
//     }
// 
//     public ExpressionParseException(String expression, String subExpression, int position) {
//         super("Unable to parse sub-expression '" + subExpression + "' starting at position " + position + ". (Expression = " + expression + ")");
//     }
// 
//     public ExpressionParseException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ExpressionParseException(Throwable cause) {
//         super(cause);
//     }
// }


// Path: hydra-composer/src/main/java/com/flipkart/hydra/composer/utils/CompositionParser.java
import com.flipkart.hydra.composer.exception.ComposerInstantiationException;
import com.flipkart.hydra.expression.DefaultExpression;
import com.flipkart.hydra.expression.exception.ExpressionParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * 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.composer.utils;



public class CompositionParser {

    public static Object parse(Object context) throws ComposerInstantiationException {
        if (context instanceof String) {
            String stringContext = (String) context;
            if (stringContext.startsWith("{{") && stringContext.endsWith("}}")) {
                String varString = stringContext.substring(2, stringContext.length() - 2);
                try {
                    return new DefaultExpression(varString);
                } catch (ExpressionParseException e) {