@Override public void onBindViewHolder(V holder, int position) { if (cursor == null || !cursor.moveToPosition(position)) { throw new IllegalStateException("this should only be called when the cursor is valid"); } holder.item.readPropertiesFromCursor(cursor); onBindSquidViewHolder(holder, position); }
/** * Get a model instance representing the item at the specified position. The object returned by this method is a * singleton/shared instance. If you do this: * * <pre> * Model item0 = getItem(0); * Model item1 = getItem(1); * </pre> * * Then item0 and item1 will be the same object with the same values (those at position 1). We recommend you not * call getItem() outside of {@link #getView(int, android.view.View, android.view.ViewGroup) getView()} or on * different positions in the same method scope, and definitely don't call it from other threads. If you do need a * non-shared instance, you can clone the object returned by this method. * * @return the model object at the specified cursor position */ @Override public T getItem(int position) { if (this.cursor == null) { return null; } cursor.moveToPosition(position); model.readPropertiesFromCursor(cursor); return model; }
@Override public long getItemId(int position) { if (hasStableIds()) { if (cursor != null && cursor.moveToPosition(position)) { return cursor.get(columnForId); } } return 0; }
@Override public long getItemId(int position) { if (hasStableIds()) { if (cursor != null && cursor.moveToPosition(position)) { return cursor.get(idProperty); } return RecyclerView.NO_ID; } return super.getItemId(position); }
assertEquals(randomBlobs.size(), cursor.getCount()); for (int i = 0; i < randomBlobs.size(); i++) { cursor.moveToPosition(i); byte[] blob = cursor.get(Thing.BLOB); assertTrue(Arrays.equals(randomBlobs.get(i), blob));
private void assertExpectedValues(Query query, Property<?> property, Object... expectedValues) { final int expectedCount = expectedValues == null ? 0 : expectedValues.length; SquidCursor<?> cursor = database.query(null, query); try { assertEquals(expectedCount, cursor.getCount()); for (int i = 0; i < expectedCount; i++) { cursor.moveToPosition(i); assertEquals(expectedValues[i], cursor.get(property)); } } finally { cursor.close(); } }
private void testQueryResults(Criterion criterion, TestVirtualModel... expectedResults) { Query query = Query.select(TestVirtualModel.PROPERTIES).where(criterion); SquidCursor<TestVirtualModel> cursor = database.query(TestVirtualModel.class, query); try { int expectedCount = expectedResults == null ? 0 : expectedResults.length; assertEquals(expectedCount, cursor.getCount()); if (expectedCount == 0) { return; } for (int i = 0; i < expectedCount; i++) { cursor.moveToPosition(i); assertEquals(expectedResults[i], new TestVirtualModel(cursor)); } } finally { cursor.close(); } } }
public void testOrderByArray() { Long[] order = new Long[]{5L, 1L, 4L}; SquidCursor<Employee> cursor = database.query(Employee.class, Query.select(Employee.ID).limit(order.length).orderBy(Employee.ID.byArray(order))); try { assertEquals(order.length, cursor.getCount()); for (int i = 0; i < order.length; i++) { cursor.moveToPosition(i); assertEquals(order[i], cursor.get(Employee.ID)); } } finally { cursor.close(); } }
int index = 0; int start = offset > 0 ? offset : 0; for (cursor.moveToPosition(start); !cursor.isAfterLast(); cursor.moveToNext()) { if (index == expectedIds.length) { break;
evens.moveToPosition(i); assertEquals(i * 2, evens.get(Thing.BAR).intValue());