Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2ad7343fc8297a9921ed61b6a791ec8a06889951 (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
/*******************************************************************************
 * 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.internal.p2.metadata.IUMap;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.expression.IEvaluationContext;
import org.eclipse.equinox.p2.metadata.expression.IExpression;

public class IdIndex extends Index<IInstallableUnit> {
	private final IUMap iuMap;

	public IdIndex(IUMap iuMap) {
		this.iuMap = iuMap;
	}

	public IdIndex(Iterator<IInstallableUnit> ius) {
		iuMap = new IUMap();
		while (ius.hasNext())
			iuMap.add(ius.next());
	}

	@Override
	public Iterator<IInstallableUnit> getCandidates(IEvaluationContext ctx, IExpression variable, IExpression booleanExpr) {
		Object queriedKeys = getQueriedIDs(ctx, variable, InstallableUnit.MEMBER_ID, booleanExpr, null);
		if (queriedKeys == null)
			return null;

		if (queriedKeys instanceof Collection<?>) {
			HashSet<IInstallableUnit> collector = new HashSet<>();
			for (Object key : (Collection<?>) queriedKeys)
				collector.addAll(iuMap.getUnits((String) key));
			return collector.iterator();
		}
		return iuMap.getUnits((String) queriedKeys).iterator();
	}
}

Back to the top