-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented lightweight primitive iterators/streams type adapters
- Loading branch information
1 parent
e1e3a7c
commit 80e8460
Showing
10 changed files
with
95 additions
and
195 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package lsh.ext.gson; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
|
||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public final class StreamedTypeAdapter<S, I> | ||
extends TypeAdapter<S> { | ||
|
||
private final Function<? super JsonReader, ? extends S> toStream; | ||
private final Function<? super S, ? extends I> toIterator; | ||
private final Predicate<? super I> hasNext; | ||
private final BiConsumer<? super JsonWriter, ? super I> writeNext; | ||
|
||
public static <S, I> TypeAdapter<S> getInstance( | ||
final Function<? super JsonReader, ? extends S> toStream, | ||
final Function<? super S, ? extends I> toIterator, | ||
final Predicate<? super I> hasNext, | ||
final BiConsumer<? super JsonWriter, ? super I> writeNext | ||
) { | ||
return new StreamedTypeAdapter<>(toStream, toIterator, hasNext, writeNext); | ||
} | ||
|
||
@Override | ||
public void write(final JsonWriter out, final S cursor) { | ||
final I iterator = toIterator.apply(cursor); | ||
while ( hasNext.test(iterator) ) { | ||
writeNext.accept(out, iterator); | ||
} | ||
} | ||
|
||
@Override | ||
public S read(final JsonReader in) { | ||
return toStream.apply(in); | ||
} | ||
|
||
} |
50 changes: 0 additions & 50 deletions
50
src/main/java/lsh/ext/gson/ext/java/util/stream/DoubleStreamTypeAdapter.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/main/java/lsh/ext/gson/ext/java/util/stream/IntStreamTypeAdapter.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/main/java/lsh/ext/gson/ext/java/util/stream/LongStreamTypeAdapter.java
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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