SQLiteIndex extends AbstractAttributeIndex<A, O> implements SortedKeyStatisticsAttributeIndex<A, O>, NonHeapTypeIndex { static <O, K, A> Iterable<Row< K, A>> rowIterable(final Iterable<O> objects, final SimpleAttribute<O, K> primaryKeyAttribute, final Attribute<O, A> indexAttribute, final QueryOptions queryOptions){ return new Iterable<Row<K, A>>() { @Override public Iterator<Row<K, A>> iterator() { return new LazyIterator<Row<K, A>>() { final Iterator<O> objectIterator = objects.iterator(); Iterator<A> valuesIterator = null; K currentObjectKey; Row<K, A> next; @Override protected Row<K, A> computeNext() { while(computeNextOrNull()){ if (next!=null) return next; } return endOfData(); } boolean computeNextOrNull(){ if (valuesIterator == null || !valuesIterator.hasNext()){ if (objectIterator.hasNext()){ O next = objectIterator.next(); currentObjectKey = primaryKeyAttribute.getValue(next, queryOptions); valuesIterator = indexAttribute.getValues(next, queryOptions).iterator(); }else{ return false; } } if (valuesIterator.hasNext()){ next = new Row<K, A>(currentObjectKey, valuesIterator.next()); return true; }else{ next = null; return true; } } }; } }; } SQLiteIndex(final Attribute<O, A> attribute,
                       final SimpleAttribute<O, K> primaryKeyAttribute,
                       final SimpleAttribute<K, O> foreignKeyAttribute,
                       final String tableNameSuffix); @Override boolean supportsQuery(Query<O> query, QueryOptions queryOptions); @Override boolean isMutable(); @Override boolean isQuantized(); @Override Index<O> getEffectiveIndex(); @Override ResultSet<O> retrieve(final Query<O> query, final QueryOptions queryOptions); @Override boolean addAll(final ObjectSet<O> objectSet, final QueryOptions queryOptions); @Override boolean removeAll(final ObjectSet<O> objectSet, final QueryOptions queryOptions); @Override void clear(QueryOptions queryOptions); @Override void init(ObjectStore<O> objectStore, QueryOptions queryOptions); @Override void destroy(QueryOptions queryOptions); @Override CloseableIterable<A> getDistinctKeys(final QueryOptions queryOptions); @Override CloseableIterable<A> getDistinctKeys(A lowerBound, boolean lowerInclusive, A upperBound, boolean upperInclusive, final QueryOptions queryOptions); @Override CloseableIterable<A> getDistinctKeysDescending(QueryOptions queryOptions); @Override CloseableIterable<A> getDistinctKeysDescending(A lowerBound, boolean lowerInclusive, A upperBound, boolean upperInclusive, QueryOptions queryOptions); @Override Integer getCountOfDistinctKeys(QueryOptions queryOptions); @Override CloseableIterable<KeyStatistics<A>> getStatisticsForDistinctKeysDescending(QueryOptions queryOptions); @Override CloseableIterable<KeyStatistics<A>> getStatisticsForDistinctKeys(QueryOptions queryOptions); @Override CloseableIterable<KeyValue<A, O>> getKeysAndValues(final QueryOptions queryOptions); @Override CloseableIterable<KeyValue<A, O>> getKeysAndValues(A lowerBound, boolean lowerInclusive, A upperBound, boolean upperInclusive, final QueryOptions queryOptions); @Override CloseableIterable<KeyValue<A, O>> getKeysAndValuesDescending(QueryOptions queryOptions); @Override CloseableIterable<KeyValue<A, O>> getKeysAndValuesDescending(A lowerBound, boolean lowerInclusive, A upperBound, boolean upperInclusive, QueryOptions queryOptions); @Override Integer getCountForKey(A key, QueryOptions queryOptions); @Override boolean equals(Object o); @Override int hashCode(); static SQLiteIndex<A, O, K> onAttribute(final Attribute<O, A> attribute,
                                                                                   final SimpleAttribute<O, K> objectKeyAttribute,
                                                                                   final SimpleAttribute<K, O> foreignKeyAttribute);  }
@Test public void testRowIterable(){ Iterable<DBQueries.Row<Integer, String>> rows = SQLiteIndex.rowIterable(data, Car.CAR_ID, Car.FEATURES, null); assertNotNull(rows); Iterator<DBQueries.Row<Integer, String>> rowsIterator = rows.iterator(); assertNotNull(rowsIterator); assertTrue(rowsIterator.hasNext()); assertEquals(new DBQueries.Row<Integer, String>(1, "abs"), rowsIterator.next()); assertTrue(rowsIterator.hasNext()); assertEquals(new DBQueries.Row<Integer, String>(1, "gps"), rowsIterator.next()); assertTrue(rowsIterator.hasNext()); assertEquals(new DBQueries.Row<Integer, String>(2, "airbags"), rowsIterator.next()); assertTrue(rowsIterator.hasNext()); assertEquals(new DBQueries.Row<Integer, String>(3, "abs"), rowsIterator.next()); assertTrue(rowsIterator.hasNext()); assertEquals(new DBQueries.Row<Integer, String>(5, "gps"), rowsIterator.next()); assertFalse(rowsIterator.hasNext()); }