use iterator interface exclusively in ParcelableFileCache
This commit is contained in:
@@ -48,17 +48,18 @@ public class ParcelableFileCache<E extends Parcelable> {
|
||||
private Context mContext;
|
||||
|
||||
private final String mFilename;
|
||||
private int mNumEntries;
|
||||
|
||||
public ParcelableFileCache(Context context, String filename) {
|
||||
mContext = context;
|
||||
mFilename = filename;
|
||||
}
|
||||
|
||||
public void writeCache(ArrayList<E> selectedEntries) throws IOException {
|
||||
writeCache(selectedEntries.iterator());
|
||||
public int getNumEntries() {
|
||||
return mNumEntries;
|
||||
}
|
||||
|
||||
public void writeCache(Iterator<E> it) throws IOException {
|
||||
public void writeCache(int numEntries, Iterator<E> it) throws IOException {
|
||||
|
||||
File cacheDir = mContext.getCacheDir();
|
||||
if (cacheDir == null) {
|
||||
@@ -70,6 +71,8 @@ public class ParcelableFileCache<E extends Parcelable> {
|
||||
|
||||
DataOutputStream oos = new DataOutputStream(new FileOutputStream(tempFile));
|
||||
|
||||
oos.writeInt(numEntries);
|
||||
|
||||
while (it.hasNext()) {
|
||||
Parcel p = Parcel.obtain(); // creating empty parcel object
|
||||
p.writeParcelable(it.next(), 0); // saving bundle as parcel
|
||||
@@ -83,15 +86,6 @@ public class ParcelableFileCache<E extends Parcelable> {
|
||||
|
||||
}
|
||||
|
||||
public List<E> readCacheIntoList() throws IOException {
|
||||
ArrayList<E> result = new ArrayList<E>();
|
||||
Iterator<E> it = readCache();
|
||||
while (it.hasNext()) {
|
||||
result.add(it.next());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Iterator<E> readCache() throws IOException {
|
||||
return readCache(true);
|
||||
}
|
||||
@@ -113,6 +107,9 @@ public class ParcelableFileCache<E extends Parcelable> {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
// yes this is slightly sloppy data flow. WE WOULDN'T NEED THIS WITH TUPLE RETURN TYPES
|
||||
mNumEntries = ois.readInt();
|
||||
|
||||
return new Iterator<E>() {
|
||||
|
||||
E mRing = null;
|
||||
|
||||
Reference in New Issue
Block a user