blob: 7bad617619647437b4059ef844caacde00773566 (
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
|
/*******************************************************************************
* Copyright (c) 2009, 2017 Cloudsmith Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Cloudsmith Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.metadata.expression;
import java.util.Iterator;
import org.eclipse.equinox.p2.metadata.expression.IEvaluationContext;
/**
* A collection filter that yields true if the <code>filter</code> yields true for
* any of the elements of the <code>collection</code>
*/
final class Exists extends CollectionFilter {
Exists(Expression collection, LambdaExpression lambda) {
super(collection, lambda);
}
@Override
protected Object evaluate(IEvaluationContext context, Iterator<?> itor) {
Variable variable = lambda.getItemVariable();
while (itor.hasNext()) {
variable.setValue(context, itor.next());
if (lambda.evaluate(context) == Boolean.TRUE)
return Boolean.TRUE;
}
return Boolean.FALSE;
}
@Override
public int getExpressionType() {
return TYPE_EXISTS;
}
@Override
public String getOperator() {
return KEYWORD_EXISTS;
}
}
|