// Path: app/src/main/java/io/github/marktony/espresso/data/Company.java
// public class Company extends RealmObject {
// 
//     @Expose
//     @SerializedName("name")
//     private String name;
// 
//     @PrimaryKey
//     @Expose
//     @SerializedName("id")
//     private String id;
// 
//     @Expose
//     @SerializedName("tel")
//     private String tel;
// 
//     @Expose
//     @SerializedName("website")
//     private String website;
// 
//     @Expose
//     @SerializedName("alphabet")
//     private String alphabet;
// 
//     @Expose
//     @SerializedName("avatar")
//     private String avatar;
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getTel() {
//         return tel;
//     }
// 
//     public void setTel(String tel) {
//         this.tel = tel;
//     }
// 
//     public String getWebsite() {
//         return website;
//     }
// 
//     public void setWebsite(String website) {
//         this.website = website;
//     }
// 
//     public String getAlphabet() {
//         return alphabet;
//     }
// 
//     public void setAlphabet(String alphabet) {
//         this.alphabet = alphabet;
//     }
// 
//     public String getAvatarColor() {
//         return avatar;
//     }
// 
//     public void setAvatarColor(String avatar) {
//         this.avatar = avatar;
//     }
// 
//     @Override
//     public String toString() {
//         return new Gson().toJson(this);
//     }
// }
// 
// Path: app/src/main/java/io/github/marktony/espresso/data/source/CompaniesDataSource.java
// public interface CompaniesDataSource {
// 
//     Observable<List<Company>> getCompanies();
// 
//     Observable<Company> getCompany(@NonNull String companyId);
// 
//     void initData();
// 
//     Observable<List<Company>> searchCompanies(@NonNull String keyWords);
// 
// }
// 
// Path: app/src/main/java/io/github/marktony/espresso/realm/RealmHelper.java
// public class RealmHelper {
// 
//     public static final String DATABASE_NAME = "Espresso.realm";
// 
//     public static Realm newRealmInstance() {
//         return Realm.getInstance(new RealmConfiguration.Builder()
//                 .deleteRealmIfMigrationNeeded()
//                 .name(RealmHelper.DATABASE_NAME)
//                 .build());
//     }
// 
// }


import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
import io.github.marktony.espresso.data.Company;
import io.github.marktony.espresso.data.source.CompaniesDataSource;
import io.github.marktony.espresso.realm.RealmHelper;
import io.reactivex.Observable;
import io.realm.Case;
import io.realm.Realm;
import io.realm.Sort;
/*
 *  Copyright(c) 2017 lizhaotailang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.marktony.espresso.data.source.local;




/**
 * Created by lizhaotailang on 2017/3/22.
 */

public class CompaniesLocalDataSource implements CompaniesDataSource {

    @Nullable
    public static CompaniesLocalDataSource INSTANCE = null;

    // Prevent direct instantiation
    private CompaniesLocalDataSource() {

    }

    public static CompaniesLocalDataSource getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new CompaniesLocalDataSource();
        }
        return INSTANCE;
    }

    @Override
    public Observable<List<Company>> getCompanies() {
        Realm rlm = RealmHelper.newRealmInstance();
        return Observable
                .fromIterable(rlm.copyFromRealm(rlm.where(Company.class).findAllSorted("alphabet", Sort.ASCENDING)))
                .toList()
                .toObservable();
    }

    @Override
    public Observable<Company> getCompany(@NonNull String companyId) {
// Path: app/src/main/java/io/github/marktony/espresso/data/Company.java
// public class Company extends RealmObject {
// 
//     @Expose
//     @SerializedName("name")
//     private String name;
// 
//     @PrimaryKey
//     @Expose
//     @SerializedName("id")
//     private String id;
// 
//     @Expose
//     @SerializedName("tel")
//     private String tel;
// 
//     @Expose
//     @SerializedName("website")
//     private String website;
// 
//     @Expose
//     @SerializedName("alphabet")
//     private String alphabet;
// 
//     @Expose
//     @SerializedName("avatar")
//     private String avatar;
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getTel() {
//         return tel;
//     }
// 
//     public void setTel(String tel) {
//         this.tel = tel;
//     }
// 
//     public String getWebsite() {
//         return website;
//     }
// 
//     public void setWebsite(String website) {
//         this.website = website;
//     }
// 
//     public String getAlphabet() {
//         return alphabet;
//     }
// 
//     public void setAlphabet(String alphabet) {
//         this.alphabet = alphabet;
//     }
// 
//     public String getAvatarColor() {
//         return avatar;
//     }
// 
//     public void setAvatarColor(String avatar) {
//         this.avatar = avatar;
//     }
// 
//     @Override
//     public String toString() {
//         return new Gson().toJson(this);
//     }
// }
// 
// Path: app/src/main/java/io/github/marktony/espresso/data/source/CompaniesDataSource.java
// public interface CompaniesDataSource {
// 
//     Observable<List<Company>> getCompanies();
// 
//     Observable<Company> getCompany(@NonNull String companyId);
// 
//     void initData();
// 
//     Observable<List<Company>> searchCompanies(@NonNull String keyWords);
// 
// }
// 
// Path: app/src/main/java/io/github/marktony/espresso/realm/RealmHelper.java
// public class RealmHelper {
// 
//     public static final String DATABASE_NAME = "Espresso.realm";
// 
//     public static Realm newRealmInstance() {
//         return Realm.getInstance(new RealmConfiguration.Builder()
//                 .deleteRealmIfMigrationNeeded()
//                 .name(RealmHelper.DATABASE_NAME)
//                 .build());
//     }
// 
// }


// Path: app/src/main/java/io/github/marktony/espresso/data/source/local/CompaniesLocalDataSource.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
import io.github.marktony.espresso.data.Company;
import io.github.marktony.espresso.data.source.CompaniesDataSource;
import io.github.marktony.espresso.realm.RealmHelper;
import io.reactivex.Observable;
import io.realm.Case;
import io.realm.Realm;
import io.realm.Sort;

/*
 *  Copyright(c) 2017 lizhaotailang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.marktony.espresso.data.source.local;




/**
 * Created by lizhaotailang on 2017/3/22.
 */

public class CompaniesLocalDataSource implements CompaniesDataSource {

    @Nullable
    public static CompaniesLocalDataSource INSTANCE = null;

    // Prevent direct instantiation
    private CompaniesLocalDataSource() {

    }

    public static CompaniesLocalDataSource getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new CompaniesLocalDataSource();
        }
        return INSTANCE;
    }

    @Override
    public Observable<List<Company>> getCompanies() {
        Realm rlm = RealmHelper.newRealmInstance();
        return Observable
                .fromIterable(rlm.copyFromRealm(rlm.where(Company.class).findAllSorted("alphabet", Sort.ASCENDING)))
                .toList()
                .toObservable();
    }

    @Override
    public Observable<Company> getCompany(@NonNull String companyId) {
        Realm rlm = RealmHelper.newRealmInstance();