-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/QueryableArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008, 2023 IBM Corporation 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: | ||
* IBM Corporation - initial API and implementation | ||
* Cloudsmith Inc. - query indexes | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.p2tools.copiedfromp2; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils; | ||
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; | ||
import org.eclipse.equinox.internal.p2.metadata.TranslationSupport; | ||
import org.eclipse.equinox.internal.p2.metadata.index.CapabilityIndex; | ||
import org.eclipse.equinox.internal.p2.metadata.index.IdIndex; | ||
import org.eclipse.equinox.internal.p2.metadata.index.IndexProvider; | ||
import org.eclipse.equinox.p2.metadata.IInstallableUnit; | ||
import org.eclipse.equinox.p2.metadata.KeyWithLocale; | ||
import org.eclipse.equinox.p2.metadata.index.IIndex; | ||
|
||
public class QueryableArray extends IndexProvider<IInstallableUnit> { | ||
private final List<IInstallableUnit> dataSet; | ||
private IIndex<IInstallableUnit> capabilityIndex; | ||
private IIndex<IInstallableUnit> idIndex; | ||
private TranslationSupport translationSupport; | ||
|
||
public QueryableArray(IInstallableUnit[] ius) { | ||
dataSet = CollectionUtils.unmodifiableList(ius); | ||
} | ||
|
||
public QueryableArray(Collection<IInstallableUnit> ius) { | ||
dataSet = List.copyOf(ius); | ||
} | ||
|
||
@Override | ||
public Iterator<IInstallableUnit> everything() { | ||
return dataSet.iterator(); | ||
} | ||
|
||
@Override | ||
public boolean contains(IInstallableUnit element) { | ||
return dataSet.contains(element); | ||
} | ||
|
||
@Override | ||
public synchronized IIndex<IInstallableUnit> getIndex(String memberName) { | ||
if (InstallableUnit.MEMBER_PROVIDED_CAPABILITIES.equals(memberName)) { | ||
if (capabilityIndex == null) | ||
capabilityIndex = new CapabilityIndex(dataSet.iterator()); | ||
return capabilityIndex; | ||
} | ||
if (InstallableUnit.MEMBER_ID.equals(memberName)) { | ||
if (idIndex == null) | ||
idIndex = new IdIndex(dataSet.iterator()); | ||
return idIndex; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public synchronized Object getManagedProperty(Object client, String memberName, Object key) { | ||
if (!(client instanceof IInstallableUnit)) | ||
return null; | ||
IInstallableUnit iu = (IInstallableUnit) client; | ||
if (InstallableUnit.MEMBER_TRANSLATED_PROPERTIES.equals(memberName)) { | ||
if (translationSupport == null) | ||
translationSupport = new TranslationSupport(this); | ||
return key instanceof KeyWithLocale ? translationSupport.getIUProperty(iu, (KeyWithLocale) key) | ||
: translationSupport.getIUProperty(iu, key.toString()); | ||
} | ||
return null; | ||
} | ||
} |