// Path: app/src/main/java/org/freespanish/diccionario/database/DiccionarioDBHelper.java
// public class DiccionarioDBHelper extends SQLiteOpenHelper {
// 
//     private static final String DATABASE_NAME = "diccionario.db";
//     private static final int DATABASE_VERSION = 1;
//     private static DiccionarioDBHelper diccionarioDBHelper;
// 
//     private DiccionarioDBHelper(Context context) {
//         super(context, DATABASE_NAME, null, DATABASE_VERSION);
//     }
// 
//     public static DiccionarioDBHelper getInstance(Context context) {
//         if (diccionarioDBHelper == null)
//             return new DiccionarioDBHelper(context.getApplicationContext());
//         return diccionarioDBHelper;
//     }
// 
//     static {
//         cupboard().register(Definition.class);
//     }
// 
//     @Override
//     public void onCreate(SQLiteDatabase db) {
//         cupboard().withDatabase(db).createTables();
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//         cupboard().withDatabase(db).upgradeTables();
//     }
// }
// 
// Path: app/src/main/java/org/freespanish/diccionario/database/models/Definition.java
// public class Definition implements Comparable<Definition> {
// 
//     public Long _id;
//     public String word;
//     public Boolean isFavorite;
//     public Boolean isHistory;
//     public Long historyTimestamp;
// 
//     public Definition() {
//     }
// 
//     public Definition(String word, Boolean isFavorite, Boolean isHistory, Long historyTimestamp) {
//         this.word = word;
//         this.isFavorite = isFavorite;
//         this.isHistory = isHistory;
//         this.historyTimestamp = historyTimestamp;
//     }
// 
//     public Definition(String word, Boolean isFavorite) {
//         this.word = word;
//         this.isFavorite = isFavorite;
//         this.isHistory = false;
//         this.historyTimestamp = 0L;
//     }
// 
//     public Definition(String word, Long historyTimestamp) {
//         this.word = word;
//         this.isHistory = true;
//         this.historyTimestamp = historyTimestamp;
//         this.isFavorite = false;
//     }
// 
//     @Override
//     public int compareTo(@NonNull Definition o) {
//         if (this.historyTimestamp < o.historyTimestamp)
//             return 1;
//         else if (this.historyTimestamp > o.historyTimestamp)
//             return -1;
//         else
//             return 0;
//     }
// }


import android.content.Context;
import android.database.Cursor;
import org.freespanish.diccionario.database.DiccionarioDBHelper;
import org.freespanish.diccionario.database.models.Definition;
import java.util.ArrayList;
import nl.qbusict.cupboard.QueryResultIterable;
import static nl.qbusict.cupboard.CupboardFactory.cupboard;
package org.freespanish.diccionario.fragments.fav;






/**
 *    This file is part of Diccionario.
 *
 *    Diccionario is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Diccionario is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Diccionario.  If not, see <http://www.gnu.org/licenses/>.
 */

public class FavInteractorImpl implements FavInteractor {

    @Override
    public ArrayList<Definition> retrieveFavorites(Context context) {
        ArrayList<Definition> definitions = new ArrayList<>();
        Cursor history = cupboard().withDatabase(DiccionarioDBHelper.getInstance(context)
                .getReadableDatabase())
                .query(Definition.class).getCursor();
        try {
// Path: app/src/main/java/org/freespanish/diccionario/database/DiccionarioDBHelper.java
// public class DiccionarioDBHelper extends SQLiteOpenHelper {
// 
//     private static final String DATABASE_NAME = "diccionario.db";
//     private static final int DATABASE_VERSION = 1;
//     private static DiccionarioDBHelper diccionarioDBHelper;
// 
//     private DiccionarioDBHelper(Context context) {
//         super(context, DATABASE_NAME, null, DATABASE_VERSION);
//     }
// 
//     public static DiccionarioDBHelper getInstance(Context context) {
//         if (diccionarioDBHelper == null)
//             return new DiccionarioDBHelper(context.getApplicationContext());
//         return diccionarioDBHelper;
//     }
// 
//     static {
//         cupboard().register(Definition.class);
//     }
// 
//     @Override
//     public void onCreate(SQLiteDatabase db) {
//         cupboard().withDatabase(db).createTables();
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//         cupboard().withDatabase(db).upgradeTables();
//     }
// }
// 
// Path: app/src/main/java/org/freespanish/diccionario/database/models/Definition.java
// public class Definition implements Comparable<Definition> {
// 
//     public Long _id;
//     public String word;
//     public Boolean isFavorite;
//     public Boolean isHistory;
//     public Long historyTimestamp;
// 
//     public Definition() {
//     }
// 
//     public Definition(String word, Boolean isFavorite, Boolean isHistory, Long historyTimestamp) {
//         this.word = word;
//         this.isFavorite = isFavorite;
//         this.isHistory = isHistory;
//         this.historyTimestamp = historyTimestamp;
//     }
// 
//     public Definition(String word, Boolean isFavorite) {
//         this.word = word;
//         this.isFavorite = isFavorite;
//         this.isHistory = false;
//         this.historyTimestamp = 0L;
//     }
// 
//     public Definition(String word, Long historyTimestamp) {
//         this.word = word;
//         this.isHistory = true;
//         this.historyTimestamp = historyTimestamp;
//         this.isFavorite = false;
//     }
// 
//     @Override
//     public int compareTo(@NonNull Definition o) {
//         if (this.historyTimestamp < o.historyTimestamp)
//             return 1;
//         else if (this.historyTimestamp > o.historyTimestamp)
//             return -1;
//         else
//             return 0;
//     }
// }


// Path: app/src/main/java/org/freespanish/diccionario/fragments/fav/FavInteractorImpl.java
import android.content.Context;
import android.database.Cursor;
import org.freespanish.diccionario.database.DiccionarioDBHelper;
import org.freespanish.diccionario.database.models.Definition;
import java.util.ArrayList;
import nl.qbusict.cupboard.QueryResultIterable;
import static nl.qbusict.cupboard.CupboardFactory.cupboard;

package org.freespanish.diccionario.fragments.fav;






/**
 *    This file is part of Diccionario.
 *
 *    Diccionario is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Diccionario is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Diccionario.  If not, see <http://www.gnu.org/licenses/>.
 */

public class FavInteractorImpl implements FavInteractor {

    @Override
    public ArrayList<Definition> retrieveFavorites(Context context) {
        ArrayList<Definition> definitions = new ArrayList<>();
        Cursor history = cupboard().withDatabase(DiccionarioDBHelper.getInstance(context)
                .getReadableDatabase())
                .query(Definition.class).getCursor();
        try {
            QueryResultIterable<Definition> itr = cupboard().withCursor(history).iterate(Definition.class);