1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package android.support.v17.leanback.database; 15 16 import android.database.Cursor; 17 18 /** 19 * Abstract class used to convert the current {@link Cursor} row to a single 20 * object. 21 */ 22 public abstract class CursorMapper { 23 24 private Cursor mCursor; 25 26 /** 27 * Called once when the associated {@link Cursor} is changed. A subclass 28 * should bind column indexes to column names in this method. This method is 29 * not intended to be called outside of CursorMapper. 30 */ bindColumns(Cursor cursor)31 protected abstract void bindColumns(Cursor cursor); 32 33 /** 34 * A subclass should implement this method to create a single object using 35 * binding information. This method is not intended to be called 36 * outside of CursorMapper. 37 */ bind(Cursor cursor)38 protected abstract Object bind(Cursor cursor); 39 40 /** 41 * Convert a {@link Cursor} at its current position to an Object. 42 */ convert(Cursor cursor)43 public Object convert(Cursor cursor) { 44 if (cursor != mCursor) { 45 mCursor = cursor; 46 bindColumns(mCursor); 47 } 48 return bind(mCursor); 49 } 50 } 51