Open
Description
Hi, @SimonVT .
I'm thinking about creating merge request with "column getter" functionality (see description below). Please tell me if it suitable for library or not.
Motivation: Instead of writing String note = cursor.getString(cursor.getColumnIndex(NoteColumns.NOTE));
just call String note = NotesGetter.noteString(cursor);
. It's more significant when you deal with nullable columns.
Couple details about suggested implementation:
- Use
getColumnIndexOrThrow
instead ofgetColumnIndex
. I think this approach is more robust because let identify problems earlier. - Create implementation for all primitive types and for wrappers. Support
null
for wrappers. Example of generated code.
public static Integer getIdIntOrNull(Cursor cursor) {
int index = cursor.getColumnIndexOrThrow(NoteColumns.ID);
if (cursor.isNull(index)) {
return null;
} else {
return cursor.getInt(index);
}
}
public int getIdInt(Cursor cursor) {
return cursor.getInt(cursor.getColumnIndexOrThrow(NoteColumns.ID));
}
- I'll always generate
null
support despite@NotNull
annotation. - I'm still looking for better class and method names.
Metadata
Metadata
Assignees
Labels
No labels