Skip to main content
summaryrefslogtreecommitdiffstats
blob: 67be63c1133dddf92a47a713fcbbaede38ed049e (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 *  Copyright (c) 2007, 2009 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.metadata.query;

import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.equinox.p2.query.MatchQuery;

/**
 * A query that matches on the id and version of an {@link IInstallableUnit}.
 */
public class InstallableUnitQuery extends MatchQuery<IInstallableUnit> {
	/**
	 * A convenience query that will match any {@link IInstallableUnit}
	 * it encounters.
	 */
	public static final InstallableUnitQuery ANY = new InstallableUnitQuery((String) null);

	private String id;
	private final VersionRange range;

	/**
	 * Creates a query that will match any {@link IInstallableUnit} with the given
	 * id, regardless of version.
	 * 
	 * @param id The installable unit id to match, or <code>null</code> to match any id
	 */
	public InstallableUnitQuery(String id) {
		this.id = id;
		this.range = null;
	}

	/**
	 * Creates a query that will match any {@link IInstallableUnit} with the given
	 * id, and whose version falls in the provided range.
	 * 
	 * @param id The installable unit id to match, or <code>null</code> to match any id
	 * @param range The version range to match
	 */
	public InstallableUnitQuery(String id, VersionRange range) {
		this.id = id;
		this.range = range;
	}

	/**
	 * Creates a query that will match any {@link IInstallableUnit} with the given
	 * id and version.
	 * 
	 * @param id The installable unit id to match, or <code>null</code> to match any id
	 * @param version The precise version that a matching unit must have
	 */
	public InstallableUnitQuery(String id, Version version) {
		this.id = id;
		this.range = (version == null || Version.emptyVersion.equals(version)) ? null : new VersionRange(version, true, version, true);
	}

	/**
	 * Creates a query that will match any {@link IInstallableUnit} with the given
	 * id and version.
	 * 
	 * @param versionedId The precise id/version combination that a matching unit must have
	 */
	public InstallableUnitQuery(IVersionedId versionedId) {
		this(versionedId.getId(), versionedId.getVersion());
	}

	/**
	 * Returns the id that this query will match against.
	 * @return The installable unit it
	 */
	public String getId() {
		return id;
	}

	/**
	 * Returns the version range that this query will match against.
	 * @return The installable unit version range.
	 */
	public VersionRange getRange() {
		return range;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.equinox.p2.query2.Query#isMatch(java.lang.Object)
	 */
	public boolean isMatch(IInstallableUnit candidate) {
		if (id != null && !id.equals(candidate.getId()))
			return false;
		if (range != null && !range.isIncluded(candidate.getVersion()))
			return false;
		return true;
	}

}

Back to the top