fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.concurrent.*;
  5. import java.util.function.*;
  6. import java.util.stream.*;
  7. import java.lang.*;
  8. import java.io.*;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. System.out.println("shuffle permutations: " + permutations(Collections::shuffle));
  16. System.out.println("sort permutations: " + permutations(list -> list.sort(randomOrder())));
  17. }
  18.  
  19. private static long permutations(Consumer<List<String>> shuffle) {
  20. return Stream.generate(() -> Arrays.asList("a", "b", "c"))
  21. .peek(shuffle)
  22. .limit(1000)
  23. .distinct()
  24. .count();
  25. }
  26.  
  27. public static Comparator<String> randomOrder() {
  28. ThreadLocalRandom r = ThreadLocalRandom.current();
  29. int x = r.nextInt(), y = r.nextInt();
  30. boolean b = r.nextBoolean();
  31. return Comparator.comparingInt((String s)->s.hashCode()^x)
  32. .thenComparingInt(s->s.length()^y)
  33. .thenComparing(b? Comparator.naturalOrder(): Comparator.reverseOrder());
  34. }
  35. }
Success #stdin #stdout 0.19s 42172KB
stdin
Standard input is empty
stdout
shuffle permutations: 6
sort permutations: 4