-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ListAdapter a generic collection adapter
- Loading branch information
1 parent
e3de6b5
commit f0ba493
Showing
7 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/marcospassos/phpserializer/adapter/CollectionAdapter.java
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,33 @@ | ||
package com.marcospassos.phpserializer.adapter; | ||
|
||
import com.marcospassos.phpserializer.Context; | ||
import com.marcospassos.phpserializer.TypeAdapter; | ||
import com.marcospassos.phpserializer.Writer; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Adapter for handling collections. | ||
* | ||
* @param <T> The type of values in the collection. | ||
* | ||
* @author Marcos Passos | ||
* @since 1.0 | ||
*/ | ||
public class CollectionAdapter<T> implements TypeAdapter<Collection<T>> | ||
{ | ||
@Override | ||
public void write(Collection<T> collection, Writer writer, Context context) | ||
{ | ||
int size = collection.size(); | ||
|
||
writer.writeArrayStart(size); | ||
|
||
int index = 0; | ||
for (Object value: collection) { | ||
writer.writeKey(index++); | ||
context.write(value, writer); | ||
} | ||
|
||
writer.writeArrayEnd(); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/com/marcospassos/phpserializer/adapter/ListAdapter.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