Java 类org.apache.commons.collections4.iterators.PermutationIterator 实例源码

项目:language-tools-bg    文件:Anagram.java   
public Set<String> getAnagrams(String word) {
      //TODO n-grams
      Set<String> anagrams = new HashSet<String>();
      char[] chars = word.toLowerCase().toCharArray();
      List<Character> list = Arrays.asList(ArrayUtils.toObject(chars));
      PermutationIterator<Character> gen = new PermutationIterator<Character>(list);
StringBuilder sb = new StringBuilder();
      while (gen.hasNext()) {
          List<Character> anagramList = gen.next();

          for (Character ch : anagramList) {
              sb.append(ch);
          }
          String anagram = sb.toString();
          if (Checker.formsDictionary.containsKey(anagram)) {
              anagrams.add(anagram);
          }
    sb.setLength(0);
      }
      anagrams.remove(word.toLowerCase()); // don't return the input word
      return anagrams;
  }
项目:graphdb-benchmarks    文件:PermutingBenchmarkBase.java   
@Override
public void startBenchmarkInternal()
{
    LOG.info(String.format("Executing %s Benchmark . . . .", type.longname()));

    if (bench.permuteBenchmarks())
    {
        PermutationIterator<GraphDatabaseType> iter = new PermutationIterator<GraphDatabaseType>(
            bench.getSelectedDatabases());
        int cntPermutations = 1;
        while (iter.hasNext())
        {
            LOG.info("Scenario " + cntPermutations);
            startBenchmarkInternalOnePermutation(iter.next(), cntPermutations);
            cntPermutations++;
        }
    }
    else
    {
        startBenchmarkInternalOnePermutation(bench.getSelectedDatabases(), 1);
    }

    LOG.info(String.format("%s Benchmark finished", type.longname()));
    post();
}
项目:HCFCore    文件:CollectionUtils.java   
/**
 * Returns a {@link Collection} of all the permutations of the input collection.
 * <p>
 * NOTE: the number of permutations of a given collection is equal to n!, where
 * n is the size of the collection. Thus, the resulting collection will become
 * <b>very</b> large for collections &gt; 10 (e.g. 10! = 3628800, 15! = 1307674368000).
 * <p>
 * For larger collections it is advised to use a {@link PermutationIterator} to
 * iterate over all permutations.
 *
 * @see PermutationIterator
 *
 * @param <E>  the element type
 * @param collection  the collection to create permutations for, may not be null
 * @return an unordered collection of all permutations of the input collection
 * @throws NullPointerException if collection is null
 * @since 4.0
 */
public static <E> Collection<List<E>> permutations(final Collection<E> collection) {
    final PermutationIterator<E> it = new PermutationIterator<E>(collection);
    final Collection<List<E>> result = new LinkedList<List<E>>();
    while (it.hasNext()) {
        result.add(it.next());
    }
    return result;
}
项目:HCFCore    文件:CollectionUtils.java   
/**
 * Returns a {@link Collection} of all the permutations of the input collection.
 * <p>
 * NOTE: the number of permutations of a given collection is equal to n!, where
 * n is the size of the collection. Thus, the resulting collection will become
 * <b>very</b> large for collections &gt; 10 (e.g. 10! = 3628800, 15! = 1307674368000).
 * <p>
 * For larger collections it is advised to use a {@link PermutationIterator} to
 * iterate over all permutations.
 *
 * @see PermutationIterator
 *
 * @param <E>  the element type
 * @param collection  the collection to create permutations for, may not be null
 * @return an unordered collection of all permutations of the input collection
 * @throws NullPointerException if collection is null
 * @since 4.0
 */
public static <E> Collection<List<E>> permutations(final Collection<E> collection) {
    final PermutationIterator<E> it = new PermutationIterator<E>(collection);
    final Collection<List<E>> result = new LinkedList<List<E>>();
    while (it.hasNext()) {
        result.add(it.next());
    }
    return result;
}