Created
September 11, 2014 00:11
-
-
Save yohhoy/247b74a75b576eea2e5a to your computer and use it in GitHub Desktop.
Java8 StreamAPI Spliterator characteristics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.stream.*; | |
public class SpliteratorDump { | |
static String c2s(String hdr, int c) { | |
StringBuilder sb = new StringBuilder(hdr + ":"); | |
if ((c & Spliterator.CONCURRENT) != 0) sb.append(" CONCURRENT"); | |
if ((c & Spliterator.DISTINCT) != 0) sb.append(" DISTINCT"); | |
if ((c & Spliterator.IMMUTABLE) != 0) sb.append(" IMMUTABLE"); | |
if ((c & Spliterator.NONNULL) != 0) sb.append(" NONNULL"); | |
if ((c & Spliterator.ORDERED) != 0) sb.append(" ORDERED"); | |
if ((c & Spliterator.SIZED) != 0) sb.append(" SIZED"); | |
if ((c & Spliterator.SORTED) != 0) sb.append(" SORTED"); | |
if ((c & Spliterator.SUBSIZED) != 0) sb.append(" SUBSIZED"); | |
return sb.toString(); | |
} | |
static <T> void dump(String hdr, Spliterator<T> s) { | |
System.out.println(c2s(hdr, s.characteristics())); | |
} | |
static public void main(String[] args) { | |
dump("IntStream.range", IntStream.range(0,10).spliterator()); | |
dump("IntStream.range.boxed", IntStream.range(0,10).boxed().spliterator()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment