-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return a CursorList from ManyQuery which lazily instantiates models f…
…rom the cursor
- Loading branch information
1 parent
d246228
commit c028449
Showing
4 changed files
with
109 additions
and
37 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
39 changes: 39 additions & 0 deletions
39
library/src/se/emilsjolander/sprinkles/CursorIterator.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,39 @@ | ||
package se.emilsjolander.sprinkles; | ||
|
||
import android.database.Cursor; | ||
|
||
import java.util.Iterator; | ||
|
||
/** | ||
* Created by emilsjolander on 28/11/13. | ||
*/ | ||
public class CursorIterator<T extends Model> implements Iterator<T> { | ||
|
||
private Cursor cursor; | ||
private Class<T> type; | ||
private int pos = -1; | ||
|
||
CursorIterator(Cursor cursor, Class<T> type) { | ||
this.cursor = cursor; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
cursor.moveToPosition(pos); | ||
return !cursor.isLast(); | ||
} | ||
|
||
@Override | ||
public T next() { | ||
pos++; | ||
cursor.moveToPosition(pos); | ||
return Utils.getModelFromCursor(type, cursor); | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
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