Interface Transformer
- All Known Subinterfaces:
Filter,IdentityTransformer
- All Known Implementing Classes:
AndFilter,CoerceStringsTransformer,ComparatorFilter,ContainsFilter,DateEpochTransformer,DateISOStringTransformer,EpochDateTransformer,EqualsFilter,GreaterThanFilter,GreaterThanOrEqualFilter,InsertKeyTransformer,ISOStringDateTransformer,LessThanFilter,LessThanOrEqualFilter,LikeFilter,NotFilter,OrFilter,SortedGroupByTransformer,UnsortedGroupByTransformer
public interface Transformer
An interface for applying lazy transformations to JSON objects during iteration.
This enables efficient streaming transformations of data without loading entire
collections into memory.
Transformations can include data cleaning, filtering, enrichment, or any other modifications to JSON objects. The transformations are applied on-the-fly as elements are accessed through the iterator.
Example usage:
// Create a transformer that adds a timestamp to each record
Transformer timestampTransformer = new Transformer() {
public Iterator<JSONObject> transform(Iterator<JSONObject> iterator) {
return new Iterator<JSONObject>() {
public JSONObject next() {
JSONObject obj = iterator.next();
obj.put("timestamp", System.currentTimeMillis());
return obj;
}
// ... implement other Iterator methods
};
}
};
- Author:
- jbanes
-
Method Summary
Modifier and TypeMethodDescriptiondefault Iterable<JSONObject> transform(Iterable<JSONObject> iterable) Provides a lazy transformation mechanism for anIterableof JSON objects.transform(Iterator<JSONObject> iterator) Creates an iterator that transforms JSON objects as they are accessed.
-
Method Details
-
transform
Provides a lazy transformation mechanism for anIterableof JSON objects. The transformation is applied to each element only when it is accessed through the iterator.This default implementation wraps the iterator-based transformation, preserving the lazy evaluation semantics.
- Parameters:
iterable- The source collection of JSON objects to transform.- Returns:
- An
Iterablethat will apply transformations to elements when iterated. - Throws:
ConvirganceException- If an error occurs during transformation.
-
transform
Creates an iterator that transforms JSON objects as they are accessed. Implementations should maintain lazy evaluation by only transforming elements when they are requested through the iterator.The returned iterator should follow standard Iterator contract:
- Only transform elements when next() is called
- Throw NoSuchElementException if next() is called when hasNext() is false
- Maintain consistent state between hasNext() and next() calls
- Parameters:
iterator- The source iterator providing JSON objects to transform.- Returns:
- An iterator that applies transformations to elements as they are accessed.
-