If you think the Android project InMemoryDb listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.gawst.asyncdb.purge;
/*www.java2s.com*/import android.database.Cursor;
import android.support.annotation.Nullable;
import org.gawst.asyncdb.source.DatabaseSource;
/**
* Helper class to purge a database with a maximum number of items and based on a date field.
*
* @author Created by robUx4 on 07/01/2015.
*/publicclass DatabasePurgerMaxDate extends DatabaseSourcePurgerMax<Long> {
/**
* Constructor for the database purger. It will purge the database after each insertion.
*
* @param maxItems Maximum number of items to keep in the database.
* @param dateField Date field in the database.
* @param databaseSource Database source (Sqlite, ContentProvider)
*/public DatabasePurgerMaxDate(int maxItems, String dateField, DatabaseSource<?, ?> databaseSource) {
super(maxItems, dateField, databaseSource);
}
/**
* Constructor for the database purger.
*
* @param maxItems Maximum number of items to keep in the database.
* @param checkInsertFrequency The number of insertion before a purge is done. A purge is done after the first insertion.
* @param dateField Date field in the database.
* @param databaseSource Database source (Sqlite, ContentProvider)
*/public DatabasePurgerMaxDate(int maxItems, int checkInsertFrequency, String dateField, DatabaseSource<?, ?> databaseSource) {
super(maxItems, checkInsertFrequency, dateField, databaseSource);
}
@Nullable
@Override
protectedfinal Long getLastFilteredElement(Cursor cursor) {
int freshnessIndex = cursor.getColumnIndex(fieldName);
if (cursor.isNull(freshnessIndex))
return null;
return cursor.getLong(freshnessIndex);
}
}