Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 884664e4be8da16a7a99ee4021b77fe011db35ce (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
/*******************************************************************************
 * Copyright (c) 2010, 2017 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.metadata.index;

import java.util.*;
import org.eclipse.equinox.p2.metadata.expression.IEvaluationContext;
import org.eclipse.equinox.p2.metadata.expression.IExpression;
import org.eclipse.equinox.p2.metadata.index.IIndex;

public class CompoundIndex<T> implements IIndex<T> {

	private final Collection<IIndex<T>> indexes;

	public CompoundIndex(Collection<IIndex<T>> indexes) {
		this.indexes = indexes;
	}

	@Override
	public Iterator<T> getCandidates(IEvaluationContext ctx, IExpression variable, IExpression booleanExpr) {
		Set<T> result = null;
		for (IIndex<T> index : indexes) {
			Iterator<T> indexResult = index.getCandidates(ctx, variable, booleanExpr);
			if (indexResult == null)
				return null;
			if (indexResult.hasNext()) {
				if (result == null)
					result = new HashSet<>();
				do {
					result.add(indexResult.next());
				} while (indexResult.hasNext());
			}
		}
		if (result == null)
			result = Collections.emptySet();
		return result.iterator();
	}
}

Back to the top