Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.gawst.asyncdb.purge;
 
 
 import  android.support.annotation.NonNull;
 import  android.text.TextUtils;

Abstract helper class to purge a database with a maximum number of items and based on a sorted field.

Parameters:
<LAST_ELEMENT> Type of the last element to keep during the purge.
public abstract class DatabaseSourcePurgerMax<LAST_ELEMENT> extends DatabaseSourcePurger<LAST_ELEMENT> {
	protected final String fieldName;

Constructor for the database purger. It will purge the database after each insertion.

Parameters:
maxItems Maximum number of items to keep in the database.
fieldName Name of the sorted field in the database to determine 'old' elements
databaseSource Database source (Sqlite, ContentProvider)
	public DatabaseSourcePurgerMax(int maxItemsString fieldNameTypedDatabaseSource<?, ?, ?> databaseSource) {
		this(maxItems, 1, fieldNamedatabaseSource);
	}

Constructor for the database purger.

Parameters:
maxItems Maximum number of items to keep in the database.
checkInsertFrequency The number of insertion before a purge is done. A purge is done after the first insertion.
fieldName Name of the sorted field in the database to determine 'old' elements
databaseSource Database source (Sqlite, ContentProvider)
	public DatabaseSourcePurgerMax(int maxItemsint checkInsertFrequencyString fieldNameTypedDatabaseSource<?, ?, ?> databaseSource) {
		super(maxItemscheckInsertFrequencydatabaseSource);
		this. = fieldName;
	}
	@NonNull
	protected final String[] getFilterFields() {
		return new String[]{};
	}
	@NonNull
	protected String getFilterOrder() {
		return  + " desc";
	}
	@NonNull
	protected String getDeleteClause(LAST_ELEMENT lastElement) {
		String purgeFilterClause = getPurgeFilterClause();
		if (TextUtils.isEmpty(purgeFilterClause)) {
			return  + " < ?";
else {
			return  + " < ? AND (" + purgeFilterClause + ')';
		}
	}
	@NonNull
	protected String[] getDeleteArgs(LAST_ELEMENT lastElement) {
		if (args == null) {
			return new String[]{String.valueOf(lastElement)};
else {
			String[] result = new String[args.length + 1];
			result[0] = String.valueOf(lastElement);
			System.arraycopy(args, 0, result, 1, args.length);
			return result;
		}
	}
New to GrepCode? Check out our FAQ X