private T processActiveRegion( final ActiveRegion activeRegion, final LinkedHashSet<GATKSAMRecord> reads, final Queue<ActiveRegion> workQueue, final T sum, final ActiveRegionWalker<M, T> walker) { final ArrayList<GATKSAMRecord> placedReads = new ArrayList<GATKSAMRecord>(); for (final GATKSAMRecord read : reads) { final GenomeLoc readLoc = this.engine.getGenomeLocParser().createGenomeLoc(read); if (activeRegion.getLocation().overlapsP(readLoc)) { // The region which the highest amount of overlap is chosen as the primary region for the // read (tie breaking is done as right most region) long maxOverlap = activeRegion.getLocation().sizeOfOverlap(readLoc); ActiveRegion bestRegion = activeRegion; for (final ActiveRegion otherRegionToTest : workQueue) { if (otherRegionToTest.getLocation().sizeOfOverlap(readLoc) >= maxOverlap) { maxOverlap = otherRegionToTest.getLocation().sizeOfOverlap(readLoc); bestRegion = otherRegionToTest; } } bestRegion.add(read); // The read is also added to all other regions in which it overlaps but marked as // non-primary if (walker.wantsNonPrimaryReads()) { if (!bestRegion.equals(activeRegion)) { activeRegion.add(read); } for (final ActiveRegion otherRegionToTest : workQueue) { if (!bestRegion.equals(otherRegionToTest) && otherRegionToTest.getExtendedLoc().overlapsP(readLoc)) { otherRegionToTest.add(read); } } } placedReads.add(read); } else if (activeRegion.getExtendedLoc().overlapsP(readLoc) && walker.wantsNonPrimaryReads()) { activeRegion.add(read); } } reads.removeAll( placedReads); // remove all the reads which have been placed into their active region // WARNING: This hashset relies on reads being exactly equal when they are placed in the list as // when they are removed. So the ActiveRegionWalker can't modify the reads in any way. logger.debug( ">> Map call with " + activeRegion.getReads().size() + " " + (activeRegion.isActive ? "active" : "inactive") + " reads @ " + activeRegion.getLocation() + " with full extent: " + activeRegion.getReferenceLoc()); final M x = walker.map(activeRegion, null); return walker.reduce(x, sum); }
@Override public void flushVariable(@NotNull final DfaVariableValue variable) { List<DfaValue> updatedStack = ContainerUtil.map(myStack, value -> handleFlush(variable, value)); myStack.clear(); for (DfaValue value : updatedStack) { myStack.push(value); } doFlush(variable, false); flushDependencies(variable); myUnknownVariables.remove(variable); myUnknownVariables.removeAll(myFactory.getVarFactory().getAllQualifiedBy(variable)); myCachedHash = null; }
private static Set<TemplateContextType> getDirectlyApplicableContextTypes( @NotNull PsiFile file, int offset) { LinkedHashSet<TemplateContextType> set = new LinkedHashSet<TemplateContextType>(); LinkedList<TemplateContextType> contexts = buildOrderedContextTypes(); for (TemplateContextType contextType : contexts) { if (contextType.isInContext(file, offset)) { set.add(contextType); } } removeBases: while (true) { for (TemplateContextType type : set) { if (set.removeAll(getBases(type))) { continue removeBases; } } return set; } }
/** * @param addClearListItem - used for detecting whether the "Clear List" action should be added to * the end of the returned list of actions * @return */ public AnAction[] getRecentProjectsActions(boolean addClearListItem) { validateRecentProjects(); final Set<String> openedPaths = ContainerUtil.newHashSet(); for (Project openProject : ProjectManager.getInstance().getOpenProjects()) { ContainerUtil.addIfNotNull(openedPaths, getProjectPath(openProject)); } final LinkedHashSet<String> paths; synchronized (myStateLock) { paths = ContainerUtil.newLinkedHashSet(myState.recentPaths); } paths.remove(null); paths.removeAll(openedPaths); ArrayList<AnAction> actions = new ArrayList<AnAction>(); Set<String> duplicates = getDuplicateProjectNames(openedPaths, paths); for (final String path : paths) { final String projectName = getProjectName(path); String displayName; synchronized (myStateLock) { displayName = myState.names.get(path); } if (StringUtil.isEmptyOrSpaces(displayName)) { displayName = duplicates.contains(path) ? path : projectName; } // It's better don't to remove non-existent projects. Sometimes projects stored // on USB-sticks or flash-cards, and it will be nice to have them in the list // when USB device or SD-card is mounted if (new File(path).exists()) { actions.add(new ReopenProjectAction(path, projectName, displayName)); } } if (actions.isEmpty()) { return AnAction.EMPTY_ARRAY; } ArrayList<AnAction> list = new ArrayList<AnAction>(); for (AnAction action : actions) { list.add(action); } if (addClearListItem) { AnAction clearListAction = new AnAction(IdeBundle.message("action.clear.list")) { public void actionPerformed(AnActionEvent e) { final int rc = Messages.showOkCancelDialog( e.getData(PlatformDataKeys.PROJECT), "Would you like to clear the list of recent projects?", "Clear Recent Projects List", Messages.getQuestionIcon()); if (rc == 0) { synchronized (myStateLock) { myState.recentPaths.clear(); } WelcomeFrame.clearRecents(); } } }; list.add(Separator.getInstance()); list.add(clearListAction); } return list.toArray(new AnAction[list.size()]); }
private void setComboboxModel( final JComboBox comboBox, final VirtualFile initialTargetDirectorySourceRoot, final VirtualFile oldSelection, final ProjectFileIndex fileIndex, final VirtualFile[] sourceRoots, final Project project, final boolean forceIncludeAll, final Pass<String> updateErrorMessage) { final LinkedHashSet<PsiDirectory> targetDirectories = new LinkedHashSet<PsiDirectory>(); final HashMap<PsiDirectory, String> pathsToCreate = new HashMap<PsiDirectory, String>(); MoveClassesOrPackagesUtil.buildDirectoryList( new PackageWrapper(PsiManager.getInstance(project), getTargetPackage()), sourceRoots, targetDirectories, pathsToCreate); if (!forceIncludeAll && targetDirectories.size() > pathsToCreate.size()) { targetDirectories.removeAll(pathsToCreate.keySet()); } final ArrayList<DirectoryChooser.ItemWrapper> items = new ArrayList<DirectoryChooser.ItemWrapper>(); DirectoryChooser.ItemWrapper initial = null; DirectoryChooser.ItemWrapper oldOne = null; for (PsiDirectory targetDirectory : targetDirectories) { DirectoryChooser.ItemWrapper itemWrapper = new DirectoryChooser.ItemWrapper(targetDirectory, pathsToCreate.get(targetDirectory)); items.add(itemWrapper); final VirtualFile sourceRootForFile = fileIndex.getSourceRootForFile(targetDirectory.getVirtualFile()); if (sourceRootForFile == initialTargetDirectorySourceRoot) { initial = itemWrapper; } else if (sourceRootForFile == oldSelection) { oldOne = itemWrapper; } } items.add(NULL_WRAPPER); final DirectoryChooser.ItemWrapper selection = chooseSelection(initialTargetDirectorySourceRoot, fileIndex, items, initial, oldOne); final ComboBoxModel model = comboBox.getModel(); if (model instanceof CollectionComboBoxModel) { boolean sameModel = model.getSize() == items.size(); if (sameModel) { for (int i = 0; i < items.size(); i++) { final DirectoryChooser.ItemWrapper oldItem = (DirectoryChooser.ItemWrapper) model.getElementAt(i); final DirectoryChooser.ItemWrapper itemWrapper = items.get(i); if (!areItemsEquivalent(oldItem, itemWrapper)) { sameModel = false; break; } } } if (sameModel) { if (areItemsEquivalent( (DirectoryChooser.ItemWrapper) comboBox.getSelectedItem(), selection)) { return; } } } updateErrorMessage(updateErrorMessage, fileIndex, selection); Collections.sort( items, new Comparator<DirectoryChooser.ItemWrapper>() { @Override public int compare(DirectoryChooser.ItemWrapper o1, DirectoryChooser.ItemWrapper o2) { if (o1 == NULL_WRAPPER) return -1; if (o2 == NULL_WRAPPER) return 1; return o1.getRelativeToProjectPath().compareToIgnoreCase(o2.getRelativeToProjectPath()); } }); comboBox.setModel(new CollectionComboBoxModel(items, selection)); }