If you think the Android project adme 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 com.danielesegato.adme.db.serializer;
/*fromwww.java2s.com*/import android.content.ContentValues;
import android.database.Cursor;
import com.danielesegato.adme.config.ADMEFieldConfig;
import com.danielesegato.adme.config.SQLiteType;
/**
* Persist a primitive boolean in the SQLite database.
*/publicclass BooleanADMESerializer extends BaseADMESerializer {
publicstaticfinal String BOOLEAN_TRUE = "1";
publicstaticfinal String BOOLEAN_FALSE = "0";
privatestatic BooleanADMESerializer singleton = new BooleanADMESerializer();
publicstatic BooleanADMESerializer getSingleton() {
return singleton;
}
@Override
public SQLiteType getSQLiteType() {
return SQLiteType.NUMERIC;
}
@Override
public Object sqlToJava(Cursor cursor, int columnPos, ADMEFieldConfig fieldConfig) {
return cursor.getInt(columnPos) == 1;
}
@Override
public String stringToSqlRaw(String val, ADMEFieldConfig fieldConfig) {
return val.equals(BOOLEAN_TRUE) ? BOOLEAN_TRUE : BOOLEAN_FALSE;
}
@Override
publicvoid storeInContentValues(String key, ContentValues values, Object fieldValue, ADMEFieldConfig fieldConfig) throws IllegalArgumentException {
if (fieldValue == null || !(fieldValue instanceof Boolean)) {
thrownew IllegalArgumentException(String.format(
String.format("Field value for entity %s field %s can't be considered a primitive boolean for key %s: %s",
fieldConfig.getADMEEntityConfig().getEntityName(),
fieldConfig.getColumnName(),
key,
fieldValue)
));
}
values.put(key, (Boolean) fieldValue);
}
}