// Path: ExpenseTracker/app/src/main/java/com/pedrocarrillo/expensetracker/utils/RealmManager.java
// public class RealmManager {
// 
//     private Realm realm;
// 
//     private static RealmManager ourInstance = new RealmManager();
// 
//     public static RealmManager getInstance() {
//         return ourInstance;
//     }
// 
//     public RealmManager(){
//         realm = Realm.getInstance(ExpenseTrackerApp.getContext());
//     }
// 
//     public Realm getRealmInstance() {
//         return realm;
//     }
// 
//     public <E extends RealmObject> void update(final E object) {
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 realm.copyToRealmOrUpdate(object);
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void update(final Iterable<E> object) {
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 realm.copyToRealmOrUpdate(object);
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void save(final E object, final Class<E> clazz) {
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 checkDuplicateUUID(object, clazz);
//                 realm.copyToRealmOrUpdate(object);
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void delete(final Iterable<E> objects){
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 if (objects == null) {
//                     return;
//                 }
//                 for (E object : objects) {
//                     if (object instanceof Category) {
//                         Category category = (Category) object;
//                         RealmResults<Expense> expenseList  = Expense.getExpensesPerCategory(category);
//                         for (int i = expenseList.size()-1; i >= 0; i--) {
//                             expenseList.get(i).removeFromRealm();
//                         }
//                     }
//                     object.removeFromRealm();
//                 }
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void delete(final E object){
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 if (object instanceof Category) {
//                     Category category = (Category) object;
//                     RealmResults<Expense> expenseList  = Expense.getExpensesPerCategory(category);
//                     for (int i = expenseList.size()-1; i >= 0; i--) {
//                         expenseList.get(i).removeFromRealm();
//                     }
//                 }
//                 object.removeFromRealm();
//             }
//         });
//     }
// 
//     public <E extends RealmObject> RealmObject findById(Class<E> clazz, String id) {
//         return realm.where(clazz).equalTo("id", id).findFirst();
//     }
// 
//     public <E extends RealmObject>  void checkDuplicateUUID(E object, Class<E> clazz) {
//         boolean repeated = true;
//         while (repeated) {
//             String id = UUID.randomUUID().toString();
//             RealmObject realmObject = findById(clazz, id);
//             if ( realmObject == null ) {
//                 if (object instanceof Expense) {
//                     ((Expense)object).setId(id);
//                 } else if (object instanceof  Category){
//                     ((Category)object).setId(id);
//                 } else {
//                     ((Reminder)object).setId(id);
//                 }
//                 repeated = false;
//             }
//         }
//     }
// 
// }


import com.pedrocarrillo.expensetracker.interfaces.IExpensesType;
import com.pedrocarrillo.expensetracker.utils.RealmManager;
import java.util.List;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.annotations.PrimaryKey;
package com.pedrocarrillo.expensetracker.entities;




/**
 * Created by pcarrillo on 17/09/2015.
 */
public class Category extends RealmObject {

    @PrimaryKey
    private String id;

    private String name;
    private int type;
    private RealmList<Expense> expenses;

    public Category() {
    }

    public Category(String name, @IExpensesType int type) {
        this.name = name;
        this.type = type;
    }

    public String getName() {
// Path: ExpenseTracker/app/src/main/java/com/pedrocarrillo/expensetracker/utils/RealmManager.java
// public class RealmManager {
// 
//     private Realm realm;
// 
//     private static RealmManager ourInstance = new RealmManager();
// 
//     public static RealmManager getInstance() {
//         return ourInstance;
//     }
// 
//     public RealmManager(){
//         realm = Realm.getInstance(ExpenseTrackerApp.getContext());
//     }
// 
//     public Realm getRealmInstance() {
//         return realm;
//     }
// 
//     public <E extends RealmObject> void update(final E object) {
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 realm.copyToRealmOrUpdate(object);
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void update(final Iterable<E> object) {
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 realm.copyToRealmOrUpdate(object);
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void save(final E object, final Class<E> clazz) {
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 checkDuplicateUUID(object, clazz);
//                 realm.copyToRealmOrUpdate(object);
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void delete(final Iterable<E> objects){
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 if (objects == null) {
//                     return;
//                 }
//                 for (E object : objects) {
//                     if (object instanceof Category) {
//                         Category category = (Category) object;
//                         RealmResults<Expense> expenseList  = Expense.getExpensesPerCategory(category);
//                         for (int i = expenseList.size()-1; i >= 0; i--) {
//                             expenseList.get(i).removeFromRealm();
//                         }
//                     }
//                     object.removeFromRealm();
//                 }
//             }
//         });
//     }
// 
//     public <E extends RealmObject> void delete(final E object){
//         realm.executeTransaction(new Realm.Transaction() {
//             @Override
//             public void execute(Realm realm) {
//                 if (object instanceof Category) {
//                     Category category = (Category) object;
//                     RealmResults<Expense> expenseList  = Expense.getExpensesPerCategory(category);
//                     for (int i = expenseList.size()-1; i >= 0; i--) {
//                         expenseList.get(i).removeFromRealm();
//                     }
//                 }
//                 object.removeFromRealm();
//             }
//         });
//     }
// 
//     public <E extends RealmObject> RealmObject findById(Class<E> clazz, String id) {
//         return realm.where(clazz).equalTo("id", id).findFirst();
//     }
// 
//     public <E extends RealmObject>  void checkDuplicateUUID(E object, Class<E> clazz) {
//         boolean repeated = true;
//         while (repeated) {
//             String id = UUID.randomUUID().toString();
//             RealmObject realmObject = findById(clazz, id);
//             if ( realmObject == null ) {
//                 if (object instanceof Expense) {
//                     ((Expense)object).setId(id);
//                 } else if (object instanceof  Category){
//                     ((Category)object).setId(id);
//                 } else {
//                     ((Reminder)object).setId(id);
//                 }
//                 repeated = false;
//             }
//         }
//     }
// 
// }


// Path: ExpenseTracker/app/src/main/java/com/pedrocarrillo/expensetracker/entities/Category.java
import com.pedrocarrillo.expensetracker.interfaces.IExpensesType;
import com.pedrocarrillo.expensetracker.utils.RealmManager;
import java.util.List;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.annotations.PrimaryKey;

package com.pedrocarrillo.expensetracker.entities;




/**
 * Created by pcarrillo on 17/09/2015.
 */
public class Category extends RealmObject {

    @PrimaryKey
    private String id;

    private String name;
    private int type;
    private RealmList<Expense> expenses;

    public Category() {
    }

    public Category(String name, @IExpensesType int type) {
        this.name = name;
        this.type = type;
    }

    public String getName() {
        return name;