Sha256: f7fb2190471a3ec780e2de1c5c614949929df54848cef0cce6f76e106b0e7d4f

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 KB

Contents

package sh.calaba.instrumentationbackend.query.ast;

import java.util.ArrayList;
import java.util.List;

import sh.calaba.instrumentationbackend.query.Operation;
import sh.calaba.instrumentationbackend.query.QueryResult;
import sh.calaba.instrumentationbackend.query.UIQueryResultVoid;
import sh.calaba.instrumentationbackend.query.ViewMapper;

public class UIQueryEvaluator {
	
	@SuppressWarnings({ "rawtypes" })
	public static QueryResult evaluateQueryWithOptions(List<UIQueryAST> query, List inputViews, List<Operation> operations) {
        List views = evaluateQueryForPath(query, inputViews);
        List result = applyOperations(views, operations);
        return new QueryResult(result);
	}



	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List applyOperations(List views, List<Operation> operations) {
		List result = views;
		for(Operation op : operations) {
			List nextResult = new ArrayList(result.size());
			for (Object obj : result) {
				try {
					nextResult.add(op.apply(obj));	
				} catch (Exception e) {
					e.printStackTrace();
					nextResult.add(UIQueryResultVoid.instance.asMap(op.getName(), obj, e.getMessage()));
				}				
			}
			result = nextResult;
		}
		return result;
	}


	@SuppressWarnings("rawtypes")
	private static List evaluateQueryForPath(List<UIQueryAST> queryPath,
			List inputViews) {

		List currentResult = inputViews;
		UIQueryDirection currentDirection = UIQueryDirection.DESCENDANT;
		UIQueryVisibility currentVisibility = UIQueryVisibility.VISIBLE;
		
		for (UIQueryAST step : queryPath) {			
			if (step instanceof UIQueryDirection) {
				currentDirection = (UIQueryDirection) step;
			}
			else if (step instanceof UIQueryVisibility) {
				currentVisibility = (UIQueryVisibility) step;
			}
			else {
				currentResult = step.evaluateWithViews(currentResult, currentDirection,currentVisibility);
			}

		}
		return currentResult;
	}
		

	public static boolean isDirection(UIQueryAST step) {
		return step instanceof UIQueryDirection;
	}
			
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
calabash-android-0.4.20.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.5.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.5.2.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.5.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.5.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.5.0.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.5.0.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.22.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.22.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.22.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.21 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.20 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.19 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.19.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.19.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java
calabash-android-0.4.19.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java