本文整理汇总了Java中java.util.HashSet.retainAll方法的典型用法代码示例。如果您正苦于以下问题:Java HashSet.retainAll方法的具体用法?Java HashSet.retainAll怎么用?Java HashSet.retainAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashSet
的用法示例。
在下文中一共展示了HashSet.retainAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reconfigure
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Apply Bundle matched properties.
*/
public static CloudIotOptions reconfigure(CloudIotOptions original, Bundle bundle) {
try {
if (Log.isLoggable(TAG, Log.INFO)) {
HashSet<String> valid = new HashSet<>(Arrays.asList(new String[] {"project_id",
"registry_id", "device_id","cloud_region", "mqtt_bridge_hostname",
"mqtt_bridge_port"}));
valid.retainAll(bundle.keySet());
Log.i(TAG, "Configuring options using the following intent extras: " + valid);
}
CloudIotOptions result = new CloudIotOptions();
result.projectId = bundle.getString("project_id", original.projectId);
result.registryId = bundle.getString("registry_id", original.registryId);
result.deviceId = bundle.getString("device_id", original.deviceId);
result.cloudRegion = bundle.getString("cloud_region", original.cloudRegion);
result.bridgeHostname = bundle.getString("mqtt_bridge_hostname",
original.bridgeHostname);
result.bridgePort = (short) bundle.getInt("mqtt_bridge_port", original.bridgePort);
return result;
} catch (Exception e) {
throw new IllegalArgumentException("While processing configuration options", e);
}
}
示例2: clearNearbyUrls
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Forget all nearby URLs and clear the notification.
*/
public void clearNearbyUrls() {
HashSet<String> intersection = new HashSet<>(mNearbyUrls);
intersection.retainAll(mPwsResultMap.keySet());
mNearbyUrls.clear();
putCachedNearbyUrls();
// Only notify listeners for URLs that were previously displayable (both nearby and
// resolved).
for (String url : intersection) {
safeNotifyNativeListenersOnLost(url);
}
clearNotification();
cancelClearNotificationAlarm();
}
示例3: getNamesOfClassesImplementingAllOf
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Returns the names of classes on the classpath that implement (or have superclasses that implement) all of the
* specified interfaces or their subinterfaces. Should be called after scan(), and returns matching interfaces
* whether or not an InterfaceMatchProcessor was added to the scanner before the call to scan(). Does not call the
* classloader on the matching classes, just returns their names.
*
* @param implementedInterfaceNames
* The name of the interfaces that classes need to implement.
* @return A list of the names of matching classes, or the empty list if none.
*/
public List<String> getNamesOfClassesImplementingAllOf(final String... implementedInterfaceNames) {
HashSet<String> classNames = new HashSet<String>();
for (int i = 0; i < implementedInterfaceNames.length; i++) {
String implementedInterfaceName = implementedInterfaceNames[i];
List<String> namesOfImplementingClasses = getNamesOfClassesImplementing(implementedInterfaceName);
if (i == 0) {
classNames.addAll(namesOfImplementingClasses);
}
else {
classNames.retainAll(namesOfImplementingClasses);
}
}
return new ArrayList<String>(classNames);
}
示例4: getNamesOfClassesWithAnnotationsAllOf
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Returns the names of classes on the classpath that have all of the specified annotations. Should be called after
* scan(), and returns matching classes whether or not a ClassAnnotationMatchProcessor was added to the scanner
* before the call to scan(). Does not call the classloader on the matching classes, just returns their names.
*
* @param annotationNames
* The annotation names.
* @return A list of the names of classes that have all of the annotations, or the empty list if none.
*/
public List<String> getNamesOfClassesWithAnnotationsAllOf(final String... annotationNames) {
HashSet<String> classNames = new HashSet<String>();
for (int i = 0; i < annotationNames.length; i++) {
String annotationName = annotationNames[i];
List<String> namesOfClassesWithMetaAnnotation = getNamesOfClassesWithAnnotation(annotationName);
if (i == 0) {
classNames.addAll(namesOfClassesWithMetaAnnotation);
}
else {
classNames.retainAll(namesOfClassesWithMetaAnnotation);
}
}
return new ArrayList<String>(classNames);
}
示例5: getNamesOfClassesWithMetaAnnotationsAllOf
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Returns the names of classes on the classpath that have all of the specified meta-annotations (i.e. classes that
* are annotated with all of the requested meta-annotations, or with an annotation that is annotated with each of
* the meta-annotations). Should be called after scan(), and returns matching classes whether or not a
* ClassAnnotationMatchProcessor was added to the scanner before the call to scan(). Does not call the classloader
* on the matching classes, just returns their names.
*
* @param metaAnnotationNames
* The meta-annotation names.
* @return A list of the names of classes that have all of the meta-annotations, or the empty list if none.
*/
public List<String> getNamesOfClassesWithMetaAnnotationsAllOf(final String... metaAnnotationNames) {
HashSet<String> classNames = new HashSet<String>();
for (int i = 0; i < metaAnnotationNames.length; i++) {
String metaAnnotationName = metaAnnotationNames[i];
List<String> namesOfClassesWithMetaAnnotation = getNamesOfClassesWithMetaAnnotation(metaAnnotationName);
if (i == 0) {
classNames.addAll(namesOfClassesWithMetaAnnotation);
}
else {
classNames.retainAll(namesOfClassesWithMetaAnnotation);
}
}
return new ArrayList<String>(classNames);
}
示例6: ReachabilityAnalysis
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Some polygons cannot be reached we find them with the help of navigation
* graph Definition: 1. Any polygon with navigation point is reachable 2.
* Any polygon sharing edge with a reachable polygon is also reachable.
*/
public ReachabilityAnalysis(
PolygonAnalysis polygonAnalysis,
LineSegmentAnalysis lineSegmentAnalysis,
NavGraphAnalysis navGraphAnalysis,
Logger log
) {
if (navGraphAnalysis.navPointToInfoMap.values().isEmpty()) {
log.warning("There are no navpoints present within the worldview, could not analyze reachability.");
return;
}
// navigation graph is expected to be sane, so all off-mesh nav points are reachable
reachableOffMeshNavPoints.addAll( navGraphAnalysis.offMeshNavPoints );
reachableOffMeshNavLinks.addAll( navGraphAnalysis.offMeshNavLinks );
for (NavGraphAnalysis.NavPointInfo navPointInfo : navGraphAnalysis.navPointToInfoMap.values()) {
recursivelyMarkAsReachable( navPointInfo.polygonId, polygonAnalysis, lineSegmentAnalysis );
}
log.info("Reachability analysis: There are " + reachablePolygons.size() + " reachable polygons containing " + reachableVertices.size() + " vertices.");
// create vertex ID to containing polygon map without unreachable polygons
for (int reachableVertexId : reachableVertices ) {
HashSet<Integer> containingPolygonIds = Sets.newHashSet();
containingPolygonIds.addAll( polygonAnalysis.vertexIdToInfoMap.get(reachableVertexId).containingPolygonIdToVertexIndexMap.keySet() );
containingPolygonIds.retainAll(reachablePolygons);
vertexIdToContainingPolygonsMap.put( reachableVertexId, containingPolygonIds );
}
}
示例7: validateHole
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygon
*/
protected void validateHole(LineStringBuilder shell, LineStringBuilder hole) {
HashSet<Coordinate> exterior = Sets.newHashSet(shell.coordinates);
HashSet<Coordinate> interior = Sets.newHashSet(hole.coordinates);
exterior.retainAll(interior);
if (exterior.size() >= 2) {
throw new InvalidShapeException("Invalid polygon, interior cannot share more than one point with the exterior");
}
}
示例8: excludes
import java.util.HashSet; //导入方法依赖的package包/类
public static HashSet<String> excludes(HashSet<String> toExclude, HashMap<HashSet<String>, HashSet<String>> mapping){
HashSet<String> relevantRecipes = new HashSet<String>();
HashSet<String> temp = new HashSet<String>();
HashSet<String> empty = new HashSet<String>();
for(HashSet<String> key:mapping.keySet()){
temp.addAll(toExclude);
temp.retainAll(key);
if(temp.size() == 0){ //make sure all items in toExclude are NOT present by checking size of itersection
relevantRecipes.addAll(mapping.get(key));
} else{
temp.retainAll(empty); //avoids need to create new empty set in each iteration
}
}
return relevantRecipes;
}
示例9: startSearch
import java.util.HashSet; //导入方法依赖的package包/类
protected void startSearch(String SearchQuery) {
Intent searchIntent = new Intent(this, SearchResultActivity.class);
searchIntent.setAction(Intent.ACTION_SEARCH);
Bundle bundle = new Bundle();
bundle.putBoolean(ARG_IS_GLOBAL_SEARCH, true);
ArrayList<Integer> selectedSearchableBooks = new ArrayList<>();
if (shouldDisplayDownloadedOnly()) {
selectedSearchableBooks.addAll(selectedBooksIds);
} else {
HashSet<Integer> downloadedHashSet = mBooksInformationDbHelper.getBookIdsDownloadedOnly();
downloadedHashSet.retainAll(selectedBooksIds);
if (downloadedHashSet.size() == 0) {
Toast.makeText(this, R.string.no_downloaded_selected_books, Toast.LENGTH_SHORT).show();
return;
} else {
if (downloadedHashSet.size() < selectedBooksIds.size()) {
Toast.makeText(this, R.string.searching_downloaded_only, Toast.LENGTH_SHORT).show();
}
selectedSearchableBooks.addAll(downloadedHashSet);
}
}
bundle.putIntegerArrayList(SearchResultFragment.ARG_SEARCHABLE_BOOKS, selectedSearchableBooks);
bundle.putString(SearchManager.QUERY, SearchQuery);
searchIntent.putExtras(bundle);
startActivity(searchIntent);
}
示例10: validateHole
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygon
*/
protected void validateHole(BaseLineStringBuilder shell, BaseLineStringBuilder hole) {
HashSet exterior = Sets.newHashSet(shell.points);
HashSet interior = Sets.newHashSet(hole.points);
exterior.retainAll(interior);
if (exterior.size() >= 2) {
throw new InvalidShapeException("Invalid polygon, interior cannot share more than one point with the exterior");
}
}
示例11: selectFlagAttributes
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Select a subset of principal attributes - flag attributes.
*
* @param attributes attributes to get flags from
* @return flag attributes subset
*/
public static Set<String> selectFlagAttributes(Set<String> attributes) {
HashSet<String> flags = new HashSet<String>(Arrays.asList(flagsArray));
flags.retainAll(attributes);
return flags;
}
示例12: intersection
import java.util.HashSet; //导入方法依赖的package包/类
/**
* @see org.odmg.DSet#intersection(DSet)
*/
public DSet intersection(DSet otherSet) {
read();
HashSet newset = new HashSet( this.set.size() );
newset.addAll(this.set);
newset.retainAll(otherSet);
return new Set(getSession(), newset);
}
示例13: jaccard
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Returns the jaccard index of the given two terms.
*
* @param t1
* @param t2
* @return
*/
public double jaccard(int t1, int t2)
{
if (t1 == t2) {
return 1;
}
if (this.jaccardMatrix != null) {
if (t1 < t2) {
return this.jaccardMatrix[t1][t2 - t1 - 1];
} else {
return this.jaccardMatrix[t2][t1 - t2 - 1];
}
}
Term tt1 = this.slimGraph.getVertex(t1);
Term tt2 = this.slimGraph.getVertex(t2);
HashSet<ByteString> tt1a =
new HashSet<ByteString>(this.termEnumerator.getAnnotatedGenes(tt1.getID()).totalAnnotated);
HashSet<ByteString> tt2a =
new HashSet<ByteString>(this.termEnumerator.getAnnotatedGenes(tt2.getID()).totalAnnotated);
HashSet<ByteString> union = new HashSet<ByteString>(tt1a);
union.addAll(tt2a);
tt1a.retainAll(tt2a);
return (double) tt1a.size() / union.size();
}
示例14: findLeastLoadedClientWithPreviousStandByTask
import java.util.HashSet; //导入方法依赖的package包/类
private ClientState findLeastLoadedClientWithPreviousStandByTask(final TaskId taskId, final Set<ID> clientsWithin) {
final Set<ID> ids = previousStandbyTaskAssignment.get(taskId);
if (ids == null) {
return null;
}
final HashSet<ID> constrainTo = new HashSet<>(ids);
constrainTo.retainAll(clientsWithin);
return leastLoaded(taskId, constrainTo);
}
示例15: mergeNodes
import java.util.HashSet; //导入方法依赖的package包/类
/**
* Merges the network model by using at least two (selected) nodes.
*
* @param nodes2Merge the nodes that have to be merge, as GraphNodePairs
* @return the residual GraphNode, after the merge process
*/
public GraphNodePairs mergeNodes(GraphNodePairs nodes2Merge) {
// --- Preliminary check ----------------------------------------------
if (nodes2Merge==null)return null;
if (nodes2Merge.getGraphNode1()==null) return null;
if (nodes2Merge.getGraphNode2Hash()==null) return null;
// --- Have a look to the case of one or more DistributionNode's ------
nodes2Merge = this.getValidGraphNodePairConfig4Merging(nodes2Merge);
if (nodes2Merge==null) return null;
// --- Create revert information --------------------------------------
HashSet<GraphNodePairsRevert> revertInfos = new HashSet<GraphNodePairsRevert>();
// --------------------------------------------------------------------
// --- Get first GraphNode and NetworkCommponent ----------------------
GraphNode graphNode1 = (GraphNode) this.getGraphElement(nodes2Merge.getGraphNode1().getId());
if (graphNode1==null) return null;
NetworkComponent comp1 = this.getNetworkComponents(graphNode1).iterator().next();
// --------------------------------------------------------------------
// --- Walk through the list of GraphNode that have to be merged ------
for (GraphNode graphNode2 : nodes2Merge.getGraphNode2Hash() ) {
// --- Make sure that this is a current GraphNode -----------------
graphNode2 = (GraphNode) this.getGraphElement(graphNode2.getId());
if (graphNode2==null) continue;
NetworkComponent comp2 = this.getNetworkComponents(graphNode2).iterator().next();
// --- Find the intersection set of the Graph elements of the two NetworkComponent
// --- NetworkComponent in order to make sure that they are not already connected
HashSet<String> intersection = new HashSet<String>(comp1.getGraphElementIDs());
intersection.retainAll(comp2.getGraphElementIDs());
// Checking the constraint - Two network components can have maximum one node in common
if (intersection.size() == 0) {
// --- No intersection node found - proceed -------------------
for (GraphEdge edgeOld : this.getGraph().getIncidentEdges(graphNode2)) {
// --- switch connection to graphNode1 ----------
GraphEdge edgeNew = this.switchEdgeBetweenGraphNodes(edgeOld, graphNode1, graphNode2);
this.removeGraphElementToNetworkComponent(edgeOld);
this.addGraphElementToNetworkComponentRelation(edgeNew, comp2);
// --- store revert information -----------------
GraphNodePairsRevert revert = new GraphNodePairsRevert(graphNode2, edgeNew);
revertInfos.add(revert);
}
// --- Updating the graph element IDs of the component --------
comp2.getGraphElementIDs().remove(graphNode2.getId());
comp2.getGraphElementIDs().add(graphNode1.getId());
this.addGraphElementToNetworkComponentRelation(graphNode1, comp2);
// --- Removing node2 from the graph and network model --------
this.getGraph().removeVertex(graphNode2);
this.graphElements.remove(graphNode2.getId());
}
}
nodes2Merge.setRevertInfos(revertInfos);
return nodes2Merge;
}