Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9ea863a0e467ebb9006da6ba6b8d986327205d51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************************************
 * Copyright (c) 2009 Cloudsmith Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Cloudsmith Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.ql.expression;

import java.util.Iterator;
import org.eclipse.equinox.internal.p2.metadata.expression.*;
import org.eclipse.equinox.internal.p2.ql.MatchIteratorFilter;
import org.eclipse.equinox.p2.metadata.expression.IEvaluationContext;
import org.eclipse.equinox.p2.ql.IQLExpression;

/**
 * An expression that yields a new collection consisting of all elements of the
 * <code>collection</code> for which the <code>filter</code> yields <code>true</code>.
 */
final class Select extends CollectionFilter implements IQLExpression {
	Select(Expression collection, LambdaExpression lambda) {
		super(collection, lambda);
	}

	protected Object evaluate(IEvaluationContext context, Iterator<?> itor) {
		return evaluateAsIterator(context, itor);
	}

	protected Iterator<?> evaluateAsIterator(final IEvaluationContext context, Iterator<?> itor) {
		return new MatchIteratorFilter<Object>(itor) {
			protected boolean isMatch(Object val) {
				lambda.getItemVariable().setValue(context, val);
				return lambda.evaluate(context) == Boolean.TRUE;
			}
		};
	}

	public int getExpressionType() {
		return TYPE_SELECT;
	}

	public String getOperator() {
		return IQLConstants.KEYWORD_SELECT;
	}

	boolean isCollection() {
		return true;
	}
}

Back to the top