Last active
March 22, 2017 06:12
-
-
Save cwensel/a1a53ee40b14d1c541527c3d5d72deea to your computer and use it in GitHub Desktop.
Tuple Streams
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
long count = TupleEntryStream.entryStream( tap, flowProcess ).count(); | |
assertEquals( 20, count ); | |
int sum = TupleEntryStream.entryStream( tap, flowProcess ) | |
.mapToInt( TupleEntryStream.fieldToInt( Fields.FIRST ) ) | |
.sum(); | |
assertEquals( 210, sum ); | |
List<Object> collect1 = TupleEntryStream.entryStream( tap, flowProcess ) | |
.map( TupleEntryStream.fieldToObject( Fields.FIRST ) ) | |
.collect( Collectors.toList() ); | |
assertEquals( 20, collect1.size() ); | |
List<Integer> collect2 = TupleEntryStream.entryStream( tap, flowProcess ) | |
.map( TupleEntryStream.fieldToObject( Fields.FIRST, Integer.class ) ) | |
.collect( Collectors.toList() ); | |
assertEquals( 20, collect2.size() ); | |
List<Integer> collect3 = TupleEntryStream.entryStream( tap, flowProcess ) | |
.map( TupleEntryStream.fieldToObject( Fields.FIRST, Coercions.INTEGER_OBJECT ) ) // CoercibleType<Integer> | |
.collect( Collectors.toList() ); | |
assertEquals( 20, collect3.size() ); | |
// same instance | |
Set<TupleEntry> collect4 = TupleEntryStream.entryStream( tap, flowProcess ) | |
.collect( Collectors.toSet() ); // error prone, instances are re-used | |
assertEquals( 1, new HashSet<>( collect4 ).size() ); // re-hash | |
// new instance | |
Set<TupleEntry> collect5 = TupleEntryStream.entryStreamCopy( tap, flowProcess ) | |
.collect( Collectors.toSet() ); // correct | |
assertEquals( 20, new HashSet<>( collect5 ).size() ); // re-hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment