Example #1
0
 public ListValue except(ListValue other) {
   LinkedHashSet<SingleValue> set = new LinkedHashSet<SingleValue>();
   set.addAll(this.values);
   set.removeAll(other.values);
   ListValue result = new ListValue();
   result.values.addAll(set);
   return result;
 }
  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);
  }
 public synchronized void drainTo(List<T> list, int maxItems) {
   List<T> intermediateList = Lists.newArrayList();
   int ctr = 0;
   for (T item : items) {
     intermediateList.add(item);
     ctr++;
     if (ctr == maxItems) break;
   }
   list.addAll(intermediateList);
   items.removeAll(intermediateList);
 }
 public void forget(ConceptInstanceMap other) {
   for (String cn : other.myNodes.keySet()) {
     assert myNodes.containsKey(cn); // other shall be subset of this map
     List<SNode> nodes = myNodes.get(cn);
     LinkedHashSet<SNode> newNodes = new LinkedHashSet<SNode>(nodes);
     newNodes.removeAll(other.myNodes.get(cn));
     if (newNodes.isEmpty()) {
       myNodes.remove(cn);
     } else {
       myNodes.put(cn, new ArrayList<SNode>(newNodes));
     }
   }
 }
Example #5
0
 public MPSModulesClosure designtimeClosure() {
   // direct and indirect dependencies of the modules, languages used and their runtimes
   collectDependencies(initialModules, false);
   collectAllUsedLanguageRuntimesAndTheirDeps(initialModules);
   for (SNode m : Sequence.fromIterable(initialModules)) {
     Iterable<SNode> usedLanguages = getUsedLanguages(m);
     collectDependencies(usedLanguages, false);
     collectAllUsedLanguageRuntimesAndTheirDeps(usedLanguages);
     modules.addAll(Sequence.fromIterable(usedLanguages).toListSequence());
   }
   modules.removeAll(Sequence.fromIterable(initialModules).toListSequence());
   return this;
 }
Example #6
0
  @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;
  }
  /**
   * Removes the values from the existing values associated with the specified key. If the map
   * doesn't contain the given values, removal will not happen.
   *
   * @param map map holding multiple values for a key
   * @param key key specifying values
   * @param values values to be removed
   * @param <K> type of the key
   * @param <V> type of the element of the list
   * @return true if the operation succeeds, false otherwise
   */
  private <K, V> boolean removeValues(
      TransactionalMap<K, Set<V>> map, K key, List<? extends V> values) {
    Set<V> oldValues = map.putIfAbsent(key, new LinkedHashSet<>());
    if (oldValues == null) {
      return true;
    }

    if (values.stream().allMatch(x -> !oldValues.contains(x))) {
      // don't write map because none of the values are stored
      return true;
    }

    LinkedHashSet<V> newValues = new LinkedHashSet<>(oldValues);
    newValues.removeAll(values);
    return map.replace(key, oldValues, newValues);
  }
  /** Runs Program One */
  public void run() {
    System.out.println("Problem One running...\n");

    // Input
    System.out.println(
        "Type a word to be added to Set One and press Enter to add. Type -1 to finish. ");
    while (!input.equals("-1")) {
      System.out.print("Set One, Word " + (setOne.size() + 1) + ": ");
      input = in.nextLine();
      if (!(input.isEmpty() || input.equals("-1"))) {
        setOne.add(input);
      }
    }

    input = "";
    System.out.println();
    System.out.println(
        "Type a word to be added to Set Two and press Enter to add. Type -1 to finish. ");
    while (!input.equals("-1")) {
      System.out.print("Set Two, Word " + (setTwo.size() + 1) + ": ");
      input = in.nextLine();
      if (!(input.isEmpty() || input.equals("-1"))) {
        setTwo.add(input);
      }
    }

    // Clone setOne to retain original copy of data
    LinkedHashSet<String> cloneOne = (LinkedHashSet<String>) setOne.clone();
    LinkedHashSet<String> cloneTwo = (LinkedHashSet<String>) setOne.clone();
    LinkedHashSet<String> cloneThree = (LinkedHashSet<String>) setOne.clone();

    // Unionize the sets by appending setTwo to setOne (only unique elements
    // are added)
    cloneOne.addAll(setTwo);
    // Intersect sets by removing elements in setOne NOT found in setTwo
    cloneTwo.retainAll(setTwo);
    // Differentiate sets by removing elements in setOne found in setTwo
    cloneThree.removeAll(setTwo);

    // Output
    System.out.println();
    System.out.println("SetOne: " + setOne.toString());
    System.out.println("SetTwo: " + setTwo.toString());
    System.out.println("Union of SetOne to SetTwo : " + cloneOne.toString());
    System.out.println("Intersection of SetOne to SetTwo : " + cloneTwo.toString());
    System.out.println("Difference of SetOne to SetTwo " + cloneThree.toString());
  }
Example #9
0
  public MPSModulesClosure closure() {
    // get all direct dependencies abd runtimes, plus re-exported dependencies thereof.
    Set<SNode> langs = SetSequence.fromSet(new HashSet<SNode>());
    Set<SNode> solutions = SetSequence.fromSet(new HashSet<SNode>());

    for (SNode module : Sequence.fromIterable(initialModules)) {
      List<SNode> firstLevelDeps =
          Sequence.fromIterable(getDependencies(module, false)).toListSequence();
      collectDependencies(firstLevelDeps, true);
      fillUsedLanguageRuntimes(module, langs, solutions);
      modules.addAll(firstLevelDeps);
    }
    modules.addAll(solutions);
    languagesWithRuntime.addAll(langs);
    collectDependencies(((Iterable<SNode>) solutions), true);
    modules.removeAll(Sequence.fromIterable(initialModules).toListSequence());
    return this;
  }
Example #10
0
  /**
   * Method to remove all elements from the collection from the LinkedHashSet.
   *
   * @param elements The collection of elements to remove
   * @return Whether it was removed ok.
   */
  public boolean removeAll(java.util.Collection elements) {
    boolean success = delegate.removeAll(elements);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
      // Relationship management
      Iterator iter = elements.iterator();
      RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
      while (iter.hasNext()) {
        relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
      }
    }

    if (ownerOP != null && elements != null && !elements.isEmpty()) {
      // Cascade delete
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue the cascade delete
        Iterator iter = elements.iterator();
        while (iter.hasNext()) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
        }
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        Iterator iter = elements.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }
    }

    if (success) {
      makeDirty();
      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }

    return success;
  }
  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;
    }
  }
Example #12
0
 Set<String> getReferencesWithoutDefinition() {
   LinkedHashSet<String> referencesCopy = Sets.newLinkedHashSet(references);
   referencesCopy.removeAll(definitions);
   return referencesCopy;
 }
  /**
   * @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));
 }
Example #15
0
 public MPSModulesClosure runtimeClosure() {
   collectDependencies(initialModules, false);
   collectAllUsedLanguageRuntimesAndTheirDeps(initialModules);
   modules.removeAll(Sequence.fromIterable(initialModules).toListSequence());
   return this;
 }