We have implemented PutResolver before and we have created a stub interface for the GetResolver. Here, we will finish the work that we have started by fully implementing the missing interface.
Let's create a class named StockUpdateGetResolver in the same package as StockUpdatePutResolver, which will extend the DefaultGetResolver class:
public class StockUpdateGetResolver extends DefaultGetResolver<StockUpdate> {
}
Next, add a missing implementation of mapFromCursor():
@NonNull
@Override
public StockUpdate mapFromCursor(@NonNull Cursor cursor) {
final int id = cursor.getInt(cursor.getColumnIndexOrThrow
(StockUpdateTable.Columns.ID));
final long dateLong = cursor.getLong(cursor.getColumnIndexOrThrow
(StockUpdateTable.Columns.DATE));
final long priceLong = cursor.getLong(cursor.getColumnIndexOrThrow
(StockUpdateTable.Columns.PRICE));
final String stockSymbol =
cursor.getString(cursor.getColumnIndexOrThrow
(StockUpdateTable.Columns.STOCK_SYMBOL));
Date date = getDate(dateLong);
BigDecimal price = getPrice(priceLong);
final StockUpdate stockUpdate = new StockUpdate(
stockSymbol,
price,
date
);
stockUpdate.setId(id);
return stockUpdate;
}
It's quite a big chunk of code, so let's dig into its pieces.