/** * Schedules runnable task for execution. * * @param w Runnable task. * @throws GridException Thrown if any exception occurred. */ @SuppressWarnings({"CatchGenericClass", "ProhibitedExceptionThrown"}) public void execute(final GridWorker w) throws GridException { workers.add(w); try { exec.execute( new Runnable() { @Override public void run() { try { w.run(); } finally { workers.remove(w); } } }); } catch (RejectedExecutionException e) { workers.remove(w); throw new GridComputeExecutionRejectedException( "Failed to execute worker due to execution rejection.", e); } catch (RuntimeException e) { workers.remove(w); throw new GridException("Failed to execute worker due to runtime exception.", e); } catch (Error e) { workers.remove(w); throw e; } }
private void associateWithBuildRun( BuildRun buildRun, Collection<ChangeSet> changeSets, Set<PrimaryWorkitem> workitems) { for (ChangeSet changeSet : changeSets) { buildRun.getChangeSets().add(changeSet); for (PrimaryWorkitem workitem : workitems) { if (workitem.isClosed()) { logger.println(MessagesRes.workitemClosedCannotAttachData(workitem.getDisplayID())); continue; } final Collection<BuildRun> completedIn = workitem.getCompletedIn(); final List<BuildRun> toRemove = new ArrayList<BuildRun>(completedIn.size()); changeSet.getPrimaryWorkitems().add(workitem); for (BuildRun otherRun : completedIn) { if (otherRun.getBuildProject().equals(buildRun.getBuildProject())) { toRemove.add(otherRun); } } for (BuildRun buildRunDel : toRemove) { completedIn.remove(buildRunDel); } completedIn.add(buildRun); } } }
@Override @Nullable public Collection<PsiImportStatementBase> findRedundantImports(final PsiJavaFile file) { final PsiImportList importList = file.getImportList(); if (importList == null) return null; final PsiImportStatementBase[] imports = importList.getAllImportStatements(); if (imports.length == 0) return null; Set<PsiImportStatementBase> allImports = new THashSet<PsiImportStatementBase>(Arrays.asList(imports)); final Collection<PsiImportStatementBase> redundant; if (FileTypeUtils.isInServerPageFile(file)) { // remove only duplicate imports redundant = ContainerUtil.newIdentityTroveSet(); ContainerUtil.addAll(redundant, imports); redundant.removeAll(allImports); for (PsiImportStatementBase importStatement : imports) { if (importStatement instanceof JspxImportStatement && importStatement.isForeignFileImport()) { redundant.remove(importStatement); } } } else { redundant = allImports; final List<PsiFile> roots = file.getViewProvider().getAllFiles(); for (PsiElement root : roots) { root.accept( new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference) { if (!reference.isQualified()) { final JavaResolveResult resolveResult = reference.advancedResolve(false); if (!inTheSamePackage(file, resolveResult.getElement())) { final PsiElement resolveScope = resolveResult.getCurrentFileResolveScope(); if (resolveScope instanceof PsiImportStatementBase) { final PsiImportStatementBase importStatementBase = (PsiImportStatementBase) resolveScope; redundant.remove(importStatementBase); } } } super.visitReferenceElement(reference); } private boolean inTheSamePackage(PsiJavaFile file, PsiElement element) { if (element instanceof PsiClass && ((PsiClass) element).getContainingClass() == null) { final PsiFile containingFile = element.getContainingFile(); if (containingFile instanceof PsiJavaFile) { return Comparing.strEqual( file.getPackageName(), ((PsiJavaFile) containingFile).getPackageName()); } } return false; } }); } } return redundant; }
private void remove() { Collection<SamplingTask> samplers = samplingTasks.get(samplingPeriod); if (samplers == null) { return; } samplers.remove(this); }
public static void main(String[] args) { Collection c = new ArrayList(); // 添加元素 c.add("孙悟空"); // 虽然集合里不能放基本类型的值,但Java支持自动装箱 c.add(6); System.out.println("c集合的元素个数为:" + c.size()); // 删除指定元素 c.remove(6); System.out.println("c集合的元素个数为:" + c.size()); // 判断是否包含指定字符串 System.out.println("c集合的是否包含\"孙悟空\"字符串:" + c.contains("孙悟空")); c.add("轻量级Java EE企业应用实战"); System.out.println("c集合的元素:" + c); Collection books = new HashSet(); books.add("轻量级Java EE企业应用实战"); books.add("疯狂Java讲义"); System.out.println("c集合是否完全包含books集合?" + c.containsAll(books)); // 用c集合减去books集合里的元素 c.removeAll(books); System.out.println("c集合的元素:" + c); // 删除c集合里所有元素 c.clear(); System.out.println("c集合的元素:" + c); // books集合里只剩下c集合里也包含的元素 books.retainAll(c); System.out.println("books集合的元素:" + books); }
public void setHighlightingEnabled(@NotNull PsiFile file, boolean value) { if (value) { myDisabledHighlightingFiles.remove(file); } else { myDisabledHighlightingFiles.add(file); } }
@Override protected void doOKAction() { apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue()); final Collection<SeverityBasedTextAttributes> infoTypes = new HashSet<SeverityBasedTextAttributes>( SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar)); final ListModel listModel = myOptionsList.getModel(); final List<HighlightSeverity> order = new ArrayList<HighlightSeverity>(); for (int i = listModel.getSize() - 1; i >= 0; i--) { final SeverityBasedTextAttributes info = (SeverityBasedTextAttributes) listModel.getElementAt(i); order.add(info.getSeverity()); if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) { infoTypes.remove(info); final Color stripeColor = info.getAttributes().getErrorStripeColor(); mySeverityRegistrar.registerSeverity( info, stripeColor != null ? stripeColor : LightColors.YELLOW); } } for (SeverityBasedTextAttributes info : infoTypes) { mySeverityRegistrar.unregisterSeverity(info.getSeverity()); } mySeverityRegistrar.setOrder(order); super.doOKAction(); }
private void remove() { Collection<PerformanceProbe> probes = _perfProbes.get(outputPeriod); if (probes == null) { return; } probes.remove(this); }
@Override public Collection<String> wordsNearest(String label, int n) { Collection<String> collection = wordsNearest(Arrays.asList(label), new ArrayList<String>(), n + 1); if (collection.contains(label)) collection.remove(label); return collection; }
protected <T> List<T> intersect(Collection<? extends T> a, Collection<? extends T> b) { List<T> result = new ArrayList<T>(); for (T t : a) { if (b.remove(t)) result.add(t); } return result; }
@Override public void setHighlightingEnabled(@NotNull PsiFile file, boolean value) { VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file); if (value) { myDisabledHighlightingFiles.remove(virtualFile); } else { myDisabledHighlightingFiles.add(virtualFile); } }
public void setImportHintsEnabled(@NotNull PsiFile file, boolean value) { VirtualFile vFile = file.getVirtualFile(); if (value) { myDisabledHintsFiles.remove(vFile); stopProcess(true); } else { myDisabledHintsFiles.add(vFile); HintManager.getInstance().hideAllHints(); } }
/** * Removed rejected merge requests from merge_rsps and coords. This method has a lock on * merge_rsps */ private void removeRejectedMergeRequests(Collection<Address> coords) { for (Map.Entry<Address, MergeData> entry : merge_rsps.getResults().entrySet()) { Address member = entry.getKey(); MergeData data = entry.getValue(); if (data.merge_rejected) { if (data.getSender() != null) coords.remove(data.getSender()); merge_rsps.remove(member); } } }
public void markBCDirty(final Module module, final FlexBuildConfiguration bc) { final Collection<BCInfo> infosForModule = myCache.get(module); final BCInfo existingInfo = infosForModule == null ? null : findCacheForBC(infosForModule, bc); if (existingInfo != null) { infosForModule.remove(existingInfo); if (infosForModule.isEmpty()) { myCache.remove(module); } } }
private void update() { if (party.memb != om) { Collection<Member> old = new HashSet<Member>(avs.keySet()); for (final Member m : (om = party.memb).values()) { if (m.gobid == ign) continue; Avaview w = avs.get(m); if (w == null) { w = new Avaview(Coord.z, this, m.gobid, new Coord(27, 27)) { private Tex tooltip = null; public Object tooltip(Coord c, boolean again) { Gob gob = m.getgob(); if (gob == null) return (tooltip); KinInfo ki = gob.getattr(KinInfo.class); if (ki == null) return (null); return (tooltip = ki.rendered()); } }; avs.put(m, w); } else { old.remove(m); } } for (Member m : old) { ui.destroy(avs.get(m)); avs.remove(m); } List<Map.Entry<Member, Avaview>> wl = new ArrayList<Map.Entry<Member, Avaview>>(avs.entrySet()); Collections.sort( wl, new Comparator<Map.Entry<Member, Avaview>>() { public int compare(Entry<Member, Avaview> a, Entry<Member, Avaview> b) { return (a.getKey().gobid - b.getKey().gobid); } }); int i = 0; for (Map.Entry<Member, Avaview> e : wl) { e.getValue().c = new Coord((i % 2) * 43, (i / 2) * 43 + 24); i++; } } for (Map.Entry<Member, Avaview> e : avs.entrySet()) { e.getValue().color = e.getKey().col; } if ((avs.size() > 0) && (leave == null)) { leave = new Button(Coord.z, 84, this, "Leave party"); } if ((avs.size() == 0) && (leave != null)) { ui.destroy(leave); leave = null; } sz.y = MainFrame.getScreenSize().y - c.y; }
@SmallTest @MediumTest @LargeTest public void testCollectionRemoveThrows() throws JSONException { try { Collection<Integer> collection = GraphObject.Factory.createList(Integer.class); collection.remove(5); fail("Expected exception"); } catch (UnsupportedOperationException exception) { } }
public boolean remove(final K key, final V value) { final Collection<V> values = myMap.get(key); if (values != null) { boolean removed = values.remove(value); if (values.isEmpty()) { myMap.remove(key); } return removed; } return false; }
@SuppressWarnings("unchecked") private void addExcludeRuleInternal(Map map, Object o) { Collection excludes = (Collection) map.get(EXCLUDES); if (excludes == null) { excludes = new ArrayList(); map.put(EXCLUDES, excludes); } Collection includes = (Collection) map.get(INCLUDES); if (includes != null) includes.remove(o); excludes.add(o); }
public boolean testSizeRemove() { description = "remove decreases size by 1"; Iterator it = c.iterator(); precondition = new Boolean(it.hasNext()); Object e = it.hasNext() ? it.next() : new Object(); // precondition = new Boolean(c.contains(e)); // precondition = Boolean.TRUE; int s = c.size(); c.remove(e); return c.size() == s - 1; }
/** * Remove status from presets. * * @param statusMode * @param statusText */ public void removeSavedStatus(final SavedStatus savedStatus) { if (!savedStatuses.remove(savedStatus)) return; Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance() .remove(savedStatus.getStatusMode(), savedStatus.getStatusText()); } }); }
private void checkOverwrites(final Project project) { final Collection<AddedFileInfo> addedFileInfos = myAddedFiles.get(project); final Collection<File> deletedFiles = myDeletedFiles.get(project); if (addedFileInfos.isEmpty() || deletedFiles.isEmpty()) return; final Iterator<AddedFileInfo> iterator = addedFileInfos.iterator(); while (iterator.hasNext()) { AddedFileInfo addedFileInfo = iterator.next(); final File ioFile = new File(addedFileInfo.myDir.getPath(), addedFileInfo.myName); if (deletedFiles.remove(ioFile)) { iterator.remove(); } } }
/** * Check if set of vertices contains another set * * @param vs1 Collection of vertices * @param vs2 Collection of vertices * @return <code>true</code> if vs2 is contained in vs1, <code>false</code> otherwise */ protected boolean contains(Collection<V> vs1, Collection<V> vs2) { if (vs2 == null || vs2.size() == 0) return true; if (vs1 == null || vs1.size() == 0) return false; Collection<V> v3 = new ArrayList<V>(vs1); Iterator<V> i = vs2.iterator(); while (i.hasNext()) { V v = i.next(); if (!v3.remove(v)) return false; } return true; }
public void cacheBC( final Module module, final FlexBuildConfiguration bc, final List<VirtualFile> configFiles) { Collection<BCInfo> infosForModule = myCache.get(module); if (infosForModule == null) { infosForModule = new ArrayList<BCInfo>(); myCache.put(module, infosForModule); } else { final BCInfo existingInfo = findCacheForBC(infosForModule, bc); if (existingInfo != null) { infosForModule.remove(existingInfo); } } final VirtualFile outputFile = FlexCompilationManager.refreshAndFindFileInWriteAction(bc.getActualOutputFilePath()); if (outputFile == null) return; final BCInfo bcInfo = new BCInfo(Factory.getCopy(bc), ModuleRootManager.getInstance(module).getSourceRootUrls()); infosForModule.add(bcInfo); bcInfo.addFileDependency(outputFile.getPath()); final String workDirPath = FlexUtils.getFlexCompilerWorkDirPath(module.getProject(), null); for (VirtualFile configFile : configFiles) { addFileDependencies(bcInfo, configFile, workDirPath); } if (bc.isTempBCForCompilation() && !bc.getCompilerOptions().getAdditionalConfigFilePath().isEmpty()) { bcInfo.addFileDependency(bc.getCompilerOptions().getAdditionalConfigFilePath()); } final BuildConfigurationNature nature = bc.getNature(); if (nature.isApp() && !nature.isWebPlatform()) { if (nature.isDesktopPlatform()) { if (!bc.getAirDesktopPackagingOptions().isUseGeneratedDescriptor()) { bcInfo.addFileDependency(bc.getAirDesktopPackagingOptions().getCustomDescriptorPath()); } } else { if (bc.getAndroidPackagingOptions().isEnabled() && !bc.getAndroidPackagingOptions().isUseGeneratedDescriptor()) { bcInfo.addFileDependency(bc.getAndroidPackagingOptions().getCustomDescriptorPath()); } if (bc.getIosPackagingOptions().isEnabled() && !bc.getIosPackagingOptions().isUseGeneratedDescriptor()) { bcInfo.addFileDependency(bc.getIosPackagingOptions().getCustomDescriptorPath()); } } } }
@Override public void removeSubscriber(User user, Test test) { Test freshTest = testDAO.get(test.getId()); Collection<User> testSubscribers = new ArrayList<>(freshTest.getSubscribers()); for (User testSubscriber : freshTest.getSubscribers()) { if (testSubscriber.getId().equals(user.getId())) { testSubscribers.remove(testSubscriber); } } test.setSubscribers(testSubscribers); testDAO.update(test); }
/** * Unregister the au with this Tdb for its plugin. * * @param au the TdbAu * @return <code>false</code> if au was not registered, otherwise <code>true</code> */ private boolean removeTdbAuForPlugin(TdbAu au) { // if can't add au to title, we need to undo the au // registration and re-throw the exception we just caught String pluginId = au.getPluginId(); Collection<TdbAu.Id> c = pluginIdTdbAuIdsMap.get(pluginId); if (c.remove(au.getId())) { if (c.isEmpty()) { pluginIdTdbAuIdsMap.remove(c); } tdbAuCount--; return true; } return false; }
private Object removeFromList(Serializable key, Object value) { Object ret = null; if (component.initialStateMarked() || value instanceof PartialStateHolder) { Collection<Object> deltaList = (Collection<Object>) deltaMap.get(key); if (deltaList != null) { ret = deltaList.remove(value); if (deltaList.isEmpty()) { deltaMap.remove(key); } } } Collection<Object> list = (Collection<Object>) get(key); if (list != null) { if (ret == null) { ret = list.remove(value); } else { list.remove(value); } if (list.isEmpty()) { defaultMap.remove(key); } } return ret; }
/** Try to figure out whether the predefined Templates have already been migrated. */ static boolean hasDeployed() { if (hasDeployed) { return true; } Collection<String> names = getPredefinedTemplateNames(); File dir = TemplateDatabase.TemplateDir; if (dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { String name = file.getName(); names.remove(name); } } return names.isEmpty(); }
/** * INTERNAL: Compares two Collections as sets (ignoring the order of the elements). Note that the * passed Collections are cloned. Used for testing only. */ public static boolean areCollectionsEqualAsSets(Collection col1, Collection col2) { if (col1 == col2) { return true; } if (col1.size() != col2.size()) { return false; } Collection c1 = new ArrayList(col1); Collection c2 = new ArrayList(col2); for (Iterator i = c1.iterator(); i.hasNext(); ) { Object o = i.next(); c2.remove(o); } return c2.isEmpty(); }
/** * Removed rejected merge requests from merge_rsps and coords. This method has a lock on * merge_rsps */ private void removeRejectedMergeRequests(Collection<Address> coords) { int num_removed = 0; for (Iterator<Map.Entry<Address, MergeData>> it = merge_rsps.getResults().entrySet().iterator(); it.hasNext(); ) { Map.Entry<Address, MergeData> entry = it.next(); MergeData data = entry.getValue(); if (data.merge_rejected) { if (data.getSender() != null) coords.remove(data.getSender()); it.remove(); num_removed++; } } if (num_removed > 0) { if (log.isTraceEnabled()) log.trace(gms.local_addr + ": removed " + num_removed + " rejected merge responses"); } }
public boolean isNothingChangedSincePreviousCompilation( final Module module, final FlexBuildConfiguration bc) { final Collection<BCInfo> infosForModule = myCache.get(module); final BCInfo existingInfo = infosForModule == null ? null : findCacheForBC(infosForModule, bc); if (existingInfo == null) { return false; } final String[] currentSourceRoots = ModuleRootManager.getInstance(module).getSourceRootUrls(); if (!Arrays.equals(existingInfo.mySourceRootUrls, currentSourceRoots) || existingInfo.timestampsChanged()) { infosForModule.remove(existingInfo); if (infosForModule.isEmpty()) { myCache.remove(module); } return false; } return true; }