Debian Codegraph @

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/expression/IMatchExpression.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2009 - 2010 Cloudsmith Inc. and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * Cloudsmith Inc. - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.equinox.p2.metadata.expression;
15
16 /**
17 * A match expression is a boolean expression matching a candidate of a
18 * specific type. An {@link IEvaluationContext} is needed in order to evaluate
19 * a match and this class provides two ways of doing that. Either a context
20 * is created first and then reused in several subsequent calls to
21 * {@link #isMatch(IEvaluationContext, Object)} or, if no repeated calls are
22 * expected, the {@link #isMatch(Object)} method can be used. It will then
23 * create a context on each call.
24 * @since 2.0
25 */
26 public interface IMatchExpression<T> extends IExpression {
27 /**
28 * <p>Creates a new context to be passed to repeated subsequent evaluations. The context
29 * will introduce 'this' as an uninitialized variable and make the parameters available.
30 * @return A new evaluation context.
31 */
32 IEvaluationContext createContext();
33
34 /**
35 * Returns the parameters that this match expression was created with.
36 * @return An array of parameters, possibly empty but never <code>null</code>.
37 */
38 Object[] getParameters();
39
40 /**
41 * This method creates a new evaluation context and assigns the <code>candidate</code>
42 * to the 'this' variable of the <code>context</code> and then evaluates the expression.
43 * This is essentially a short form for <pre>isMatch(createContext(), candidate)</pre>.
44 * @param candidate The object to test.
45 * @return the result of the evaluation.
46 */
47 boolean isMatch(T candidate);
48
49 /**
50 * This method assigns <code>candidate</code> to the 'this' variable of the
51 * <code>context</code> and then evaluates the expression.
52 * @param context A context
53 * @param candidate The object to test.
54 * @return the result of the evaluation.
55 */
56 boolean isMatch(IEvaluationContext context, T candidate);
57 }