Created
November 9, 2019 11:59
-
-
Save masayuki038/1501e681ac9c21b1a6019bbe9ca9a7e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class AvroEnumerator implements Enumerator<Object> { | |
| private List<GenericData.Record> records; | |
| private Integer[] fields; | |
| private int pos; | |
| public AvroEnumerator(List<GenericData.Record> records, Integer[] fields) { | |
| this.records = records; | |
| this.fields = fields; | |
| this.pos = -1; | |
| } | |
| @Override | |
| public Object current() { | |
| GenericData.Record record = records.get(this.pos); | |
| return Arrays.stream(this.fields) | |
| .map(record::get).collect(Collectors.toList()).toArray(); | |
| } | |
| @Override | |
| public boolean moveNext() { | |
| return (this.records.size() > (++this.pos)); | |
| } | |
| @Override | |
| public void reset() { | |
| this.pos = -1; | |
| } | |
| @Override | |
| public void close() {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment