Java 类com.intellij.util.containers.FlatteningIterator 实例源码

项目:intellij-ce-playground    文件:StatisticsWeigher.java   
@Override
public Iterable<LookupElement> classify(Iterable<LookupElement> source, final ProcessingContext context) {
  checkPrefixChanged(context);

  final Collection<List<LookupElement>> byWeight = buildMapByWeight(source, context).descendingMap().values();

  List<LookupElement> initialList = getInitialNoStatElements(source, context);

  //noinspection unchecked
  final THashSet<LookupElement> initialSet = new THashSet<LookupElement>(initialList, TObjectHashingStrategy.IDENTITY);
  final Condition<LookupElement> notInInitialList = new Condition<LookupElement>() {
    @Override
    public boolean value(LookupElement element) {
      return !initialSet.contains(element);
    }
  };

  return ContainerUtil.concat(initialList, new Iterable<LookupElement>() {
    @Override
    public Iterator<LookupElement> iterator() {
      return new FlatteningIterator<List<LookupElement>, LookupElement>(byWeight.iterator()) {
        @Override
        protected Iterator<LookupElement> createValueIterator(List<LookupElement> group) {
          return myNext.classify(ContainerUtil.findAll(group, notInInitialList), context).iterator();
        }
      };
    }
  });
}
项目:intellij-ce-playground    文件:ComparingClassifier.java   
@Override
public Iterable<T> classify(final Iterable<T> source, final ProcessingContext context) {
  List<T> nulls = null;
  TreeMap<Comparable, List<T>> map = new TreeMap<Comparable, List<T>>();
  for (T t : source) {
    final Comparable weight = getWeight(t, context);
    if (weight == null) {
      if (nulls == null) nulls = new SmartList<T>();
      nulls.add(t);
    } else {
      List<T> list = map.get(weight);
      if (list == null) {
        map.put(weight, list = new SmartList<T>());
      }
      list.add(t);
    }
  }

  final List<List<T>> values = new ArrayList<List<T>>();
  values.addAll(myNegated ? map.descendingMap().values() : map.values());
  ContainerUtil.addIfNotNull(values, nulls);

  return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
      return new FlatteningIterator<List<T>, T>(values.iterator()) {
        @Override
        protected Iterator<T> createValueIterator(List<T> group) {
          return myNext.classify(group, context).iterator();
        }
      };
    }
  };
}
项目:tools-idea    文件:StatisticsWeigher.java   
@Override
public Iterable<LookupElement> classify(Iterable<LookupElement> source, final ProcessingContext context) {
  checkPrefixChanged(context);

  final Collection<List<LookupElement>> byWeight = buildMapByWeight(source).descendingMap().values();

  List<LookupElement> initialList = getInitialNoStatElements(source, context);

  //noinspection unchecked
  final THashSet<LookupElement> initialSet = new THashSet<LookupElement>(initialList, TObjectHashingStrategy.IDENTITY);
  final Condition<LookupElement> notInInitialList = new Condition<LookupElement>() {
    @Override
    public boolean value(LookupElement element) {
      return !initialSet.contains(element);
    }
  };

  return ContainerUtil.concat(initialList, new Iterable<LookupElement>() {
    @Override
    public Iterator<LookupElement> iterator() {
      return new FlatteningIterator<List<LookupElement>, LookupElement>(byWeight.iterator()) {
        @Override
        protected Iterator<LookupElement> createValueIterator(List<LookupElement> group) {
          return myNext.classify(ContainerUtil.findAll(group, notInInitialList), context).iterator();
        }
      };
    }
  });
}
项目:tools-idea    文件:ComparingClassifier.java   
@Override
public Iterable<T> classify(final Iterable<T> source, final ProcessingContext context) {
  List<T> nulls = null;
  TreeMap<Comparable, List<T>> map = new TreeMap<Comparable, List<T>>();
  for (T t : source) {
    final Comparable weight = getWeight(t);
    if (weight == null) {
      if (nulls == null) nulls = new SmartList<T>();
      nulls.add(t);
    } else {
      List<T> list = map.get(weight);
      if (list == null) {
        map.put(weight, list = new SmartList<T>());
      }
      list.add(t);
    }
  }

  final List<List<T>> values = new ArrayList<List<T>>();
  values.addAll(myNegated ? map.descendingMap().values() : map.values());
  ContainerUtil.addIfNotNull(values, nulls);

  return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
      return new FlatteningIterator<List<T>, T>(values.iterator()) {
        @Override
        protected Iterator<T> createValueIterator(List<T> group) {
          return myNext.classify(group, context).iterator();
        }
      };
    }
  };
}
项目:consulo    文件:ComparingClassifier.java   
@Nonnull
@Override
public Iterable<T> classify(@Nonnull final Iterable<T> source, @Nonnull final ProcessingContext context) {
  List<T> nulls = null;
  TreeMap<Comparable, List<T>> map = new TreeMap<Comparable, List<T>>();
  for (T t : source) {
    final Comparable weight = getWeight(t, context);
    if (weight == null) {
      if (nulls == null) nulls = new SmartList<T>();
      nulls.add(t);
    } else {
      List<T> list = map.get(weight);
      if (list == null) {
        map.put(weight, list = new SmartList<T>());
      }
      list.add(t);
    }
  }

  final List<List<T>> values = new ArrayList<List<T>>();
  values.addAll(myNegated ? map.descendingMap().values() : map.values());
  ContainerUtil.addIfNotNull(values, nulls);

  return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
      return new FlatteningIterator<List<T>, T>(values.iterator()) {
        @Override
        protected Iterator<T> createValueIterator(List<T> group) {
          return myNext.classify(group, context).iterator();
        }
      };
    }
  };
}