Java Code Examples for com.intellij.util.containers.ContainerUtil#newConcurrentSet()

The following examples show how to use com.intellij.util.containers.ContainerUtil#newConcurrentSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualFileTrackerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Set<VirtualFileListener> getSet(final String fileUrl, final Map<String, Set<VirtualFileListener>> map) {
  Set<VirtualFileListener> listeners = map.get(fileUrl);

  if (listeners == null) {
    listeners = ContainerUtil.newConcurrentSet();
    map.put(fileUrl, listeners);
  }
  return listeners;
}
 
Example 2
Source File: CompletionService.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * The main method that is invoked to collect all the completion variants
 *
 * @param parameters Parameters specifying current completion environment
 * @param consumer   The consumer of the completion variants. Pass an instance of {@link BatchConsumer} if you need to receive information
 *                   about item batches generated by each completion contributor.
 */
public void performCompletion(CompletionParameters parameters, Consumer<? super CompletionResult> consumer) {
  final Set<LookupElement> lookupSet = ContainerUtil.newConcurrentSet();

  AtomicBoolean typoTolerant = new AtomicBoolean();

  BatchConsumer<CompletionResult> batchConsumer = new BatchConsumer<CompletionResult>() {
    @Override
    public void startBatch() {
      if (consumer instanceof BatchConsumer) {
        ((BatchConsumer)consumer).startBatch();
      }
    }

    @Override
    public void endBatch() {
      if (consumer instanceof BatchConsumer) {
        ((BatchConsumer)consumer).endBatch();
      }
    }

    @Override
    public void consume(CompletionResult result) {
      if (typoTolerant.get() && result.getLookupElement().getAutoCompletionPolicy() != AutoCompletionPolicy.NEVER_AUTOCOMPLETE) {
        result = result.withLookupElement(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(result.getLookupElement()));
      }
      if (lookupSet.add(result.getLookupElement())) {
        consumer.consume(result);
      }
    }
  };
  String prefix = suggestPrefix(parameters);
  getVariantsFromContributors(parameters, null, createMatcher(prefix, false), batchConsumer);
  if (lookupSet.isEmpty() && prefix.length() > 2) {
    typoTolerant.set(true);
    getVariantsFromContributors(parameters, null, createMatcher(prefix, true), batchConsumer);
  }
}
 
Example 3
Source File: LithoPluginUtils.java    From litho with Apache License 2.0 4 votes vote down vote up
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> key) {
  Set<Object> seen = ContainerUtil.newConcurrentSet();
  return t -> seen.add(key.apply(t));
}
 
Example 4
Source File: FileTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
FileTree() {
  myDirectory2Children = ContainerUtil.newConcurrentMap();
  myFiles = ContainerUtil.newConcurrentSet();
  myStrictDirectory2Children = ContainerUtil.newConcurrentMap();
}