com.google.common.collect.Sets#newCopyOnWriteArraySet ( )源码实例Demo

下面列出了com.google.common.collect.Sets#newCopyOnWriteArraySet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private static Set<CompletionResult> removeDuplicateCompletions(Set<CompletionResult> unfilteredCompletions) {
  // We sort the elements according to name, giving preference to compiler-provided results
  // if the two names are identical.
  CompletionResult sorted[] = unfilteredCompletions.toArray(new CompletionResult[]{});
  Arrays.sort(sorted, new Comparator<CompletionResult>() {
    @Override
    public int compare(CompletionResult o1, CompletionResult o2) {
      LookupElement el1 = o1.getLookupElement();
      LookupElement el2 = o2.getLookupElement();
      String fnName1 = null != el1 ? el1.getLookupString() : null;
      String fnName2 = null != el2 ? el2.getLookupString() : null;

      // Can't really throw a null pointer exception... It would be thrown past sort.
      if (null == fnName1) return -1;
      if (null == fnName2) return 1;

      int comp = fnName1.compareTo(fnName2);
      if (0 == comp) {
        Object obj1 = el1.getObject();
        Object obj2 = el2.getObject();

        comp = obj1 instanceof HaxeCompilerCompletionItem
               ? (obj2 instanceof HaxeCompilerCompletionItem ? 0 : -1)
               : (obj2 instanceof HaxeCompilerCompletionItem ? 1 : 0);
      }
      return comp;
    }
  });

  // Now remove duplicates by looping over the list, dropping any that match the entry prior.
  ArrayList<CompletionResult> deduped = new ArrayList<CompletionResult>();
  String lastName = null;
  for (CompletionResult next: sorted) {
    String nextName = getFunctionName(next);
    // In the long run, it's probably not good enough just to check the name.  Multiple argument types may
    // be present, and we may be able to filter based on the local variables available.
    if (null == lastName || !lastName.equals(nextName)) {
      deduped.add(next);
    }
    lastName = nextName;
  }
  return Sets.newCopyOnWriteArraySet(deduped);
}
 
源代码2 项目: util   文件: VarExporter.java
@Override
public Set<Variable> get() {
    return Sets.newCopyOnWriteArraySet();
}