Available operators in PrivacyStreams

Type API & Description
Item,Number ArithmeticOperators.add(String numField1, String numField2)
Add the values of two fields in an item.
- numField1: the name of the first field
- numField2: the name of the second field
Item,Integer ArithmeticOperators.castToInt(String numField)
Cast a number to integer type.
- numField: the name of the number field
Item,Long ArithmeticOperators.castToLong(String numField)
Cast a number to long type.
- numField: the name of the number field
Item,Number ArithmeticOperators.divide(String numField1, String numField2)
Divide the values of two fields in an item.
- numField1: the name of the first field
- numField2: the name of the second field
Item,Number ArithmeticOperators.mode(String numField1, String numField2)
Mode the values of two fields in an item.
- numField1: the name of the first field
- numField2: the name of the second field
Item,Number ArithmeticOperators.multiply(String numField1, String numField2)
Multiply the values of two fields in an item.
- numField1: the name of the first field
- numField2: the name of the second field
Item,Double ArithmeticOperators.roundDown(String numField, Number value)
Round down a number. For example, given an item with field “x”=0.027, roundUp(“x”, 0.01) will produce 0.02.
- numField: the name of the number field
- value: the value to round
Item,Double ArithmeticOperators.roundUp(String numField, Number value)
Round up a number. For example, given an item with field “x”=17, roundUp("x", 10) will produce 20.
- numField: the name of the number field
- value: the value to round
Item,Number ArithmeticOperators.sub(String numField1, String numField2)
Subtract the values of two fields in an item.
- numField1: the name of the first field
- numField2: the name of the second field
Item,Double AudioOperators.calcLoudness(String audioDataField)
Calculate the average (RMS) loudness of the audio specified by an AudioData field. The loudness is an double number indicating the sound pressure level in dB.
- audioDataField: the name of the AudioData field.
Item,Double AudioOperators.convertAmplitudeToLoudness(String amplitudeField)
Calculate loudness (in decibels) based on an amplitude value. The amplitude should be a number from 0 to 32767.
- amplitudeField: the name of the amplitude field.
Item,List<Integer> AudioOperators.getAmplitudeSamples(String audioDataField)
Get the amplitude samples of the audio specified by an AudioData field. Each amplitude sample is an Integer from 0 to 32767. The amplitude sampling rate can be configured at Globals.AudioConfig.amplitudeSamplingRate;
- audioDataField: the name of the AudioData field.
Item,String AudioOperators.getFilepath(String audioDataField)
Get the file path of the audio specified by an AudioData field. The path might point to a temporary audio file if it is not from storage. To permanently save the file, you need to copy the file to another file path.
- audioDataField: the name of AudioData field
Item,Integer AudioOperators.getMaxAmplitude(String audioDataField)
Get the max amplitude of the audio specified by an AudioData field. The amplitude is an Integer from 0 to 32767.
- audioDataField: the name of the AudioData field.
Item,Boolean AudioOperators.hasHumanVoice(String audioDataField)
Detect human voice from the audio. Return true if there is human voice.
- audioDataField: the name of AudioData field
PStream,List<Item> Collectors.toItemList()
Collect the PStream to a list of Items.
Item,Boolean Comparators.eq(String field, TValue valueToCompare)
Check if the value of a field equals to a given value.
- field: the name of the field to compare
- valueToCompare: the value to compare with
- <TValue>: the type of value
Item,Boolean Comparators.gt(String field, Number valueToCompare)
Check if the value of a field is greater than a given value.
- field: the name of the field to compare
- valueToCompare: the value to compare with
Item,Boolean Comparators.gte(String field, Number valueToCompare)
Check if the value of a field is greater than or equal to a given value.
- field: the name of the field to compare
- valueToCompare: the value to compare with
Item,Boolean Comparators.lt(String field, Number valueToCompare)
Check if the value of a field is less than a given value.
- field: the name of the field to compare
- valueToCompare: the value to compare with
Item,Boolean Comparators.lte(String field, Number valueToCompare)
Check if the value of a field is less than or equal to a given value.
- field: the name of the field to compare
- valueToCompare: the value to compare with
Item,Boolean Comparators.ne(String field, TValue valueToCompare)
Check if the value of a field is not equal to a given value.
- field: the name of the field to compare
- valueToCompare: the value to compare with
- <TValue>: the type of value
T,Void DebugOperators.debug()
Print the input for debugging.
- <T>: the input type
T,T DebugOperators.logAs(String logTag)
Log the input and return as original.
- logTag: the log tag to use in logging
- <T>: the input/output type
T,T DebugOperators.logOverSocket(String logTag)
Log the input in socket and return as original.
- logTag: the log tag to use in logging
- <T>: the input/output type
Void,String DeviceOperators.getDeviceId()
Get device id.
Void,Boolean DeviceOperators.isWifiConnected()
Check if wifi is connected.
Item,Double GeolocationOperators.distanceBetween(String latLonField1, String latLonField2)
Get the distance between two locations (in meters).
- latLonField1: the first location
- latLonField2: the second location
Item,LatLon GeolocationOperators.distort(String latLonField, double radius)
Distort the coordinates value of a field and return the distorted coordinates. The distorted coordinates is an instance of LatLon class.
- latLonField: the coordinates field to distort
- radius: the distance to distort, in meters
Item,Boolean GeolocationOperators.inCircle(String latLonField, double centerLat, double centerLng, double radius)
Check if the coordinates specified by a LatLon field is a location in an given circular region.
- latLonField: the LatLon field to check
- centerLat: latitude of the center of the area
- centerLng: longitude of the center of the area
- radius: radius of the region, in meters
Item,Boolean GeolocationOperators.inSquare(String latLonField, double minLat, double minLng, double maxLat, double maxLng)
Check if the coordinates specified by a LatLon field is a location in an given square region.
- latLonField: the LatLon field to check
- minLat: the minimum latitude of the region
- minLng: the minimum longitude of the region
- maxLat: the maximum latitude of the region
- maxLng: the maximum longitude of the region
T,Void IOOperators.uploadToDropbox(Function<T,String> filePathGenerator, boolean append)
Upload an object to Dropbox, the output file path will be generated with a function. If file already exists and append is true, the object will be appended to the file; If append is false, the object will overwrite the existing file. This operator requires Dropbox configured (see https://privacystreams.github.io/pages/enable_accessibility.html). This provider requires android.permission.INTERNET permission.
- filePathGenerator: the function to generate the output file path each time
- <T>: the type of input object
T,Void IOOperators.uploadToDropbox(String filePath, boolean append)
Upload an object to Dropbox, the output file will be at filePath. If there is a file already at the filePath, the item will be appended to the file. This operator requires Dropbox configured (see https://privacystreams.github.io/pages/enable_accessibility.html). This provider requires android.permission.INTERNET permission.
- filePath: the output file path
- <T>: the type of input object
T,Void IOOperators.writeToFile(Function<T,String> filePathGenerator, boolean isPublic, boolean append)
Write an object to a local file, the output file path will be generated with a function. If isPublic is true, the file will be created in /sdcard/ folder, which can be accessed by other apps. If isPublic is false, the file will be created in the app data folder, which can not be accessed by other apps; If append is true, the object will be appended to the file; If append is false, the object will overwrite the file. This provider requires android.permission.WRITE_EXTERNAL_STORAGE permission.
- filePathGenerator: the function to generate the output file path each time
- isPublic: whether the file is public. If set to true, will requires WRITE_EXTERNAL_STORAGE permission.
- append: whether the object will be appended to the file
- <T>: the type of input object
T,Void IOOperators.writeToFile(String filePath, boolean isPublic, boolean append)
Write an object to a local file, the output file will be at filePath. If isPublic is true, the file will be created in /sdcard/ folder, which can be accessed by other apps. If isPublic is false, the file will be created in the app data folder, which can not be accessed by other apps; If append is true, the object will be appended to the file; If append is false, the object will overwrite the file. This provider requires android.permission.WRITE_EXTERNAL_STORAGE permission.
- filePath: the output file path
- isPublic: whether the file is public. If set to true, will require WRITE_EXTERNAL_STORAGE permission.
- append: whether the object will be appended to the file
- <T>: the type of input object
Item,ImageData ImageOperators.blur(String imageDataField)
Blur the image specified by an ImageData field, and return the blurred ImageData instance.
- imageDataField: the name of ImageData field
Item,Integer ImageOperators.countFaces(String imageDataField)
Count faces in an image. This operator outputs the number of faces in the image.
- imageDataField: the name of ImageData field
Item,String ImageOperators.extractText(String imageDataField)
Extract text in an image. This operator outputs the text in the images.
- imageDataField: the name of ImageData field
Item,Bitmap ImageOperators.getBitmap(String imageDataField)
Get the Bitmap of the image specified by an ImageData field.
- imageDataField: the name of ImageData field
Item,ExifInterface ImageOperators.getExif(String imageDataField)
Retrieve the EXIF of the image specified by an ImageData field. The EXIF information is an instance of Android ExifInterface class.
- imageDataField: the name of ImageData field
Item,String ImageOperators.getFilepath(String imageDataField)
Get the file path of the image specified by an ImageData field. The path might point to a temporary image file if it is not from storage. To permanently save the file, you need to copy the file to another file path.
- imageDataField: the name of ImageData field
Item,LatLon ImageOperators.getLatLon(String imageDataField)
Retrieve the location information of the image specified by an ImageData field. The location information is an instance of LatLon class.
- imageDataField: the name of ImageData field
Item,Boolean ImageOperators.hasCharacter(String imageDataField)
Detect characters in an image. This operator outputs true if there is at least one character in the image.
- imageDataField: the name of ImageData field
Item,Boolean ImageOperators.hasFace(String imageDataField)
Detect faces in an image. This operator outputs true if there is at least one face in the image.
- imageDataField: the name of ImageData field
Item,Boolean ItemOperators.containsField(String fieldToCheck)
Check whether the item contains a given field.
- fieldToCheck: the name of field to check
Item,Item ItemOperators.excludeFields(String fieldsToExclude)
Project an item by excluding some fields. The excluded fields will be removed from the item.
- fieldsToExclude: the names of the fields to exclude.
Item,TValue ItemOperators.getField(String field)
Get the value of a given field in the item.
- field: the name of the field to get.
- <TValue>: the type of field value
Item,Item ItemOperators.getSubItem(String subItemField)
Get the sub item value of a given field.
- subItemField: the name of sub item field.
Item,Item ItemOperators.includeFields(String fieldsToInclude)
Project an item by including some fields. The fields that are not included will be removed from the item.
- fieldsToInclude: the names of the fields to include.
Item,Boolean ItemOperators.isFieldIn(String field, TValue listToCompare)
Check whether the value of a field is in a given list.
- field: the field name
- listToCompare: the list to check whether the field is in
- <TValue>: the type of list elements
Item,Item ItemOperators.setField(String fieldToSet, Function<Item,TValue> fieldValueComputer)
Set the value of a new field with a function.
- fieldToSet: the name of the field to set, it can be a new name.
- fieldValueComputer: the function to compute the value of the field based on the item.
- <TValue>: the type of the new field value.
Item,Item ItemOperators.setField(String fieldToSet, TValue fieldValue)
Set the value of a new field to a given value.
- fieldToSet: the name of the field to set, it can be a new name.
- fieldValue: the value of the field.
- <TValue>: the type of the new field value.
Item,Item ItemOperators.setGroupField(String fieldToSet, Function<List<Item>,TValue> fieldValueComputer)
Set a field to a new value for each item in the stream. This transformation can only be used after invoking group methods (groupBy, localGroupBy, etc.). The value is computed with a function that takes the grouped items as input. Eg. setGroupField("count", StatisticOperators.count()) will set a new field “count” to each item, which represents the number of items in the grouped sub stream.
- fieldToSet: the new field name
- fieldValueComputer: the function to compute the new field value, which takes the list of grouped items as input.
- <TValue>: the type of the new field value
Item,Item ItemOperators.setIndependentField(String fieldToSet, Function<Void,TValue> valueGenerator)
Set the value of a new field with a value generator function. The value generator function is independent from current item, which does not need a input (Void). The value generator will be evaluated on demand at runtime. For example, setIndependentField("time", TimeOperators.getCurrentTime()) will set the field “time” to a timestamp in each item; setIndependentField("wifiStatus", DeviceOperators.isWifiConnected()) will set the field “wifiStatus” to a boolean indicating whether wifi is connected in each item.
- fieldToSet: the name of the field to set, it can be a new name or an existing name.
- valueGenerator: the function to compute the field value.
- <TValue>: the type of the new field value.
Item,Tout ItemOperators.wrapSubStreamFunction(Function<List<Item>,Tout> subStreamFunction)
Output the grouped items in the item with a function. This function must be applied to a group item, i.e. must be used after groupBy or localGroupBy.
- subStreamFunction: the function to output sub stream.
- <Tout>: the type of sub stream collection result.
Item,Tout ItemOperators.wrapValueGenerator(Function<Void,Tout> valueGenerator)
Wrap a valueGenerator that takes Void as input type to a function that takes Item as input type.
- valueGenerator: the function that takes Void as input.
- <Tout>: the type of value generator result.
List<Item>,List<Item> ItemsOperators.asFieldList()
Collect the items in the stream to a list. Each element in the list is an instance of Item.
List<Item>,List<TValue> ItemsOperators.asFieldList(String fieldToCollect)
Collect the values of a field in the stream to a list. Each element in the list is the value of the specified field in an item.
- fieldToCollect: the name of the field to collect.
List<Item>,Item ItemsOperators.getItemWithLeast(String listField)
Select an item from the items that has the least elements in a list field.
- listField: the name of the list field
List<Item>,Item ItemsOperators.getItemWithMax(String numField)
Select an item from the items that has the max value of a field.
- numField: the name of the number field
List<Item>,Item ItemsOperators.getItemWithMin(String numField)
Select an item from the items that has the min value of a field.
- numField: the name of the number field
List<Item>,Item ItemsOperators.getItemWithMost(String listField)
Select an item from the items that has the most elements in a list field.
- listField: the name of the list field
Item,Boolean ListOperators.contains(String listField, Object value)
Check whether the list specified by a field contains a given value.
- listField: the name of the list field
- value: the value to check if is in the list
Item,Integer ListOperators.count(String listField)
Count the number of elements in the list specified by a field.
- listField: the name of the field to count
Item,Boolean ListOperators.intersects(String listField, TValue listToCompare)
Check whether the list specified by a field intersects with a given list.
- listField: the name of the list field
- listToCompare: the list to compare
Item,Number ListOperators.max(String numListField)
Get the max value of a field in the stream. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Double ListOperators.mean(String numListField)
Calculate the average of the numbers specified by a field. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Number ListOperators.median(String numListField)
Get the median value of a field in the stream. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Number ListOperators.min(String numListField)
Get the min value of a field in the stream. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Number ListOperators.mode(String numListField)
Get the mode value of a field in the stream. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Double ListOperators.range(String numListField)
Calculate the range of the numbers specified by a field. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Double ListOperators.rms(String numListField)
Calculate the RMS (root mean square) of the numbers specified by a field. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Double ListOperators.sum(String numListField)
Calculate the sum of the numbers specified by a field. The list elements must be in Number type, such as Integer, Double, Long, … If there is no valid field value in the stream, the “sum” result will be 0.0
- numListField: the name of the field, the field value must be a list of numbers.
Item,Double ListOperators.variance(String numListField)
Calculate the variance of the numbers specified by a field. The list elements must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no number in the list), the result will be null.
- numListField: the name of the field, the field value must be a list of numbers.
Item,Boolean LogicOperators.and(Function<Item,Boolean> predicate1, Function<Item,Boolean> predicate2)
Compute the logical AND of two functions.
- predicate1: the first function to test an item
- predicate2: the second function to test an item
Item,Boolean LogicOperators.not(Function<Item,Boolean> predicate)
Compute the logical NOT of a function.
- predicate: the function to test an item
Item,Boolean LogicOperators.or(Function<Item,Boolean> predicate1, Function<Item,Boolean> predicate2)
Compute the logical OR of two functions.
- predicate1: the first function to test an item
- predicate2: the second function to test an item
List<Item>,Integer StatisticOperators.count()
Count the number of items in the stream and output the number.
List<Item>,Integer StatisticOperators.count(String field)
Count the number of valid fields in the stream and output the number.
- field: the name of the field to count
List<Item>,Number StatisticOperators.max(String numField)
Get the max value of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Double StatisticOperators.mean(String numField)
Calculate the average of the number values of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Number StatisticOperators.median(String numField)
Get the median value of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Number StatisticOperators.min(String numField)
Get the min value of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Number StatisticOperators.mode(String numField)
Get the mode value of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Double StatisticOperators.range(String numField)
Calculate the range of the number values of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Double StatisticOperators.rms(String numField)
Calculate the RMS (root mean square) of the number values of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
List<Item>,Double StatisticOperators.sum(String numField)
Calculate the sum of the number values of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If there is no valid field value in the stream, the “sum” result will be 0.0
- numField: the name of the field, the field value must be a number.
List<Item>,Double StatisticOperators.variance(String numField)
Calculate the variance of the number values of a field in the stream. The field values must be in Number type, such as Integer, Double, Long, … If calculation fails (e.g. there is no item in the stream), the result will be null.
- numField: the name of the field, the field value must be a number.
Item,Boolean StringOperators.contains(String stringField, String searchString)
Check whether the string value of a field contains a certain substring.
- stringField: the name of the string field
- searchString: the substring to search
Item,String StringOperators.elide(String stringField, int start, int end)
Elide a substring in the string value of a field.
- stringField: the name of the string field to calculate length
- start: the position to start from, negative means count back from the end of the String by this many characters
- end: the position to end at (exclusive), negative means count back from the end of the String by this many characters
Item,Integer StringOperators.indexOf(String stringField, String searchString)
Get the index of a substring in the string value of a field.
- stringField: the name of the string field
- searchString: the substring to search
Item,Integer StringOperators.length(String stringField)
Get the length of the string value of a field.
- stringField: the name of the string field to calculate length
Item,String StringOperators.md5(String stringField)
Get the MD5-hashed value of the string value of a field.
- stringField: the name of the string field to perform hash.
Item,String StringOperators.replace(String stringField, String searchString, String replaceString)
Replace a substring to a new string in the string value of a field.
- stringField: the name of the string field
- searchString: the substring to search
- replaceString: the string used to replace the searchString
Item,String StringOperators.sha1(String stringField)
Get the SHA1-hashed value of the string value of a field.
- stringField: the name of the string field to perform hash.
Item,String StringOperators.sha256(String stringField)
Get the SHA256-hashed value of the string value of a field.
- stringField: the name of the string field to perform hash.
Item,String StringOperators.subString(String stringField, int start, int end)
Get a substring of the string value of a field.
- stringField: the name of the string field to calculate length
- start: the position to start from, negative means count back from the end of the String by this many characters
- end: the position to end at (exclusive), negative means count back from the end of the String by this many characters
Item,String TimeOperators.formatTime(String timestampField, String timeFormat)
Convert the timestamp value of a field to a string based a given format.
- timestampField: the name of timestamp field
- timeFormat: the format of time string
Void,Long TimeOperators.getCurrentTime()
Get current timestamp.
Item,Boolean TimeOperators.recent(String timestampField, Long duration)
Check whether the timestamp field value of a field is recent from now (less than a given duration).
- timestampField: the name of the timestamp field
- duration: the millisecond duration from now
Item,Boolean TimeOperators.since(String timestampField, Long timestampToCompare)
Check whether the timestamp value of a field is after a given timestamp.
- timestampField: the name of the timestamp field
- timestampToCompare: the timestamp to compare