// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/db/collection.java
// public class Collection {
// 
//     private Long id;
//     private String title;
//     private String detail;
//     private String url;
//     private Integer type;
// 
//     public Collection() {
//     }
// 
//     public Collection(Long id) {
//         this.id = id;
//     }
// 
//     public Collection(Long id, String title, String detail, String url, Integer type) {
//         this.id = id;
//         this.title = title;
//         this.detail = detail;
//         this.url = url;
//         this.type = type;
//     }
// 
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(String title) {
//         this.title = title;
//     }
// 
//     public String getDetail() {
//         return detail;
//     }
// 
//     public void setDetail(String detail) {
//         this.detail = detail;
//     }
// 
//     public String getUrl() {
//         return url;
//     }
// 
//     public void setUrl(String url) {
//         this.url = url;
//     }
// 
//     public Integer getType() {
//         return type;
//     }
// 
//     public void setType(Integer type) {
//         this.type = type;
//     }
// 
// }
// 
// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/db/DbUtil.java
// public class DbUtil {
// 
//     private static CollectionService operatorsService;
// 
// 
//     private static CollectionDao getOperatorsDao() {
//         return DbCore.getDaoSession().getCollectionDao();
//     }
// 
// 
// 
// 
//     public static CollectionService getOperatorsService() {
//         if (operatorsService == null) {
//             operatorsService = new CollectionService(getOperatorsDao());
//         }
//         return operatorsService;
//     }
// }
// 
// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/db/DbUtil.java
// public static CollectionService getOperatorsService() {
//     if (operatorsService == null) {
//         operatorsService = new CollectionService(getOperatorsDao());
//     }
//     return operatorsService;
// }


import com.jiang.android.zhihu_topanswer.db.Collection;
import com.jiang.android.zhihu_topanswer.db.DbUtil;
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Func1;
import static com.jiang.android.zhihu_topanswer.db.DbUtil.getOperatorsService;
    private CollectionUtils() {
        mLists = new ArrayList<>();
        mLists.addAll(getOperatorsService().queryAll());
    }


    public void saveItem(Collection model){
        getOperatorsService().save(model);
        mLists.add(model);


    }


    public Observable<Collection> contailItem(final String url){
      return   Observable.from(mLists)
                .filter(new Func1<Collection, Boolean>() {
                    @Override
                    public Boolean call(Collection model) {
                        return model.getUrl().equals(url);
                    }
                });
    }


    public void removeItem(String mQuestionUrl) {
        for (int i = 0; i < mLists.size(); i++) {
            if(mLists.get(i).getUrl().equals(mQuestionUrl)){
              List<Collection> list =   DbUtil.getOperatorsService().query(" where url=?",mLists.get(i).getUrl());
                if(list!= null && list.size()>0){
// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/db/collection.java
// public class Collection {
// 
//     private Long id;
//     private String title;
//     private String detail;
//     private String url;
//     private Integer type;
// 
//     public Collection() {
//     }
// 
//     public Collection(Long id) {
//         this.id = id;
//     }
// 
//     public Collection(Long id, String title, String detail, String url, Integer type) {
//         this.id = id;
//         this.title = title;
//         this.detail = detail;
//         this.url = url;
//         this.type = type;
//     }
// 
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(String title) {
//         this.title = title;
//     }
// 
//     public String getDetail() {
//         return detail;
//     }
// 
//     public void setDetail(String detail) {
//         this.detail = detail;
//     }
// 
//     public String getUrl() {
//         return url;
//     }
// 
//     public void setUrl(String url) {
//         this.url = url;
//     }
// 
//     public Integer getType() {
//         return type;
//     }
// 
//     public void setType(Integer type) {
//         this.type = type;
//     }
// 
// }
// 
// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/db/DbUtil.java
// public class DbUtil {
// 
//     private static CollectionService operatorsService;
// 
// 
//     private static CollectionDao getOperatorsDao() {
//         return DbCore.getDaoSession().getCollectionDao();
//     }
// 
// 
// 
// 
//     public static CollectionService getOperatorsService() {
//         if (operatorsService == null) {
//             operatorsService = new CollectionService(getOperatorsDao());
//         }
//         return operatorsService;
//     }
// }
// 
// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/db/DbUtil.java
// public static CollectionService getOperatorsService() {
//     if (operatorsService == null) {
//         operatorsService = new CollectionService(getOperatorsDao());
//     }
//     return operatorsService;
// }


// Path: app/src/main/java/com/jiang/android/zhihu_topanswer/utils/CollectionUtils.java
import com.jiang.android.zhihu_topanswer.db.Collection;
import com.jiang.android.zhihu_topanswer.db.DbUtil;
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Func1;
import static com.jiang.android.zhihu_topanswer.db.DbUtil.getOperatorsService;

    private CollectionUtils() {
        mLists = new ArrayList<>();
        mLists.addAll(getOperatorsService().queryAll());
    }


    public void saveItem(Collection model){
        getOperatorsService().save(model);
        mLists.add(model);


    }


    public Observable<Collection> contailItem(final String url){
      return   Observable.from(mLists)
                .filter(new Func1<Collection, Boolean>() {
                    @Override
                    public Boolean call(Collection model) {
                        return model.getUrl().equals(url);
                    }
                });
    }


    public void removeItem(String mQuestionUrl) {
        for (int i = 0; i < mLists.size(); i++) {
            if(mLists.get(i).getUrl().equals(mQuestionUrl)){
              List<Collection> list =   DbUtil.getOperatorsService().query(" where url=?",mLists.get(i).getUrl());
                if(list!= null && list.size()>0){
                    DbUtil.getOperatorsService().delete(list);