Skip to content

Instantly share code, notes, and snippets.

@cwensel
Last active March 22, 2017 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwensel/a1a53ee40b14d1c541527c3d5d72deea to your computer and use it in GitHub Desktop.
Save cwensel/a1a53ee40b14d1c541527c3d5d72deea to your computer and use it in GitHub Desktop.
Tuple Streams
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