public class PStream extends Stream
Constructor and Description |
---|
PStream(UQI uqi,
Function<java.lang.Void,PStream> streamProvider) |
Modifier and Type | Method and Description |
---|---|
java.util.List<Item> |
asList()
Collect the items in the stream to a list.
|
<TValue> java.util.List<TValue> |
asList(java.lang.String fieldToSelect)
Select a field in each item and output the field values to a list.
|
int |
count()
Count the number of items.
|
void |
debug()
Print the items for debugging.
|
PStream |
filter(Function<Item,java.lang.Boolean> itemChecker)
Filter the stream by testing an item with a function.
|
<TValue> PStream |
filter(java.lang.String fieldName,
TValue fieldValue)
Filter the stream by checking whether a field equals a value.
|
void |
forEach(Function<Item,java.lang.Void> callback)
Callback with each item.
|
<TValue> void |
forEach(java.lang.String fieldToSelect,
Function<TValue,java.lang.Void> callback)
Callback with a certain field of each item.
|
<TValue> TValue |
getFieldAt(java.lang.String fieldName,
int index)
Get the N-th value of a given field.
|
Item |
getFirst()
Get the first item in the stream.
|
<TValue> TValue |
getFirst(java.lang.String fieldName)
Get the first value of the given field in the stream.
|
Item |
getItemAt(int index)
Pick the N-th item in the stream.
|
Function<java.lang.Void,PStream> |
getStreamProvider() |
<Tout> Function<java.lang.Void,Tout> |
getValueGenerator(Function<PStream,Tout> streamOutputter)
Get a value generator that can be evaluated on demand.
|
PStream |
groupBy(java.lang.String groupField)
Group the items according to a field.
|
void |
idle()
Do nothing with the items.
|
void |
ifPresent(Function<Item,java.lang.Void> callback)
Callback with an item once one item is present.
|
<TValue> void |
ifPresent(java.lang.String fieldToSelect,
Function<TValue,java.lang.Void> callback)
Callback with a field value of an item once the field value is present.
|
PStream |
inFixedInterval(long fixedInterval)
Make the items be sent in a fixed interval.
|
PStream |
keepChanges()
Only keep the items that are different from the previous ones in the stream.
|
PStream |
keepChanges(java.lang.String fieldName)
Only Keep the items whose fields are different from the previous ones in the stream.
|
PStream |
limit(Function<Item,java.lang.Boolean> itemChecker)
Limit the stream by checking each item with a function.
|
PStream |
limit(int maxCount)
Limit the stream with a max number of items.
|
PStream |
localGroupBy(java.lang.String groupField)
Group the **contiguous** items according to a field.
|
PStream |
logAs(java.lang.String logTag)
Print the items in current stream.
|
PStream |
logOverSocket(java.lang.String logTag)
Print the items in current stream over socket.
|
PStream |
map(Function<Item,Item> itemConverter)
Convert each item in the stream with a function.
|
void |
onChange(Function<Item,java.lang.Void> callback)
Callback with an item when the item changes (is different from the previous item).
|
<TValue> void |
onChange(java.lang.String fieldToSelect,
Function<TValue,java.lang.Void> callback)
Callback with a field value of an item when the field value changes.
|
<Tout> Tout |
output(Function<java.util.List<Item>,Tout> itemsCollector)
Output the items in the stream with a function.
|
<Tout> void |
output(Function<java.util.List<Item>,Tout> resultComputer,
Callback<Tout> resultHandler)
Output the items in the stream with a function, and pass the result to a callback.
|
void |
output(PStreamAction pStreamAction)
Output the current PStream.
|
PStream |
project(java.lang.String... fieldsToInclude)
Project each item by including some fields.
|
PStream |
reuse(int numOfReuses)
Reuse current stream.
|
PStream |
reverse()
Reverse the order of items
`reverse()` will reverse the order of the items in the stream.
|
PStream |
sampleByCount(int stepCount)
Sample the items based on a given step count.
|
PStream |
sampleByInterval(long minInterval)
Sample the items based on a given interval.
|
<TValue> PStream |
setField(java.lang.String fieldToSet,
Function<Item,TValue> fieldValueComputer)
Set a field to a new value for each item in the stream.
|
<TValue> PStream |
setGroupField(java.lang.String fieldToSet,
Function<java.util.List<Item>,TValue> fieldValueComputer)
Set a field to a new value for each item in the stream.
|
<TValue> PStream |
setIndependentField(java.lang.String fieldToSet,
Function<java.lang.Void,TValue> valueGenerator)
Set the value of a new field with a value generator function.
|
PStream |
shuffle()
Shuffle the items.
|
PStream |
sortBy(java.lang.String fieldName)
Sort the items according to the value of a field, in ascending order.
|
PStream |
timeout(long timeoutMilliseconds)
Limit the stream with a timeout, stop the stream after time out.
|
PStream |
transform(PStreamTransformation pStreamTransformation)
Transform the current PStream to another PStream.
|
PStream |
unGroup(java.lang.String unGroupField,
java.lang.String newField)
Un-group a list field in each item to multiple items.
|
public Function<java.lang.Void,PStream> getStreamProvider()
getStreamProvider
in class Stream
public PStream transform(PStreamTransformation pStreamTransformation)
pStreamTransformation
- the function used to transform the streampublic void output(PStreamAction pStreamAction)
pStreamAction
- the function used to output stream@PSTransformation public PStream filter(Function<Item,java.lang.Boolean> itemChecker)
itemChecker
- the function to check each item.@PSTransformation public <TValue> PStream filter(java.lang.String fieldName, TValue fieldValue)
fieldName
- the name of field to checkfieldValue
- the value to compare with the field@PSTransformation public PStream keepChanges()
@PSTransformation public PStream keepChanges(java.lang.String fieldName)
fieldName
- the name of field to check whether an item should be kept@PSTransformation public PStream sampleByInterval(long minInterval)
minInterval
- the minimum interval (in milliseconds) between each two items.@PSTransformation public PStream sampleByCount(int stepCount)
stepCount
- the num of items to drop since last item@PSTransformation public PStream limit(Function<Item,java.lang.Boolean> itemChecker)
itemChecker
- the function to check each item.@PSTransformation public PStream limit(int maxCount)
maxCount
- the max number of items@PSTransformation public PStream timeout(long timeoutMilliseconds)
timeoutMilliseconds
- the timeout milliseconds@PSTransformation public PStream map(Function<Item,Item> itemConverter)
itemConverter
- the function to map each item to another item@PSTransformation public PStream inFixedInterval(long fixedInterval)
fixedInterval
- the fixed interval in milliseconds.@PSTransformation public PStream project(java.lang.String... fieldsToInclude)
fieldsToInclude
- the fields to include@PSTransformation public <TValue> PStream setField(java.lang.String fieldToSet, Function<Item,TValue> fieldValueComputer)
TValue
- the type of the new field valuefieldToSet
- the name of the field to set.fieldValueComputer
- the function to compute the value of the new field based on each item.@PSTransformation public <TValue> PStream setGroupField(java.lang.String fieldToSet, Function<java.util.List<Item>,TValue> fieldValueComputer)
TValue
- the type of the new field valuefieldToSet
- the name of the field to set.fieldValueComputer
- the function to compute the new field value, which takes the list of grouped items as input.@PSTransformation public <TValue> PStream setIndependentField(java.lang.String fieldToSet, Function<java.lang.Void,TValue> valueGenerator)
TValue
- the type of the new field value.fieldToSet
- the name of the field to set.valueGenerator
- the function to compute the field value.@PSTransformation(changeOrder=true) public PStream sortBy(java.lang.String fieldName)
fieldName
- the field used to sort the items in current stream, in ascending order@PSTransformation(changeOrder=true) public PStream shuffle()
@PSTransformation(changeOrder=true) public PStream reverse()
@PSTransformation(changeOrder=true) public PStream groupBy(java.lang.String groupField)
groupField
- the field used to group the items in current stream.@PSTransformation public PStream localGroupBy(java.lang.String groupField)
groupField
- the field used to group the items in current stream.@PSTransformation public PStream unGroup(java.lang.String unGroupField, java.lang.String newField)
unGroupField
- the field to un-group, whose value should be a listnewField
- the new field name in the new stream@PSAction(blocking=false) public <Tout> void output(Function<java.util.List<Item>,Tout> resultComputer, Callback<Tout> resultHandler)
Tout
- the type of the resultresultComputer
- the function used to compute result based on the items in current streamresultHandler
- the function to handle the result@PSAction(blocking=true) public <Tout> Tout output(Function<java.util.List<Item>,Tout> itemsCollector) throws PSException
Tout
- the type of the resultitemsCollector
- the function used to output current streamPSException
- if failed to the result.@PSAction(blocking=true) public Item getFirst() throws PSException
PSException
@PSAction(blocking=true) public <TValue> TValue getFirst(java.lang.String fieldName) throws PSException
PSException
@PSAction(blocking=true) public Item getItemAt(int index) throws PSException
index
- the index of target item.PSException
@PSAction(blocking=true) public <TValue> TValue getFieldAt(java.lang.String fieldName, int index) throws PSException
fieldName
- the name of the field to selectindex
- the index of target item.PSException
@PSTransformation public PStream logAs(java.lang.String logTag)
logTag
- the log tag to use in printing current stream@PSTransformation public PStream logOverSocket(java.lang.String logTag)
logTag
- the log tag to use in printing current stream@PSAction(blocking=true) public int count() throws PSException
PSException
@PSAction(blocking=true) public java.util.List<Item> asList() throws PSException
PSException
@PSAction(blocking=true) public <TValue> java.util.List<TValue> asList(java.lang.String fieldToSelect) throws PSException
TValue
- the type of field valuefieldToSelect
- the field to selectPSException
@PSAction(blocking=false) public void forEach(Function<Item,java.lang.Void> callback)
callback
- the callback to invoke for each item.@PSAction(blocking=false) public <TValue> void forEach(java.lang.String fieldToSelect, Function<TValue,java.lang.Void> callback)
TValue
- the type of the fieldfieldToSelect
- the name of the field to callback withcallback
- the callback to invoke for each item field@PSAction(blocking=false) public void onChange(Function<Item,java.lang.Void> callback)
callback
- the callback to invoke for the changed item@PSAction(blocking=false) public <TValue> void onChange(java.lang.String fieldToSelect, Function<TValue,java.lang.Void> callback)
TValue
- the type of the fieldfieldToSelect
- the name of the field to callback withcallback
- the callback to invoke for the changed item field@PSAction(blocking=false) public void ifPresent(Function<Item,java.lang.Void> callback)
callback
- the callback to invoke once the item is present@PSAction(blocking=false) public <TValue> void ifPresent(java.lang.String fieldToSelect, Function<TValue,java.lang.Void> callback)
TValue
- the type of the fieldfieldToSelect
- the name of the field to callback withcallback
- the callback to invoke once the field value is present@PSTransformation public PStream reuse(int numOfReuses)
public <Tout> Function<java.lang.Void,Tout> getValueGenerator(Function<PStream,Tout> streamOutputter)
streamOutputter
- the function to output the stream