repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
hufeiya/CoolSignIn | Server/src/com/hufeiya/jsonObject/JsonStudent.java | // Path: Server/src/com/hufeiya/entity/SignInfo.java
// public class SignInfo implements java.io.Serializable {
//
// // Fields
//
// private Integer signId;
// private Student student;
// private Course course;
// private String signDetail;
// private Integer signTimes;
// private String lastSignPhoto;
//
// // Constructors
//
// /** default constructor */
// public SignInfo() {
// }
//
// /** minimal constructor */
// public SignInfo(Student student, Course course) {
// this.student = student;
// this.course = course;
// }
//
// /** full constructor */
// public SignInfo(Student student, Course course, String signDetail,
// Integer signTimes, String lastSignPhoto) {
// this.student = student;
// this.course = course;
// this.signDetail = signDetail;
// this.signTimes = signTimes;
// this.lastSignPhoto = lastSignPhoto;
// }
// /** constructor for update*/
// public SignInfo( String signDetail,
// Integer signTimes, String lastSignPhoto) {
// this.signDetail = signDetail;
// this.signTimes = signTimes;
// this.lastSignPhoto = lastSignPhoto;
// }
//
// // Property accessors
//
// public Integer getSignId() {
// return this.signId;
// }
//
// public void setSignId(Integer signId) {
// this.signId = signId;
// }
//
// public Student getStudent() {
// return this.student;
// }
//
// public void setStudent(Student student) {
// this.student = student;
// }
//
// public Course getCourse() {
// return this.course;
// }
//
// public void setCourse(Course course) {
// this.course = course;
// }
//
// public String getSignDetail() {
// return this.signDetail;
// }
//
// public void setSignDetail(String signDetail) {
// this.signDetail = signDetail;
// }
//
// public Integer getSignTimes() {
// return this.signTimes;
// }
//
// public void setSignTimes(Integer signTimes) {
// this.signTimes = signTimes;
// }
//
// public String getLastSignPhoto() {
// return this.lastSignPhoto;
// }
//
// public void setLastSignPhoto(String lastSignPhoto) {
// this.lastSignPhoto = lastSignPhoto;
// }
//
// }
//
// Path: Server/src/com/hufeiya/entity/Student.java
// public class Student implements java.io.Serializable {
//
// // Fields
//
// private Integer sid;
// private StudentSheet studentSheet;
// private String clientId;
// private String studentName;
// private String studentNo;
// private String className;
// private Set signInfos = new HashSet(0);
//
// // Constructors
//
// /** default constructor */
// public Student() {
// }
//
// /** full constructor */
// public Student(StudentSheet studentSheet, String clientId,
// String studentName, String studentNo, String className,
// Set signInfos) {
// this.studentSheet = studentSheet;
// this.clientId = clientId;
// this.studentName = studentName;
// this.studentNo = studentNo;
// this.className = className;
// this.signInfos = signInfos;
// }
//
// // Property accessors
//
// public Integer getSid() {
// return this.sid;
// }
//
// public void setSid(Integer sid) {
// this.sid = sid;
// }
//
// public StudentSheet getStudentSheet() {
// return this.studentSheet;
// }
//
// public void setStudentSheet(StudentSheet studentSheet) {
// this.studentSheet = studentSheet;
// }
//
// public String getClientId() {
// return this.clientId;
// }
//
// public void setClientId(String clientId) {
// this.clientId = clientId;
// }
//
// public String getStudentName() {
// return this.studentName;
// }
//
// public void setStudentName(String studentName) {
// this.studentName = studentName;
// }
//
// public String getStudentNo() {
// return this.studentNo;
// }
//
// public void setStudentNo(String studentNo) {
// this.studentNo = studentNo;
// }
//
// public String getClassName() {
// return this.className;
// }
//
// public void setClassName(String className) {
// this.className = className;
// }
//
// public Set getSignInfos() {
// return this.signInfos;
// }
//
// public void setSignInfos(Set signInfos) {
// this.signInfos = signInfos;
// }
//
// }
| import java.util.HashSet;
import java.util.Set;
import com.hufeiya.entity.SignInfo;
import com.hufeiya.entity.Student; | package com.hufeiya.jsonObject;
public class JsonStudent {
// Fields
private Integer sid;
private String clientId;
private String studentName;
private String studentNo;
private String className;
private Set<JsonSignInfo> jsonSignInfos = new HashSet<>();
// Constructors
/** default constructor */
public JsonStudent() {
}
public JsonStudent(Student student) {
this.sid = student.getSid();
this.clientId = student.getClientId();
this.studentName = student.getStudentName();
this.studentNo = student.getStudentNo();
this.className = student.getClassName(); | // Path: Server/src/com/hufeiya/entity/SignInfo.java
// public class SignInfo implements java.io.Serializable {
//
// // Fields
//
// private Integer signId;
// private Student student;
// private Course course;
// private String signDetail;
// private Integer signTimes;
// private String lastSignPhoto;
//
// // Constructors
//
// /** default constructor */
// public SignInfo() {
// }
//
// /** minimal constructor */
// public SignInfo(Student student, Course course) {
// this.student = student;
// this.course = course;
// }
//
// /** full constructor */
// public SignInfo(Student student, Course course, String signDetail,
// Integer signTimes, String lastSignPhoto) {
// this.student = student;
// this.course = course;
// this.signDetail = signDetail;
// this.signTimes = signTimes;
// this.lastSignPhoto = lastSignPhoto;
// }
// /** constructor for update*/
// public SignInfo( String signDetail,
// Integer signTimes, String lastSignPhoto) {
// this.signDetail = signDetail;
// this.signTimes = signTimes;
// this.lastSignPhoto = lastSignPhoto;
// }
//
// // Property accessors
//
// public Integer getSignId() {
// return this.signId;
// }
//
// public void setSignId(Integer signId) {
// this.signId = signId;
// }
//
// public Student getStudent() {
// return this.student;
// }
//
// public void setStudent(Student student) {
// this.student = student;
// }
//
// public Course getCourse() {
// return this.course;
// }
//
// public void setCourse(Course course) {
// this.course = course;
// }
//
// public String getSignDetail() {
// return this.signDetail;
// }
//
// public void setSignDetail(String signDetail) {
// this.signDetail = signDetail;
// }
//
// public Integer getSignTimes() {
// return this.signTimes;
// }
//
// public void setSignTimes(Integer signTimes) {
// this.signTimes = signTimes;
// }
//
// public String getLastSignPhoto() {
// return this.lastSignPhoto;
// }
//
// public void setLastSignPhoto(String lastSignPhoto) {
// this.lastSignPhoto = lastSignPhoto;
// }
//
// }
//
// Path: Server/src/com/hufeiya/entity/Student.java
// public class Student implements java.io.Serializable {
//
// // Fields
//
// private Integer sid;
// private StudentSheet studentSheet;
// private String clientId;
// private String studentName;
// private String studentNo;
// private String className;
// private Set signInfos = new HashSet(0);
//
// // Constructors
//
// /** default constructor */
// public Student() {
// }
//
// /** full constructor */
// public Student(StudentSheet studentSheet, String clientId,
// String studentName, String studentNo, String className,
// Set signInfos) {
// this.studentSheet = studentSheet;
// this.clientId = clientId;
// this.studentName = studentName;
// this.studentNo = studentNo;
// this.className = className;
// this.signInfos = signInfos;
// }
//
// // Property accessors
//
// public Integer getSid() {
// return this.sid;
// }
//
// public void setSid(Integer sid) {
// this.sid = sid;
// }
//
// public StudentSheet getStudentSheet() {
// return this.studentSheet;
// }
//
// public void setStudentSheet(StudentSheet studentSheet) {
// this.studentSheet = studentSheet;
// }
//
// public String getClientId() {
// return this.clientId;
// }
//
// public void setClientId(String clientId) {
// this.clientId = clientId;
// }
//
// public String getStudentName() {
// return this.studentName;
// }
//
// public void setStudentName(String studentName) {
// this.studentName = studentName;
// }
//
// public String getStudentNo() {
// return this.studentNo;
// }
//
// public void setStudentNo(String studentNo) {
// this.studentNo = studentNo;
// }
//
// public String getClassName() {
// return this.className;
// }
//
// public void setClassName(String className) {
// this.className = className;
// }
//
// public Set getSignInfos() {
// return this.signInfos;
// }
//
// public void setSignInfos(Set signInfos) {
// this.signInfos = signInfos;
// }
//
// }
// Path: Server/src/com/hufeiya/jsonObject/JsonStudent.java
import java.util.HashSet;
import java.util.Set;
import com.hufeiya.entity.SignInfo;
import com.hufeiya.entity.Student;
package com.hufeiya.jsonObject;
public class JsonStudent {
// Fields
private Integer sid;
private String clientId;
private String studentName;
private String studentNo;
private String className;
private Set<JsonSignInfo> jsonSignInfos = new HashSet<>();
// Constructors
/** default constructor */
public JsonStudent() {
}
public JsonStudent(Student student) {
this.sid = student.getSid();
this.clientId = student.getClientId();
this.studentName = student.getStudentName();
this.studentNo = student.getStudentNo();
this.className = student.getClassName(); | Set<SignInfo> signInfos = student.getSignInfos(); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
| import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query; | package eu.rampsoftware.er.data.datasource.remote;
public interface CurrencyDataApi {
@GET("/historical/{date}.json") | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;
package eu.rampsoftware.er.data.datasource.remote;
public interface CurrencyDataApi {
@GET("/historical/{date}.json") | Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date, |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivityModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
| import android.content.Context;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; | package eu.rampsoftware.er.di;
/**
* Dagger module responsible for providing {@link CurrencyDetailsActivitySubComponent} dependencies. Scope
* of provided dependencies must match the scope of component, which is {@link CurrencyDetailsActivityScope}.
*/
@Module
public class CurrencyDetailsActivityModule implements ICurrencyDetailsActivityModule {
private final Context mContext;
public CurrencyDetailsActivityModule(final Context context) {
mContext = context;
}
@Provides
@CurrencyDetailsActivityScope
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivityModule.java
import android.content.Context;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
package eu.rampsoftware.er.di;
/**
* Dagger module responsible for providing {@link CurrencyDetailsActivitySubComponent} dependencies. Scope
* of provided dependencies must match the scope of component, which is {@link CurrencyDetailsActivityScope}.
*/
@Module
public class CurrencyDetailsActivityModule implements ICurrencyDetailsActivityModule {
private final Context mContext;
public CurrencyDetailsActivityModule(final Context context) {
mContext = context;
}
@Provides
@CurrencyDetailsActivityScope
@Override | public GetCurrencySeriesUseCase provideGetCurrenciesUseCase(final CurrencyRepository currencyRepository) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivityModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
| import android.content.Context;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; | package eu.rampsoftware.er.di;
/**
* Dagger module responsible for providing {@link CurrencyDetailsActivitySubComponent} dependencies. Scope
* of provided dependencies must match the scope of component, which is {@link CurrencyDetailsActivityScope}.
*/
@Module
public class CurrencyDetailsActivityModule implements ICurrencyDetailsActivityModule {
private final Context mContext;
public CurrencyDetailsActivityModule(final Context context) {
mContext = context;
}
@Provides
@CurrencyDetailsActivityScope
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivityModule.java
import android.content.Context;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
package eu.rampsoftware.er.di;
/**
* Dagger module responsible for providing {@link CurrencyDetailsActivitySubComponent} dependencies. Scope
* of provided dependencies must match the scope of component, which is {@link CurrencyDetailsActivityScope}.
*/
@Module
public class CurrencyDetailsActivityModule implements ICurrencyDetailsActivityModule {
private final Context mContext;
public CurrencyDetailsActivityModule(final Context context) {
mContext = context;
}
@Provides
@CurrencyDetailsActivityScope
@Override | public GetCurrencySeriesUseCase provideGetCurrenciesUseCase(final CurrencyRepository currencyRepository) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivityModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
| import android.content.Context;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; | package eu.rampsoftware.er.di;
/**
* Dagger module responsible for providing {@link CurrencyDetailsActivitySubComponent} dependencies. Scope
* of provided dependencies must match the scope of component, which is {@link CurrencyDetailsActivityScope}.
*/
@Module
public class CurrencyDetailsActivityModule implements ICurrencyDetailsActivityModule {
private final Context mContext;
public CurrencyDetailsActivityModule(final Context context) {
mContext = context;
}
@Provides
@CurrencyDetailsActivityScope
@Override
public GetCurrencySeriesUseCase provideGetCurrenciesUseCase(final CurrencyRepository currencyRepository) {
return new GetCurrencySeriesUseCase(Schedulers.io(), AndroidSchedulers.mainThread(),
currencyRepository);
}
@Provides
@CurrencyDetailsActivityScope
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivityModule.java
import android.content.Context;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
package eu.rampsoftware.er.di;
/**
* Dagger module responsible for providing {@link CurrencyDetailsActivitySubComponent} dependencies. Scope
* of provided dependencies must match the scope of component, which is {@link CurrencyDetailsActivityScope}.
*/
@Module
public class CurrencyDetailsActivityModule implements ICurrencyDetailsActivityModule {
private final Context mContext;
public CurrencyDetailsActivityModule(final Context context) {
mContext = context;
}
@Provides
@CurrencyDetailsActivityScope
@Override
public GetCurrencySeriesUseCase provideGetCurrenciesUseCase(final CurrencyRepository currencyRepository) {
return new GetCurrencySeriesUseCase(Schedulers.io(), AndroidSchedulers.mainThread(),
currencyRepository);
}
@Provides
@CurrencyDetailsActivityScope
@Override | public CurrencyDetailsViewModel provideCurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyListViewModel.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesRatesDate.java
// public class GetCurrenciesRatesDate extends NoArgQueryUseCase<Optional<Date>> {
// private final PreferencesData mPreferencesData;
//
// public GetCurrenciesRatesDate(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// final PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mPreferencesData = preferencesData;
// }
//
// @Override
// protected Observable<Optional<Date>> buildUseCaseObservable() {
// return Observable.just(mPreferencesData.getCurrenciesExchangeDate());
//
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
// public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
//
// private final CurrencyRepository mRepository;
// private final PreferencesData mPreferences;
//
// public GetCurrenciesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository,
// PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
// mPreferences = preferencesData;
// }
//
// @Override
// protected Observable<CurrencyData> buildUseCaseObservable(final CurrenciesParam params) {
// mPreferences.setCurrenciesExchangeDate(params.date);
// return mRepository.getCurrencies(params.date);
// }
//
// public static class CurrenciesParam {
// Date date;
//
// public CurrenciesParam(final Date date) {
// this.date = checkNotNull(date);
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
| import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesRatesDate;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesUseCase;
import eu.rampsoftware.er.navigation.Navigator;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | package eu.rampsoftware.er.viewmodel.currencies;
public class CurrencyListViewModel extends BaseDisposableViewModel implements BaseViewModel {
private final GetCurrenciesUseCase mCurrenciesUseCase; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesRatesDate.java
// public class GetCurrenciesRatesDate extends NoArgQueryUseCase<Optional<Date>> {
// private final PreferencesData mPreferencesData;
//
// public GetCurrenciesRatesDate(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// final PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mPreferencesData = preferencesData;
// }
//
// @Override
// protected Observable<Optional<Date>> buildUseCaseObservable() {
// return Observable.just(mPreferencesData.getCurrenciesExchangeDate());
//
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
// public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
//
// private final CurrencyRepository mRepository;
// private final PreferencesData mPreferences;
//
// public GetCurrenciesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository,
// PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
// mPreferences = preferencesData;
// }
//
// @Override
// protected Observable<CurrencyData> buildUseCaseObservable(final CurrenciesParam params) {
// mPreferences.setCurrenciesExchangeDate(params.date);
// return mRepository.getCurrencies(params.date);
// }
//
// public static class CurrenciesParam {
// Date date;
//
// public CurrenciesParam(final Date date) {
// this.date = checkNotNull(date);
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyListViewModel.java
import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesRatesDate;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesUseCase;
import eu.rampsoftware.er.navigation.Navigator;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
package eu.rampsoftware.er.viewmodel.currencies;
public class CurrencyListViewModel extends BaseDisposableViewModel implements BaseViewModel {
private final GetCurrenciesUseCase mCurrenciesUseCase; | private final GetCurrenciesRatesDate mGetCurrenciesRatesDate; |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyListViewModel.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesRatesDate.java
// public class GetCurrenciesRatesDate extends NoArgQueryUseCase<Optional<Date>> {
// private final PreferencesData mPreferencesData;
//
// public GetCurrenciesRatesDate(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// final PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mPreferencesData = preferencesData;
// }
//
// @Override
// protected Observable<Optional<Date>> buildUseCaseObservable() {
// return Observable.just(mPreferencesData.getCurrenciesExchangeDate());
//
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
// public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
//
// private final CurrencyRepository mRepository;
// private final PreferencesData mPreferences;
//
// public GetCurrenciesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository,
// PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
// mPreferences = preferencesData;
// }
//
// @Override
// protected Observable<CurrencyData> buildUseCaseObservable(final CurrenciesParam params) {
// mPreferences.setCurrenciesExchangeDate(params.date);
// return mRepository.getCurrencies(params.date);
// }
//
// public static class CurrenciesParam {
// Date date;
//
// public CurrenciesParam(final Date date) {
// this.date = checkNotNull(date);
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
| import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesRatesDate;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesUseCase;
import eu.rampsoftware.er.navigation.Navigator;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | package eu.rampsoftware.er.viewmodel.currencies;
public class CurrencyListViewModel extends BaseDisposableViewModel implements BaseViewModel {
private final GetCurrenciesUseCase mCurrenciesUseCase;
private final GetCurrenciesRatesDate mGetCurrenciesRatesDate; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesRatesDate.java
// public class GetCurrenciesRatesDate extends NoArgQueryUseCase<Optional<Date>> {
// private final PreferencesData mPreferencesData;
//
// public GetCurrenciesRatesDate(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// final PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mPreferencesData = preferencesData;
// }
//
// @Override
// protected Observable<Optional<Date>> buildUseCaseObservable() {
// return Observable.just(mPreferencesData.getCurrenciesExchangeDate());
//
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
// public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
//
// private final CurrencyRepository mRepository;
// private final PreferencesData mPreferences;
//
// public GetCurrenciesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository,
// PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
// mPreferences = preferencesData;
// }
//
// @Override
// protected Observable<CurrencyData> buildUseCaseObservable(final CurrenciesParam params) {
// mPreferences.setCurrenciesExchangeDate(params.date);
// return mRepository.getCurrencies(params.date);
// }
//
// public static class CurrenciesParam {
// Date date;
//
// public CurrenciesParam(final Date date) {
// this.date = checkNotNull(date);
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyListViewModel.java
import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesRatesDate;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesUseCase;
import eu.rampsoftware.er.navigation.Navigator;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
package eu.rampsoftware.er.viewmodel.currencies;
public class CurrencyListViewModel extends BaseDisposableViewModel implements BaseViewModel {
private final GetCurrenciesUseCase mCurrenciesUseCase;
private final GetCurrenciesRatesDate mGetCurrenciesRatesDate; | private final Navigator mNavigator; |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyListViewModel.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesRatesDate.java
// public class GetCurrenciesRatesDate extends NoArgQueryUseCase<Optional<Date>> {
// private final PreferencesData mPreferencesData;
//
// public GetCurrenciesRatesDate(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// final PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mPreferencesData = preferencesData;
// }
//
// @Override
// protected Observable<Optional<Date>> buildUseCaseObservable() {
// return Observable.just(mPreferencesData.getCurrenciesExchangeDate());
//
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
// public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
//
// private final CurrencyRepository mRepository;
// private final PreferencesData mPreferences;
//
// public GetCurrenciesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository,
// PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
// mPreferences = preferencesData;
// }
//
// @Override
// protected Observable<CurrencyData> buildUseCaseObservable(final CurrenciesParam params) {
// mPreferences.setCurrenciesExchangeDate(params.date);
// return mRepository.getCurrencies(params.date);
// }
//
// public static class CurrenciesParam {
// Date date;
//
// public CurrenciesParam(final Date date) {
// this.date = checkNotNull(date);
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
| import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesRatesDate;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesUseCase;
import eu.rampsoftware.er.navigation.Navigator;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | notifyPropertyChanged(BR.progressVisible);
}
@Bindable
public ObservableList<CurrencyItemViewModel> getCurrencies() {
return mCurrencies;
}
@Override
public void onLoad(final Bundle bundle) {
setProgressVisible(true);
addDisposable(
mGetCurrenciesRatesDate.run()
.doOnError(throwable -> setProgressVisible(false))
.subscribe(dateOptional -> {
mReadDate = dateOptional.or(mReadDate);
onDate(mReadDate);
})
);
}
private void onDate(final Date date) {
addDisposable(
mCurrenciesUseCase.run(new GetCurrenciesUseCase.CurrenciesParam(date))
.doFinally(() -> setProgressVisible(false))
.subscribe(this::onCurrencyDataLoaded)
);
}
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesRatesDate.java
// public class GetCurrenciesRatesDate extends NoArgQueryUseCase<Optional<Date>> {
// private final PreferencesData mPreferencesData;
//
// public GetCurrenciesRatesDate(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// final PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mPreferencesData = preferencesData;
// }
//
// @Override
// protected Observable<Optional<Date>> buildUseCaseObservable() {
// return Observable.just(mPreferencesData.getCurrenciesExchangeDate());
//
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
// public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
//
// private final CurrencyRepository mRepository;
// private final PreferencesData mPreferences;
//
// public GetCurrenciesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository,
// PreferencesData preferencesData) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
// mPreferences = preferencesData;
// }
//
// @Override
// protected Observable<CurrencyData> buildUseCaseObservable(final CurrenciesParam params) {
// mPreferences.setCurrenciesExchangeDate(params.date);
// return mRepository.getCurrencies(params.date);
// }
//
// public static class CurrenciesParam {
// Date date;
//
// public CurrenciesParam(final Date date) {
// this.date = checkNotNull(date);
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyListViewModel.java
import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesRatesDate;
import eu.rampsoftware.er.domain.usecases.GetCurrenciesUseCase;
import eu.rampsoftware.er.navigation.Navigator;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
notifyPropertyChanged(BR.progressVisible);
}
@Bindable
public ObservableList<CurrencyItemViewModel> getCurrencies() {
return mCurrencies;
}
@Override
public void onLoad(final Bundle bundle) {
setProgressVisible(true);
addDisposable(
mGetCurrenciesRatesDate.run()
.doOnError(throwable -> setProgressVisible(false))
.subscribe(dateOptional -> {
mReadDate = dateOptional.or(mReadDate);
onDate(mReadDate);
})
);
}
private void onDate(final Date date) {
addDisposable(
mCurrenciesUseCase.run(new GetCurrenciesUseCase.CurrenciesParam(date))
.doFinally(() -> setProgressVisible(false))
.subscribe(this::onCurrencyDataLoaded)
);
}
| private void onCurrencyDataLoaded(final CurrencyData currencyData) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/ExchangeRatesApplication.java | // Path: presentation/src/main/java/eu/rampsoftware/er/di/ApplicationComponent.java
// @Component(modules = {ApplicationModule.class, NetModule.class})
// @Singleton
// public interface ApplicationComponent {
// /**
// * Creates new instance of CurrenciesActivitySubComponent {@link dagger.Subcomponent Subcomponent}.
// *
// * @param module
// * @return
// */
// CurrenciesActivitySubComponent newCurrenciesActivitySubComponent(CurrenciesActivityModule module);
// CurrencyDetailsActivitySubComponent newCurrencyDetailsActivitySubComponent(CurrencyDetailsActivityModule module);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/di/ApplicationModule.java
// @Module
// public class ApplicationModule implements IApplicationModule {
//
// private final Context mContext;
//
// public ApplicationModule(Context context){
// mContext = context;
// }
//
// @Override
// @Provides
// @Named("example")
// @Singleton
// public String provideExampleString() {
// return "Production Example";
// }
//
// @Override
// @Provides
// @Singleton
// public Context provideContext(){
// return mContext;
// }
//
// @Override
// @Provides
// @Singleton
// public ApplicationProperties provideApplicationProperties(final Context context){
// return new ResourcesApplicationProperties(context);
// }
//
// @Override
// @Provides
// @Singleton
// @Named("remote")
// public CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, final CurrencyDataApi currencyDataApi){
// return new RetrofitCurrencyDataSource(currencyDataApi, properties.getOerAppId());
// }
//
// @Override
// @Provides
// @Singleton
// @Named("local")
// public CurrencyDataSource provideLocalCurrencyDataSource(){
// return new DatabaseCurrencyDataSource();
// }
//
// @Override
// @Provides
// @Singleton
// public CurrencyRepository provideCurrencyRepository(@Named("local") final CurrencyDataSource localSource,
// @Named("remote") final CurrencyDataSource remoteSource){
// return new CachingCurrencyRepository(localSource, remoteSource);
// }
//
// @Provides
// @Singleton
// @Override
// public PreferencesData providePreferencesData(ApplicationProperties properties){
// return new SharedPreferencesData(mContext.getSharedPreferences(
// properties.sharedPreferencesName(), Context.MODE_PRIVATE));
// }
// }
| import android.app.Application;
import eu.rampsoftware.er.di.ApplicationComponent;
import eu.rampsoftware.er.di.ApplicationModule;
import eu.rampsoftware.er.di.DaggerApplicationComponent;
import io.realm.Realm; | package eu.rampsoftware.er;
public class ExchangeRatesApplication extends Application {
private ApplicationComponent mApplicationComponent;
@Override
public void onCreate() {
super.onCreate();
initRealm();
mApplicationComponent = DaggerApplicationComponent.builder() | // Path: presentation/src/main/java/eu/rampsoftware/er/di/ApplicationComponent.java
// @Component(modules = {ApplicationModule.class, NetModule.class})
// @Singleton
// public interface ApplicationComponent {
// /**
// * Creates new instance of CurrenciesActivitySubComponent {@link dagger.Subcomponent Subcomponent}.
// *
// * @param module
// * @return
// */
// CurrenciesActivitySubComponent newCurrenciesActivitySubComponent(CurrenciesActivityModule module);
// CurrencyDetailsActivitySubComponent newCurrencyDetailsActivitySubComponent(CurrencyDetailsActivityModule module);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/di/ApplicationModule.java
// @Module
// public class ApplicationModule implements IApplicationModule {
//
// private final Context mContext;
//
// public ApplicationModule(Context context){
// mContext = context;
// }
//
// @Override
// @Provides
// @Named("example")
// @Singleton
// public String provideExampleString() {
// return "Production Example";
// }
//
// @Override
// @Provides
// @Singleton
// public Context provideContext(){
// return mContext;
// }
//
// @Override
// @Provides
// @Singleton
// public ApplicationProperties provideApplicationProperties(final Context context){
// return new ResourcesApplicationProperties(context);
// }
//
// @Override
// @Provides
// @Singleton
// @Named("remote")
// public CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, final CurrencyDataApi currencyDataApi){
// return new RetrofitCurrencyDataSource(currencyDataApi, properties.getOerAppId());
// }
//
// @Override
// @Provides
// @Singleton
// @Named("local")
// public CurrencyDataSource provideLocalCurrencyDataSource(){
// return new DatabaseCurrencyDataSource();
// }
//
// @Override
// @Provides
// @Singleton
// public CurrencyRepository provideCurrencyRepository(@Named("local") final CurrencyDataSource localSource,
// @Named("remote") final CurrencyDataSource remoteSource){
// return new CachingCurrencyRepository(localSource, remoteSource);
// }
//
// @Provides
// @Singleton
// @Override
// public PreferencesData providePreferencesData(ApplicationProperties properties){
// return new SharedPreferencesData(mContext.getSharedPreferences(
// properties.sharedPreferencesName(), Context.MODE_PRIVATE));
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/ExchangeRatesApplication.java
import android.app.Application;
import eu.rampsoftware.er.di.ApplicationComponent;
import eu.rampsoftware.er.di.ApplicationModule;
import eu.rampsoftware.er.di.DaggerApplicationComponent;
import io.realm.Realm;
package eu.rampsoftware.er;
public class ExchangeRatesApplication extends Application {
private ApplicationComponent mApplicationComponent;
@Override
public void onCreate() {
super.onCreate();
initRealm();
mApplicationComponent = DaggerApplicationComponent.builder() | .applicationModule(new ApplicationModule(this)) |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivitySubComponent.java | // Path: presentation/src/main/java/eu/rampsoftware/er/view/currencies/CurrencyDetailsActivity.java
// public class CurrencyDetailsActivity extends BaseActivity<CurrencyDetailsActivitySubComponent> {
//
// private static final String INTENT_EXTRA_PARAM_CURRENCY_CODE = "INTENT_EXTRA_PARAM_CURRENCY_CODE";
// @Inject
// CurrencyDetailsViewModel mViewModel;
//
// public static Intent getCallingIntent(final Context context, final String currencyCode) {
// Intent callingIntent = new Intent(context, CurrencyDetailsActivity.class);
// callingIntent.putExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE, currencyCode);
// return callingIntent;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currency_details);
// binding.setVariable(BR.model, mViewModel);
// if (!isRetained(savedInstanceState)) {
// final String currencyCode = getIntent().getStringExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE);
// Bundle bundle = new Bundle();
// bundle.putString(CurrencyDetailsViewModel.KEY_CURRENCY_CODE, currencyCode);
// mViewModel.onLoad(bundle);
// }
// }
//
// @Override
// protected void onDestroy() {
// if(!isChangingConfigurations()) {
// mViewModel.dispose();
// }
// super.onDestroy();
// }
//
// @Override
// protected void injectDependencies(final CurrencyDetailsActivitySubComponent activityComponent) {
// activityComponent.inject(this);
// }
//
// protected CurrencyDetailsActivitySubComponent newComponent() {
// return ((ExchangeRatesApplication) getApplication())
// .getApplicationComponent()
// .newCurrencyDetailsActivitySubComponent(new CurrencyDetailsActivityModule(this));
// }
// }
| import dagger.Subcomponent;
import eu.rampsoftware.er.view.currencies.CurrencyDetailsActivity; | package eu.rampsoftware.er.di;
/**
* Subcomponent of the dependency graph.
* Subcomponents have their own life-cycle and can be garbage collected when all references to the subcomponent are gone.
*/
@CurrencyDetailsActivityScope
@Subcomponent(modules = {CurrencyDetailsActivityModule.class})
public interface CurrencyDetailsActivitySubComponent {
| // Path: presentation/src/main/java/eu/rampsoftware/er/view/currencies/CurrencyDetailsActivity.java
// public class CurrencyDetailsActivity extends BaseActivity<CurrencyDetailsActivitySubComponent> {
//
// private static final String INTENT_EXTRA_PARAM_CURRENCY_CODE = "INTENT_EXTRA_PARAM_CURRENCY_CODE";
// @Inject
// CurrencyDetailsViewModel mViewModel;
//
// public static Intent getCallingIntent(final Context context, final String currencyCode) {
// Intent callingIntent = new Intent(context, CurrencyDetailsActivity.class);
// callingIntent.putExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE, currencyCode);
// return callingIntent;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currency_details);
// binding.setVariable(BR.model, mViewModel);
// if (!isRetained(savedInstanceState)) {
// final String currencyCode = getIntent().getStringExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE);
// Bundle bundle = new Bundle();
// bundle.putString(CurrencyDetailsViewModel.KEY_CURRENCY_CODE, currencyCode);
// mViewModel.onLoad(bundle);
// }
// }
//
// @Override
// protected void onDestroy() {
// if(!isChangingConfigurations()) {
// mViewModel.dispose();
// }
// super.onDestroy();
// }
//
// @Override
// protected void injectDependencies(final CurrencyDetailsActivitySubComponent activityComponent) {
// activityComponent.inject(this);
// }
//
// protected CurrencyDetailsActivitySubComponent newComponent() {
// return ((ExchangeRatesApplication) getApplication())
// .getApplicationComponent()
// .newCurrencyDetailsActivitySubComponent(new CurrencyDetailsActivityModule(this));
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/CurrencyDetailsActivitySubComponent.java
import dagger.Subcomponent;
import eu.rampsoftware.er.view.currencies.CurrencyDetailsActivity;
package eu.rampsoftware.er.di;
/**
* Subcomponent of the dependency graph.
* Subcomponents have their own life-cycle and can be garbage collected when all references to the subcomponent are gone.
*/
@CurrencyDetailsActivityScope
@Subcomponent(modules = {CurrencyDetailsActivityModule.class})
public interface CurrencyDetailsActivitySubComponent {
| void inject(CurrencyDetailsActivity activity); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyItemViewModel.java | // Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
| import android.databinding.BaseObservable;
import android.databinding.Bindable;
import java.util.Locale;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.navigation.Navigator;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | package eu.rampsoftware.er.viewmodel.currencies;
public class CurrencyItemViewModel extends BaseObservable {
private final String mCurrencyCode;
private final String mCurrencyValue; | // Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
// public class Navigator {
//
// private Activity mContext;
//
// public Navigator(final Activity context) {
// mContext = context;
// }
//
// public void navigateToCurrencyDetails(final String currencyCode) {
// Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode);
// mContext.startActivity(intentToLaunch);
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/currencies/CurrencyItemViewModel.java
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import java.util.Locale;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.navigation.Navigator;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
package eu.rampsoftware.er.viewmodel.currencies;
public class CurrencyItemViewModel extends BaseObservable {
private final String mCurrencyCode;
private final String mCurrencyValue; | private final Navigator mNavigator; |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/CurrenciesActivitySubComponent.java | // Path: presentation/src/main/java/eu/rampsoftware/er/view/currencies/CurrenciesActivity.java
// public class CurrenciesActivity extends BaseActivity<CurrenciesActivitySubComponent> {
//
// @Inject
// CurrencyListViewModel mViewModel;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currencies);
// binding.setVariable(BR.model, mViewModel);
// if (!isRetained(savedInstanceState)) {
// mViewModel.onLoad(null);
// }
// }
//
// @Override
// protected void onDestroy() {
// if(!isChangingConfigurations()) {
// mViewModel.dispose();
// }
// super.onDestroy();
// }
//
// @Override
// protected void injectDependencies(final CurrenciesActivitySubComponent activityComponent) {
// activityComponent.inject(this);
// }
//
// protected CurrenciesActivitySubComponent newComponent() {
// return ((ExchangeRatesApplication) getApplication())
// .getApplicationComponent()
// .newCurrenciesActivitySubComponent(new CurrenciesActivityModule(this));
// }
//
// }
| import dagger.Subcomponent;
import eu.rampsoftware.er.view.currencies.CurrenciesActivity; | package eu.rampsoftware.er.di;
/**
* Subcomponent of the dependency graph.
* Subcomponents have their own life-cycle and can be garbage collected when all references to the subcomponent are gone.
*/
@CurrenciesActivityScope
@Subcomponent(modules={ CurrenciesActivityModule.class })
public interface CurrenciesActivitySubComponent {
| // Path: presentation/src/main/java/eu/rampsoftware/er/view/currencies/CurrenciesActivity.java
// public class CurrenciesActivity extends BaseActivity<CurrenciesActivitySubComponent> {
//
// @Inject
// CurrencyListViewModel mViewModel;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currencies);
// binding.setVariable(BR.model, mViewModel);
// if (!isRetained(savedInstanceState)) {
// mViewModel.onLoad(null);
// }
// }
//
// @Override
// protected void onDestroy() {
// if(!isChangingConfigurations()) {
// mViewModel.dispose();
// }
// super.onDestroy();
// }
//
// @Override
// protected void injectDependencies(final CurrenciesActivitySubComponent activityComponent) {
// activityComponent.inject(this);
// }
//
// protected CurrenciesActivitySubComponent newComponent() {
// return ((ExchangeRatesApplication) getApplication())
// .getApplicationComponent()
// .newCurrenciesActivitySubComponent(new CurrenciesActivityModule(this));
// }
//
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/CurrenciesActivitySubComponent.java
import dagger.Subcomponent;
import eu.rampsoftware.er.view.currencies.CurrenciesActivity;
package eu.rampsoftware.er.di;
/**
* Subcomponent of the dependency graph.
* Subcomponents have their own life-cycle and can be garbage collected when all references to the subcomponent are gone.
*/
@CurrenciesActivityScope
@Subcomponent(modules={ CurrenciesActivityModule.class })
public interface CurrenciesActivitySubComponent {
| void inject(CurrenciesActivity currenciesActivity); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/NetModule.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; | package eu.rampsoftware.er.di;
@Module
public class NetModule implements INetModule{
@Override
@Provides
@Singleton
public Gson provideGson() {
return new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.create();
}
@Override
@Provides
@Singleton | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/NetModule.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
package eu.rampsoftware.er.di;
@Module
public class NetModule implements INetModule{
@Override
@Provides
@Singleton
public Gson provideGson() {
return new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.create();
}
@Override
@Provides
@Singleton | public OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/NetModule.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; | public OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
if (propertiesManager.logsEnabled()) {
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
}
return new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
}
@Override
@Provides
@Singleton
public Retrofit provideRetrofit(Gson gson, ApplicationProperties propertiesManager, OkHttpClient client) {
return new Retrofit.Builder()
.baseUrl(propertiesManager.baseUrl())
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(client)
.build();
}
@Override
@Provides
@Singleton | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/NetModule.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
if (propertiesManager.logsEnabled()) {
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
}
return new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
}
@Override
@Provides
@Singleton
public Retrofit provideRetrofit(Gson gson, ApplicationProperties propertiesManager, OkHttpClient client) {
return new Retrofit.Builder()
.baseUrl(propertiesManager.baseUrl())
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(client)
.build();
}
@Override
@Provides
@Singleton | public CurrencyDataApi provideCurrencyDataApi(Retrofit retrofit){ |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
| import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight; | package eu.rampsoftware.er.data.datasource.local;
public class DatabaseCurrencyDataSource extends RealmManagerBase implements CurrencyDataSource {
public DatabaseCurrencyDataSource() {
super();
}
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java
import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight;
package eu.rampsoftware.er.data.datasource.local;
public class DatabaseCurrencyDataSource extends RealmManagerBase implements CurrencyDataSource {
public DatabaseCurrencyDataSource() {
super();
}
@Override | public Observable<CurrencyData> getCurrencies(final Date date) { |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
| import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight; | package eu.rampsoftware.er.data.datasource.local;
public class DatabaseCurrencyDataSource extends RealmManagerBase implements CurrencyDataSource {
public DatabaseCurrencyDataSource() {
super();
}
@Override
public Observable<CurrencyData> getCurrencies(final Date date) {
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java
import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight;
package eu.rampsoftware.er.data.datasource.local;
public class DatabaseCurrencyDataSource extends RealmManagerBase implements CurrencyDataSource {
public DatabaseCurrencyDataSource() {
super();
}
@Override
public Observable<CurrencyData> getCurrencies(final Date date) {
| final long midnight = midnight(date.getTime()); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
| import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight; | package eu.rampsoftware.er.data.datasource.local;
public class DatabaseCurrencyDataSource extends RealmManagerBase implements CurrencyDataSource {
public DatabaseCurrencyDataSource() {
super();
}
@Override
public Observable<CurrencyData> getCurrencies(final Date date) {
final long midnight = midnight(date.getTime());
return readFromRealm((realm, emitter) -> { | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java
import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight;
package eu.rampsoftware.er.data.datasource.local;
public class DatabaseCurrencyDataSource extends RealmManagerBase implements CurrencyDataSource {
public DatabaseCurrencyDataSource() {
super();
}
@Override
public Observable<CurrencyData> getCurrencies(final Date date) {
final long midnight = midnight(date.getTime());
return readFromRealm((realm, emitter) -> { | final RealmResults<ValueEntity> items = realm.where(ValueEntity.class) |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
| import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight; | }
Map<String, Double> currencies = new HashMap<>();
for (ValueEntity item : items) {
currencies.put(item.getCode(), item.getValue());
}
emitter.onNext(new CurrencyData(new Date(midnight), currencies, ""));
emitter.onComplete();
});
}
@Override
public boolean containsCurrencyValue(final Date date, final String currencyCode) {
final long midnight = midnight(date.getTime());
return readFromRealmSync((realm) -> {
final RealmQuery<ValueEntity> query = realm.where(ValueEntity.class)
.equalTo(ValueEntity.TIMESTAMP, midnight);
if (!TextUtils.isEmpty(currencyCode)) {
query.equalTo(ValueEntity.CODE, currencyCode);
}
final long etriesCount = query.count();
return etriesCount != 0;
});
}
@Override
public boolean containsCurrencyValues(final Date date) {
return containsCurrencyValue(date, null);
}
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/model/ValueEntity.java
// public class ValueEntity extends RealmObject {
//
// public static final String TIMESTAMP = "timestamp";
// public static final String CODE = "code";
// private Double value;
// private long timestamp;
// private String code;
//
// public ValueEntity(){}
// public ValueEntity(final Double value, final long timestamp, final String currencyCode) {
// this.value = value;
// this.timestamp = timestamp;
// this.code = currencyCode;
// }
//
// public Double getValue() {
// return value;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public String getCode() {
// return code;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/utils/DateUtils.java
// public static long midnight(final long timestamp) {
// return (timestamp / DAY_MILLIS) * DAY_MILLIS;
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/local/DatabaseCurrencyDataSource.java
import android.text.TextUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.local.model.ValueEntity;
import io.reactivex.Observable;
import io.realm.RealmQuery;
import io.realm.RealmResults;
import static eu.rampsoftware.er.data.utils.DateUtils.midnight;
}
Map<String, Double> currencies = new HashMap<>();
for (ValueEntity item : items) {
currencies.put(item.getCode(), item.getValue());
}
emitter.onNext(new CurrencyData(new Date(midnight), currencies, ""));
emitter.onComplete();
});
}
@Override
public boolean containsCurrencyValue(final Date date, final String currencyCode) {
final long midnight = midnight(date.getTime());
return readFromRealmSync((realm) -> {
final RealmQuery<ValueEntity> query = realm.where(ValueEntity.class)
.equalTo(ValueEntity.TIMESTAMP, midnight);
if (!TextUtils.isEmpty(currencyCode)) {
query.equalTo(ValueEntity.CODE, currencyCode);
}
final long etriesCount = query.count();
return etriesCount != 0;
});
}
@Override
public boolean containsCurrencyValues(final Date date) {
return containsCurrencyValue(date, null);
}
@Override | public Observable<SingleValue> getCurrencyValues(final Date startDate, final Date endDate, final String currencyCode) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/ICurrencyDetailsActivityModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
| import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel; | package eu.rampsoftware.er.di;
interface ICurrencyDetailsActivityModule {
GetCurrencySeriesUseCase provideGetCurrenciesUseCase(CurrencyRepository currencyRepository);
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
// public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
//
// public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
// private GetCurrencySeriesUseCase mGetSeriesUseCase;
// private boolean mIsProgressVisible;
// private List<SingleValue> mCurrencySeries;
// private String mCurrencyCode;
//
// public CurrencyDetailsViewModel(final GetCurrencySeriesUseCase getSeriesUseCase) {
// mGetSeriesUseCase = getSeriesUseCase;
// mCurrencySeries = new ArrayList<>();
// }
//
// @Bindable
// public String getCurrencyCode() {
// return mCurrencyCode;
// }
//
// public void setCurrencyCode(final String currencyCode) {
// mCurrencyCode = currencyCode;
// notifyPropertyChanged(BR.currencyCode);
// }
//
// @Bindable
// public List<SingleValue> getCurrencySeries() {
// return mCurrencySeries;
// }
//
// @Override
// public void onLoad(final Bundle bundle) {
// checkNotNull(bundle);
// checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
// setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
// performRequest();
// }
//
// @Bindable
// public boolean isProgressVisible() {
// return mIsProgressVisible;
// }
//
// public void setProgressVisible(final boolean progressVisible) {
// mIsProgressVisible = progressVisible;
// notifyPropertyChanged(BR.progressVisible);
// }
//
// public void performRefresh() {
// performRequest();
// }
//
// private void performRequest() {
// setProgressVisible(true);
// Date endDate = new Date();
// int daysRange = 10;
// mCurrencySeries.clear();
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(endDate);
// calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
// Date from = calendar.getTime();
// CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode);
// addDisposable(
// mGetSeriesUseCase.run(params)
// .doFinally(() -> {
// setProgressVisible(false);
// notifyPropertyChanged(BR.currencySeries);
// })
// .subscribe(currencyData -> {
// mCurrencySeries.add(currencyData);
// })
// );
// }
//
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/ICurrencyDetailsActivityModule.java
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.details.CurrencyDetailsViewModel;
package eu.rampsoftware.er.di;
interface ICurrencyDetailsActivityModule {
GetCurrencySeriesUseCase provideGetCurrenciesUseCase(CurrencyRepository currencyRepository);
| CurrencyDetailsViewModel provideCurrencyDetailsViewModel(GetCurrencySeriesUseCase getSeriesUseCase); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
| import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers; | package eu.rampsoftware.er.data.repository;
public class CachingCurrencyRepository implements CurrencyRepository {
private CurrencyDataSource mLocalSource;
private CurrencyDataSource mRemoteSource;
public CachingCurrencyRepository(final CurrencyDataSource localSource,
final CurrencyDataSource remoteSource) {
mLocalSource = localSource;
mRemoteSource = remoteSource;
}
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
package eu.rampsoftware.er.data.repository;
public class CachingCurrencyRepository implements CurrencyRepository {
private CurrencyDataSource mLocalSource;
private CurrencyDataSource mRemoteSource;
public CachingCurrencyRepository(final CurrencyDataSource localSource,
final CurrencyDataSource remoteSource) {
mLocalSource = localSource;
mRemoteSource = remoteSource;
}
@Override | public Observable<CurrencyData> getCurrencies(final Date date) { |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
| import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers; | package eu.rampsoftware.er.data.repository;
public class CachingCurrencyRepository implements CurrencyRepository {
private CurrencyDataSource mLocalSource;
private CurrencyDataSource mRemoteSource;
public CachingCurrencyRepository(final CurrencyDataSource localSource,
final CurrencyDataSource remoteSource) {
mLocalSource = localSource;
mRemoteSource = remoteSource;
}
@Override
public Observable<CurrencyData> getCurrencies(final Date date) {
if (mLocalSource.containsCurrencyValues(date)) {
return mLocalSource.getCurrencies(date);
}
final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
return remoteCurrencies;
}
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
package eu.rampsoftware.er.data.repository;
public class CachingCurrencyRepository implements CurrencyRepository {
private CurrencyDataSource mLocalSource;
private CurrencyDataSource mRemoteSource;
public CachingCurrencyRepository(final CurrencyDataSource localSource,
final CurrencyDataSource remoteSource) {
mLocalSource = localSource;
mRemoteSource = remoteSource;
}
@Override
public Observable<CurrencyData> getCurrencies(final Date date) {
if (mLocalSource.containsCurrencyValues(date)) {
return mLocalSource.getCurrencies(date);
}
final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
return remoteCurrencies;
}
@Override | public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) { |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
| import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties; | package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties;
package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton | public ApplicationProperties provideApplicationProperties(final Context context){ |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
| import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties; | package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){ | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties;
package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){ | return new ResourcesApplicationProperties(context); |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
| import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties; | package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote") | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties;
package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote") | public CurrencyDataSource provideRemoteCurrencyDataSource(final ApplicationProperties properties, final CurrencyDataApi currencyDataApi) { |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
| import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties; | package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote") | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties;
package eu.rampsoftware.er.di;
@Module
public class TestApplicationModule implements IApplicationModule{
private final Context mContext;
public TestApplicationModule(Context context){
mContext = context;
}
@Provides
@Named("example")
public String provideExampleString() {
return "Test Example";
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote") | public CurrencyDataSource provideRemoteCurrencyDataSource(final ApplicationProperties properties, final CurrencyDataApi currencyDataApi) { |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
| import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties; | }
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote")
public CurrencyDataSource provideRemoteCurrencyDataSource(final ApplicationProperties properties, final CurrencyDataApi currencyDataApi) {
return null;
}
@Provides
@Override
@Named("local")
public CurrencyDataSource provideLocalCurrencyDataSource() {
return null;
}
@Provides
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties;
}
@Provides
@Singleton
public Context provideContext(){
return mContext;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote")
public CurrencyDataSource provideRemoteCurrencyDataSource(final ApplicationProperties properties, final CurrencyDataApi currencyDataApi) {
return null;
}
@Provides
@Override
@Named("local")
public CurrencyDataSource provideLocalCurrencyDataSource() {
return null;
}
@Provides
@Override | public CurrencyRepository provideCurrencyRepository(@Named("local") final CurrencyDataSource localSource, @Named("remote") final CurrencyDataSource remoteSource) { |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
| import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties; | }
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote")
public CurrencyDataSource provideRemoteCurrencyDataSource(final ApplicationProperties properties, final CurrencyDataApi currencyDataApi) {
return null;
}
@Provides
@Override
@Named("local")
public CurrencyDataSource provideLocalCurrencyDataSource() {
return null;
}
@Provides
@Override
public CurrencyRepository provideCurrencyRepository(@Named("local") final CurrencyDataSource localSource, @Named("remote") final CurrencyDataSource remoteSource) {
return null;
}
@Override
@Provides | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ResourcesApplicationProperties.java
// public class ResourcesApplicationProperties implements ApplicationProperties {
//
// private final Context mContext;
//
// public ResourcesApplicationProperties(Context context){
// mContext = context;
// }
//
//
// @Override
// public String baseUrl(){
// return mContext.getResources().getString(R.string.base_url);
// }
//
// @Override
// public boolean logsEnabled() {
// return mContext.getResources().getBoolean(R.bool.logs_enabled);
// }
//
// @Override
// public String getOerAppId() {
// return mContext.getString(R.string.oer_app_id);
// }
//
// @Override
// public String sharedPreferencesName() {
// return mContext.getResources().getString(R.string.shared_preferences_name);
// }
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import eu.rampsoftware.er.properties.ResourcesApplicationProperties;
}
@Provides
@Singleton
public ApplicationProperties provideApplicationProperties(final Context context){
return new ResourcesApplicationProperties(context);
}
@Provides
@Override
@Named("remote")
public CurrencyDataSource provideRemoteCurrencyDataSource(final ApplicationProperties properties, final CurrencyDataApi currencyDataApi) {
return null;
}
@Provides
@Override
@Named("local")
public CurrencyDataSource provideLocalCurrencyDataSource() {
return null;
}
@Provides
@Override
public CurrencyRepository provideCurrencyRepository(@Named("local") final CurrencyDataSource localSource, @Named("remote") final CurrencyDataSource remoteSource) {
return null;
}
@Override
@Provides | public PreferencesData providePreferencesData(final ApplicationProperties properties) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/INetModule.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import com.google.gson.Gson;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit; | package eu.rampsoftware.er.di;
interface INetModule {
Gson provideGson();
| // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/INetModule.java
import com.google.gson.Gson;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
package eu.rampsoftware.er.di;
interface INetModule {
Gson provideGson();
| OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/INetModule.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import com.google.gson.Gson;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit; | package eu.rampsoftware.er.di;
interface INetModule {
Gson provideGson();
OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager);
Retrofit provideRetrofit(Gson gson, ApplicationProperties propertiesManager, OkHttpClient client);
| // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/INetModule.java
import com.google.gson.Gson;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
package eu.rampsoftware.er.di;
interface INetModule {
Gson provideGson();
OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager);
Retrofit provideRetrofit(Gson gson, ApplicationProperties propertiesManager, OkHttpClient client);
| CurrencyDataApi provideCurrencyDataApi(Retrofit retrofit); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
| import java.util.Date;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import io.reactivex.Observable; | package eu.rampsoftware.er.data.datasource;
public interface CurrencyDataSource {
Observable<CurrencyData> getCurrencies(Date date);
boolean containsCurrencyValue(Date date, String currencyCode);
boolean containsCurrencyValues(Date date);
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import io.reactivex.Observable;
package eu.rampsoftware.er.data.datasource;
public interface CurrencyDataSource {
Observable<CurrencyData> getCurrencies(Date date);
boolean containsCurrencyValue(Date date, String currencyCode);
boolean containsCurrencyValues(Date date);
| Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode); |
krokers/exchange-rates-mvvm | data/src/test/java/eu/rampsoftware/er/data/data/CachingCurrencyRepositoryTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
// public class CachingCurrencyRepository implements CurrencyRepository {
// private CurrencyDataSource mLocalSource;
// private CurrencyDataSource mRemoteSource;
//
// public CachingCurrencyRepository(final CurrencyDataSource localSource,
// final CurrencyDataSource remoteSource) {
// mLocalSource = localSource;
// mRemoteSource = remoteSource;
// }
//
// @Override
// public Observable<CurrencyData> getCurrencies(final Date date) {
// if (mLocalSource.containsCurrencyValues(date)) {
// return mLocalSource.getCurrencies(date);
// }
// final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
// remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
// return remoteCurrencies;
// }
//
// @Override
// public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) {
// return Observable.create(emitter -> {
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(from);
//
// List<Observable<CurrencyData>> cloudRequestObservables = new ArrayList<>();
// while (true) {
// final Date date = calendar.getTime();
// if (!mLocalSource.containsCurrencyValue(date, currencyCode)) {
// cloudRequestObservables.add(
// mRemoteSource.getCurrencies(date)
// .doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData)));
// }
// calendar.add(Calendar.DAY_OF_YEAR, 1);
// if (calendar.getTimeInMillis() >= to.getTime()) {
// break;
// }
// }
// Observable.merge(cloudRequestObservables)
// .subscribeOn(Schedulers.io())
// .doOnComplete(() -> {
// mLocalSource.getCurrencyValues(from, to, currencyCode)
// .doOnNext(emitter::onNext)
// .doOnComplete(emitter::onComplete)
// .subscribe();
// }).subscribe();
// });
// }
// }
| import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.repository.CachingCurrencyRepository;
import io.reactivex.Observable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.data.data;
public class CachingCurrencyRepositoryTest {
public static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
public static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
public static final long MILLIS_DAY = 24 * 3600 * 1000;
@Mock | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
// public class CachingCurrencyRepository implements CurrencyRepository {
// private CurrencyDataSource mLocalSource;
// private CurrencyDataSource mRemoteSource;
//
// public CachingCurrencyRepository(final CurrencyDataSource localSource,
// final CurrencyDataSource remoteSource) {
// mLocalSource = localSource;
// mRemoteSource = remoteSource;
// }
//
// @Override
// public Observable<CurrencyData> getCurrencies(final Date date) {
// if (mLocalSource.containsCurrencyValues(date)) {
// return mLocalSource.getCurrencies(date);
// }
// final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
// remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
// return remoteCurrencies;
// }
//
// @Override
// public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) {
// return Observable.create(emitter -> {
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(from);
//
// List<Observable<CurrencyData>> cloudRequestObservables = new ArrayList<>();
// while (true) {
// final Date date = calendar.getTime();
// if (!mLocalSource.containsCurrencyValue(date, currencyCode)) {
// cloudRequestObservables.add(
// mRemoteSource.getCurrencies(date)
// .doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData)));
// }
// calendar.add(Calendar.DAY_OF_YEAR, 1);
// if (calendar.getTimeInMillis() >= to.getTime()) {
// break;
// }
// }
// Observable.merge(cloudRequestObservables)
// .subscribeOn(Schedulers.io())
// .doOnComplete(() -> {
// mLocalSource.getCurrencyValues(from, to, currencyCode)
// .doOnNext(emitter::onNext)
// .doOnComplete(emitter::onComplete)
// .subscribe();
// }).subscribe();
// });
// }
// }
// Path: data/src/test/java/eu/rampsoftware/er/data/data/CachingCurrencyRepositoryTest.java
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.repository.CachingCurrencyRepository;
import io.reactivex.Observable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.data.data;
public class CachingCurrencyRepositoryTest {
public static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
public static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
public static final long MILLIS_DAY = 24 * 3600 * 1000;
@Mock | CurrencyDataSource mLocalDataSource; |
krokers/exchange-rates-mvvm | data/src/test/java/eu/rampsoftware/er/data/data/CachingCurrencyRepositoryTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
// public class CachingCurrencyRepository implements CurrencyRepository {
// private CurrencyDataSource mLocalSource;
// private CurrencyDataSource mRemoteSource;
//
// public CachingCurrencyRepository(final CurrencyDataSource localSource,
// final CurrencyDataSource remoteSource) {
// mLocalSource = localSource;
// mRemoteSource = remoteSource;
// }
//
// @Override
// public Observable<CurrencyData> getCurrencies(final Date date) {
// if (mLocalSource.containsCurrencyValues(date)) {
// return mLocalSource.getCurrencies(date);
// }
// final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
// remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
// return remoteCurrencies;
// }
//
// @Override
// public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) {
// return Observable.create(emitter -> {
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(from);
//
// List<Observable<CurrencyData>> cloudRequestObservables = new ArrayList<>();
// while (true) {
// final Date date = calendar.getTime();
// if (!mLocalSource.containsCurrencyValue(date, currencyCode)) {
// cloudRequestObservables.add(
// mRemoteSource.getCurrencies(date)
// .doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData)));
// }
// calendar.add(Calendar.DAY_OF_YEAR, 1);
// if (calendar.getTimeInMillis() >= to.getTime()) {
// break;
// }
// }
// Observable.merge(cloudRequestObservables)
// .subscribeOn(Schedulers.io())
// .doOnComplete(() -> {
// mLocalSource.getCurrencyValues(from, to, currencyCode)
// .doOnNext(emitter::onNext)
// .doOnComplete(emitter::onComplete)
// .subscribe();
// }).subscribe();
// });
// }
// }
| import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.repository.CachingCurrencyRepository;
import io.reactivex.Observable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.data.data;
public class CachingCurrencyRepositoryTest {
public static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
public static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
public static final long MILLIS_DAY = 24 * 3600 * 1000;
@Mock
CurrencyDataSource mLocalDataSource;
@Mock
CurrencyDataSource mRemoteDataSource;
@Captor
ArgumentCaptor<Date> mDateCaptor;
@Captor | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
// public class CachingCurrencyRepository implements CurrencyRepository {
// private CurrencyDataSource mLocalSource;
// private CurrencyDataSource mRemoteSource;
//
// public CachingCurrencyRepository(final CurrencyDataSource localSource,
// final CurrencyDataSource remoteSource) {
// mLocalSource = localSource;
// mRemoteSource = remoteSource;
// }
//
// @Override
// public Observable<CurrencyData> getCurrencies(final Date date) {
// if (mLocalSource.containsCurrencyValues(date)) {
// return mLocalSource.getCurrencies(date);
// }
// final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
// remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
// return remoteCurrencies;
// }
//
// @Override
// public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) {
// return Observable.create(emitter -> {
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(from);
//
// List<Observable<CurrencyData>> cloudRequestObservables = new ArrayList<>();
// while (true) {
// final Date date = calendar.getTime();
// if (!mLocalSource.containsCurrencyValue(date, currencyCode)) {
// cloudRequestObservables.add(
// mRemoteSource.getCurrencies(date)
// .doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData)));
// }
// calendar.add(Calendar.DAY_OF_YEAR, 1);
// if (calendar.getTimeInMillis() >= to.getTime()) {
// break;
// }
// }
// Observable.merge(cloudRequestObservables)
// .subscribeOn(Schedulers.io())
// .doOnComplete(() -> {
// mLocalSource.getCurrencyValues(from, to, currencyCode)
// .doOnNext(emitter::onNext)
// .doOnComplete(emitter::onComplete)
// .subscribe();
// }).subscribe();
// });
// }
// }
// Path: data/src/test/java/eu/rampsoftware/er/data/data/CachingCurrencyRepositoryTest.java
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.repository.CachingCurrencyRepository;
import io.reactivex.Observable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.data.data;
public class CachingCurrencyRepositoryTest {
public static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
public static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
public static final long MILLIS_DAY = 24 * 3600 * 1000;
@Mock
CurrencyDataSource mLocalDataSource;
@Mock
CurrencyDataSource mRemoteDataSource;
@Captor
ArgumentCaptor<Date> mDateCaptor;
@Captor | ArgumentCaptor<CurrencyData> mCurrencyDataCaptor; |
krokers/exchange-rates-mvvm | data/src/test/java/eu/rampsoftware/er/data/data/CachingCurrencyRepositoryTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
// public class CachingCurrencyRepository implements CurrencyRepository {
// private CurrencyDataSource mLocalSource;
// private CurrencyDataSource mRemoteSource;
//
// public CachingCurrencyRepository(final CurrencyDataSource localSource,
// final CurrencyDataSource remoteSource) {
// mLocalSource = localSource;
// mRemoteSource = remoteSource;
// }
//
// @Override
// public Observable<CurrencyData> getCurrencies(final Date date) {
// if (mLocalSource.containsCurrencyValues(date)) {
// return mLocalSource.getCurrencies(date);
// }
// final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
// remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
// return remoteCurrencies;
// }
//
// @Override
// public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) {
// return Observable.create(emitter -> {
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(from);
//
// List<Observable<CurrencyData>> cloudRequestObservables = new ArrayList<>();
// while (true) {
// final Date date = calendar.getTime();
// if (!mLocalSource.containsCurrencyValue(date, currencyCode)) {
// cloudRequestObservables.add(
// mRemoteSource.getCurrencies(date)
// .doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData)));
// }
// calendar.add(Calendar.DAY_OF_YEAR, 1);
// if (calendar.getTimeInMillis() >= to.getTime()) {
// break;
// }
// }
// Observable.merge(cloudRequestObservables)
// .subscribeOn(Schedulers.io())
// .doOnComplete(() -> {
// mLocalSource.getCurrencyValues(from, to, currencyCode)
// .doOnNext(emitter::onNext)
// .doOnComplete(emitter::onComplete)
// .subscribe();
// }).subscribe();
// });
// }
// }
| import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.repository.CachingCurrencyRepository;
import io.reactivex.Observable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.data.data;
public class CachingCurrencyRepositoryTest {
public static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
public static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
public static final long MILLIS_DAY = 24 * 3600 * 1000;
@Mock
CurrencyDataSource mLocalDataSource;
@Mock
CurrencyDataSource mRemoteDataSource;
@Captor
ArgumentCaptor<Date> mDateCaptor;
@Captor
ArgumentCaptor<CurrencyData> mCurrencyDataCaptor;
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/repository/CachingCurrencyRepository.java
// public class CachingCurrencyRepository implements CurrencyRepository {
// private CurrencyDataSource mLocalSource;
// private CurrencyDataSource mRemoteSource;
//
// public CachingCurrencyRepository(final CurrencyDataSource localSource,
// final CurrencyDataSource remoteSource) {
// mLocalSource = localSource;
// mRemoteSource = remoteSource;
// }
//
// @Override
// public Observable<CurrencyData> getCurrencies(final Date date) {
// if (mLocalSource.containsCurrencyValues(date)) {
// return mLocalSource.getCurrencies(date);
// }
// final Observable<CurrencyData> remoteCurrencies = mRemoteSource.getCurrencies(date);
// remoteCurrencies.doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData));
// return remoteCurrencies;
// }
//
// @Override
// public Observable<SingleValue> getSeries(final Date from, final Date to, final String currencyCode) {
// return Observable.create(emitter -> {
// final Calendar calendar = Calendar.getInstance();
// calendar.setTime(from);
//
// List<Observable<CurrencyData>> cloudRequestObservables = new ArrayList<>();
// while (true) {
// final Date date = calendar.getTime();
// if (!mLocalSource.containsCurrencyValue(date, currencyCode)) {
// cloudRequestObservables.add(
// mRemoteSource.getCurrencies(date)
// .doOnNext(currencyData -> mLocalSource.storeCurrencies(currencyData)));
// }
// calendar.add(Calendar.DAY_OF_YEAR, 1);
// if (calendar.getTimeInMillis() >= to.getTime()) {
// break;
// }
// }
// Observable.merge(cloudRequestObservables)
// .subscribeOn(Schedulers.io())
// .doOnComplete(() -> {
// mLocalSource.getCurrencyValues(from, to, currencyCode)
// .doOnNext(emitter::onNext)
// .doOnComplete(emitter::onComplete)
// .subscribe();
// }).subscribe();
// });
// }
// }
// Path: data/src/test/java/eu/rampsoftware/er/data/data/CachingCurrencyRepositoryTest.java
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.repository.CachingCurrencyRepository;
import io.reactivex.Observable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.data.data;
public class CachingCurrencyRepositoryTest {
public static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
public static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
public static final long MILLIS_DAY = 24 * 3600 * 1000;
@Mock
CurrencyDataSource mLocalDataSource;
@Mock
CurrencyDataSource mRemoteDataSource;
@Captor
ArgumentCaptor<Date> mDateCaptor;
@Captor
ArgumentCaptor<CurrencyData> mCurrencyDataCaptor;
| private CachingCurrencyRepository mCurrencyRepository; |
krokers/exchange-rates-mvvm | domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/QueryUseCase.java
// public abstract class QueryUseCase<R, T> {
//
// private final Scheduler mWorkScheduler;
// private final Scheduler mObserveScheduler;
//
// protected QueryUseCase(Scheduler workScheduler, Scheduler observeScheduler) {
// this.mWorkScheduler = workScheduler;
// this.mObserveScheduler = observeScheduler;
// }
//
// public Observable<R> run(T params) {
// final Observable<R> observable = this.buildUseCaseObservable(params)
// .subscribeOn(mWorkScheduler)
// .observeOn(mObserveScheduler);
// return observable;
// }
//
// protected abstract Observable<R> buildUseCaseObservable(final T params);
//
//
// }
| import java.util.Date;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.domain.QueryUseCase;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull; | package eu.rampsoftware.er.domain.usecases;
public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
private final CurrencyRepository mRepository; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/QueryUseCase.java
// public abstract class QueryUseCase<R, T> {
//
// private final Scheduler mWorkScheduler;
// private final Scheduler mObserveScheduler;
//
// protected QueryUseCase(Scheduler workScheduler, Scheduler observeScheduler) {
// this.mWorkScheduler = workScheduler;
// this.mObserveScheduler = observeScheduler;
// }
//
// public Observable<R> run(T params) {
// final Observable<R> observable = this.buildUseCaseObservable(params)
// .subscribeOn(mWorkScheduler)
// .observeOn(mObserveScheduler);
// return observable;
// }
//
// protected abstract Observable<R> buildUseCaseObservable(final T params);
//
//
// }
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrenciesUseCase.java
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.domain.QueryUseCase;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
package eu.rampsoftware.er.domain.usecases;
public class GetCurrenciesUseCase extends QueryUseCase<CurrencyData, GetCurrenciesUseCase.CurrenciesParam> {
private final CurrencyRepository mRepository; | private final PreferencesData mPreferences; |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestNetModule.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import com.google.gson.Gson;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit; | package eu.rampsoftware.er.di;
@Module
class TestNetModule implements INetModule {
@Provides
@Override
public Gson provideGson() {
return null;
}
@Provides
@Override | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestNetModule.java
import com.google.gson.Gson;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
package eu.rampsoftware.er.di;
@Module
class TestNetModule implements INetModule {
@Provides
@Override
public Gson provideGson() {
return null;
}
@Provides
@Override | public OkHttpClient provideOkHttpClient(final ApplicationProperties propertiesManager) { |
krokers/exchange-rates-mvvm | presentation/src/test/java/eu/rampsoftware/er/di/TestNetModule.java | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import com.google.gson.Gson;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit; | package eu.rampsoftware.er.di;
@Module
class TestNetModule implements INetModule {
@Provides
@Override
public Gson provideGson() {
return null;
}
@Provides
@Override
public OkHttpClient provideOkHttpClient(final ApplicationProperties propertiesManager) {
return null;
}
@Provides
@Override
public Retrofit provideRetrofit(final Gson gson, final ApplicationProperties propertiesManager, final OkHttpClient client) {
return null;
}
@Provides
@Override | // Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/test/java/eu/rampsoftware/er/di/TestNetModule.java
import com.google.gson.Gson;
import dagger.Module;
import dagger.Provides;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
package eu.rampsoftware.er.di;
@Module
class TestNetModule implements INetModule {
@Provides
@Override
public Gson provideGson() {
return null;
}
@Provides
@Override
public OkHttpClient provideOkHttpClient(final ApplicationProperties propertiesManager) {
return null;
}
@Provides
@Override
public Retrofit provideRetrofit(final Gson gson, final ApplicationProperties propertiesManager, final OkHttpClient client) {
return null;
}
@Provides
@Override | public CurrencyDataApi provideCurrencyDataApi(final Retrofit retrofit) { |
krokers/exchange-rates-mvvm | domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock | CurrencyRepository mRepositoryMock; |
krokers/exchange-rates-mvvm | domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock
CurrencyRepository mRepositoryMock;
private GetCurrencySeriesUseCase mUseCase; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock
CurrencyRepository mRepositoryMock;
private GetCurrencySeriesUseCase mUseCase; | private TestDisposableObserver<SingleValue> mTestObserver; |
krokers/exchange-rates-mvvm | domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock
CurrencyRepository mRepositoryMock;
private GetCurrencySeriesUseCase mUseCase; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock
CurrencyRepository mRepositoryMock;
private GetCurrencySeriesUseCase mUseCase; | private TestDisposableObserver<SingleValue> mTestObserver; |
krokers/exchange-rates-mvvm | domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; | package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock
CurrencyRepository mRepositoryMock;
private GetCurrencySeriesUseCase mUseCase;
private TestDisposableObserver<SingleValue> mTestObserver;
@Before
public void setUp() {
initMocks(this);
this.mTestObserver = new TestDisposableObserver<>();
mUseCase = new GetCurrencySeriesUseCase(new TestScheduler(), new TestScheduler(), mRepositoryMock);
}
@Test()
public void thatPreconditionFailsIfDateRangeEmpty() {
exception.expect(InvalidParameterException.class); | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/test/java/eu/rampsoftware/er/domain/TestDisposableObserver.java
// public class TestDisposableObserver<T> extends DisposableObserver<T> {
// private int valuesCount = 0;
//
// @Override
// public void onNext(T value) {
// valuesCount++;
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onComplete() {
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: domain/src/test/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCaseTest.java
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import java.security.InvalidParameterException;
import java.util.Date;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.TestDisposableObserver;
import io.reactivex.Observable;
import io.reactivex.schedulers.TestScheduler;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
package eu.rampsoftware.er.domain.usecases;
public class GetCurrencySeriesUseCaseTest {
private static final long MILLIS_22_01_2016__10_00 = 1453453200000L;
private static final long MILLIS_24_01_2016__10_00 = 1453593600000L;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Mock
CurrencyRepository mRepositoryMock;
private GetCurrencySeriesUseCase mUseCase;
private TestDisposableObserver<SingleValue> mTestObserver;
@Before
public void setUp() {
initMocks(this);
this.mTestObserver = new TestDisposableObserver<>();
mUseCase = new GetCurrencySeriesUseCase(new TestScheduler(), new TestScheduler(), mRepositoryMock);
}
@Test()
public void thatPreconditionFailsIfDateRangeEmpty() {
exception.expect(InvalidParameterException.class); | new CurrencySeriesParam( |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java | // Path: presentation/src/main/java/eu/rampsoftware/er/view/currencies/CurrencyDetailsActivity.java
// public class CurrencyDetailsActivity extends BaseActivity<CurrencyDetailsActivitySubComponent> {
//
// private static final String INTENT_EXTRA_PARAM_CURRENCY_CODE = "INTENT_EXTRA_PARAM_CURRENCY_CODE";
// @Inject
// CurrencyDetailsViewModel mViewModel;
//
// public static Intent getCallingIntent(final Context context, final String currencyCode) {
// Intent callingIntent = new Intent(context, CurrencyDetailsActivity.class);
// callingIntent.putExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE, currencyCode);
// return callingIntent;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currency_details);
// binding.setVariable(BR.model, mViewModel);
// if (!isRetained(savedInstanceState)) {
// final String currencyCode = getIntent().getStringExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE);
// Bundle bundle = new Bundle();
// bundle.putString(CurrencyDetailsViewModel.KEY_CURRENCY_CODE, currencyCode);
// mViewModel.onLoad(bundle);
// }
// }
//
// @Override
// protected void onDestroy() {
// if(!isChangingConfigurations()) {
// mViewModel.dispose();
// }
// super.onDestroy();
// }
//
// @Override
// protected void injectDependencies(final CurrencyDetailsActivitySubComponent activityComponent) {
// activityComponent.inject(this);
// }
//
// protected CurrencyDetailsActivitySubComponent newComponent() {
// return ((ExchangeRatesApplication) getApplication())
// .getApplicationComponent()
// .newCurrencyDetailsActivitySubComponent(new CurrencyDetailsActivityModule(this));
// }
// }
| import android.app.Activity;
import android.content.Intent;
import eu.rampsoftware.er.view.currencies.CurrencyDetailsActivity; | package eu.rampsoftware.er.navigation;
public class Navigator {
private Activity mContext;
public Navigator(final Activity context) {
mContext = context;
}
public void navigateToCurrencyDetails(final String currencyCode) { | // Path: presentation/src/main/java/eu/rampsoftware/er/view/currencies/CurrencyDetailsActivity.java
// public class CurrencyDetailsActivity extends BaseActivity<CurrencyDetailsActivitySubComponent> {
//
// private static final String INTENT_EXTRA_PARAM_CURRENCY_CODE = "INTENT_EXTRA_PARAM_CURRENCY_CODE";
// @Inject
// CurrencyDetailsViewModel mViewModel;
//
// public static Intent getCallingIntent(final Context context, final String currencyCode) {
// Intent callingIntent = new Intent(context, CurrencyDetailsActivity.class);
// callingIntent.putExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE, currencyCode);
// return callingIntent;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ViewDataBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_currency_details);
// binding.setVariable(BR.model, mViewModel);
// if (!isRetained(savedInstanceState)) {
// final String currencyCode = getIntent().getStringExtra(INTENT_EXTRA_PARAM_CURRENCY_CODE);
// Bundle bundle = new Bundle();
// bundle.putString(CurrencyDetailsViewModel.KEY_CURRENCY_CODE, currencyCode);
// mViewModel.onLoad(bundle);
// }
// }
//
// @Override
// protected void onDestroy() {
// if(!isChangingConfigurations()) {
// mViewModel.dispose();
// }
// super.onDestroy();
// }
//
// @Override
// protected void injectDependencies(final CurrencyDetailsActivitySubComponent activityComponent) {
// activityComponent.inject(this);
// }
//
// protected CurrencyDetailsActivitySubComponent newComponent() {
// return ((ExchangeRatesApplication) getApplication())
// .getApplicationComponent()
// .newCurrencyDetailsActivitySubComponent(new CurrencyDetailsActivityModule(this));
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/navigation/Navigator.java
import android.app.Activity;
import android.content.Intent;
import eu.rampsoftware.er.view.currencies.CurrencyDetailsActivity;
package eu.rampsoftware.er.navigation;
public class Navigator {
private Activity mContext;
public Navigator(final Activity context) {
mContext = context;
}
public void navigateToCurrencyDetails(final String currencyCode) { | Intent intentToLaunch = CurrencyDetailsActivity.getCallingIntent(mContext, currencyCode); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import android.databinding.Bindable;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam; | package eu.rampsoftware.er.viewmodel.details;
public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE"; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
import android.databinding.Bindable;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
package eu.rampsoftware.er.viewmodel.details;
public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE"; | private GetCurrencySeriesUseCase mGetSeriesUseCase; |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import android.databinding.Bindable;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam; | package eu.rampsoftware.er.viewmodel.details;
public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
private GetCurrencySeriesUseCase mGetSeriesUseCase;
private boolean mIsProgressVisible; | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
import android.databinding.Bindable;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
package eu.rampsoftware.er.viewmodel.details;
public class CurrencyDetailsViewModel extends BaseDisposableViewModel implements BaseViewModel {
public static final String KEY_CURRENCY_CODE = "KEY_CURRENCY_CODE";
private GetCurrencySeriesUseCase mGetSeriesUseCase;
private boolean mIsProgressVisible; | private List<SingleValue> mCurrencySeries; |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
| import android.databinding.Bindable;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam; | public void onLoad(final Bundle bundle) {
checkNotNull(bundle);
checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
performRequest();
}
@Bindable
public boolean isProgressVisible() {
return mIsProgressVisible;
}
public void setProgressVisible(final boolean progressVisible) {
mIsProgressVisible = progressVisible;
notifyPropertyChanged(BR.progressVisible);
}
public void performRefresh() {
performRequest();
}
private void performRequest() {
setProgressVisible(true);
Date endDate = new Date();
int daysRange = 10;
mCurrencySeries.clear();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
Date from = calendar.getTime(); | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public class GetCurrencySeriesUseCase extends QueryUseCase<SingleValue, GetCurrencySeriesUseCase.CurrencySeriesParam> {
//
// private final CurrencyRepository mRepository;
//
// public GetCurrencySeriesUseCase(final Scheduler workScheduler,
// final Scheduler observeScheduler,
// CurrencyRepository repository) {
// super(workScheduler, observeScheduler);
// mRepository = repository;
//
// }
//
// @Override
// protected Observable<SingleValue> buildUseCaseObservable(final CurrencySeriesParam params) {
// return mRepository.getSeries(params.from, params.to, params.currencyCode);
// }
//
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseDisposableViewModel.java
// public abstract class BaseDisposableViewModel extends BaseObservable implements BaseViewModel {
//
// private final CompositeDisposable mDisposables;
//
// protected BaseDisposableViewModel() {
// mDisposables = new CompositeDisposable();
// }
//
// public void dispose() {
// if (!mDisposables.isDisposed()) {
// mDisposables.dispose();
// }
// }
//
// protected void addDisposable(Disposable disposable) {
// mDisposables.add(disposable);
// }
//
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/BaseViewModel.java
// public interface BaseViewModel {
// /**
// * Invoked when view is initialized and is ready to display the data exposed by view model.
// * @param bundle additional to be passed to the viewmodel.
// */
// void onLoad(final Bundle bundle);
//
// void dispose();
// }
//
// Path: domain/src/main/java/eu/rampsoftware/er/domain/usecases/GetCurrencySeriesUseCase.java
// public static class CurrencySeriesParam {
// Date from;
// Date to;
// String currencyCode;
//
// public CurrencySeriesParam(final Date from,
// final Date to,
// final String currencyCode) {
// this.from = checkNotNull(from);
// this.to = checkNotNull(to);
// this.currencyCode = checkNotNull(currencyCode);
// if(currencyCode.isEmpty()){
// throw new InvalidParameterException("CURRENCY CODE parameter cannot be empty");
// }
// if(from.getTime() > to.getTime()){
// throw new InvalidParameterException("START date cannot be after TO date.");
// }
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/viewmodel/details/CurrencyDetailsViewModel.java
import android.databinding.Bindable;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import eu.rampsoftware.er.BR;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase;
import eu.rampsoftware.er.viewmodel.BaseDisposableViewModel;
import eu.rampsoftware.er.viewmodel.BaseViewModel;
import static com.fernandocejas.arrow.checks.Preconditions.checkArgument;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static eu.rampsoftware.er.domain.usecases.GetCurrencySeriesUseCase.CurrencySeriesParam;
public void onLoad(final Bundle bundle) {
checkNotNull(bundle);
checkArgument(bundle.containsKey(KEY_CURRENCY_CODE), "Currency code must be provided to onLoad method");
setCurrencyCode(bundle.getString(KEY_CURRENCY_CODE));
performRequest();
}
@Bindable
public boolean isProgressVisible() {
return mIsProgressVisible;
}
public void setProgressVisible(final boolean progressVisible) {
mIsProgressVisible = progressVisible;
notifyPropertyChanged(BR.progressVisible);
}
public void performRefresh() {
performRequest();
}
private void performRequest() {
setProgressVisible(true);
Date endDate = new Date();
int daysRange = 10;
mCurrencySeries.clear();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
calendar.add(Calendar.DAY_OF_YEAR, -daysRange);
Date from = calendar.getTime(); | CurrencySeriesParam params = new CurrencySeriesParam(from, endDate, mCurrencyCode); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/widget/LineChartExtensions.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
| import android.databinding.BindingAdapter;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import eu.rampsoftware.er.R;
import eu.rampsoftware.er.data.SingleValue; | package eu.rampsoftware.er.widget;
public class LineChartExtensions {
private static SimpleDateFormat mDateFormatter = new SimpleDateFormat("dd/MM", Locale.getDefault());
@BindingAdapter({"bind:items"}) | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/widget/LineChartExtensions.java
import android.databinding.BindingAdapter;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import eu.rampsoftware.er.R;
import eu.rampsoftware.er.data.SingleValue;
package eu.rampsoftware.er.widget;
public class LineChartExtensions {
private static SimpleDateFormat mDateFormatter = new SimpleDateFormat("dd/MM", Locale.getDefault());
@BindingAdapter({"bind:items"}) | public static void populateDiagram(LineChart view, List<SingleValue> items) { |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties; | package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
| ApplicationProperties provideApplicationProperties(Context context); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties; | package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
| CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, CurrencyDataApi currencyDataApi); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties; | package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
| CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, CurrencyDataApi currencyDataApi); |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties; | package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, CurrencyDataApi currencyDataApi);
CurrencyDataSource provideLocalCurrencyDataSource();
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, CurrencyDataApi currencyDataApi);
CurrencyDataSource provideLocalCurrencyDataSource();
| CurrencyRepository provideCurrencyRepository(@Named("local") CurrencyDataSource localSource, |
krokers/exchange-rates-mvvm | presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
| import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties; | package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, CurrencyDataApi currencyDataApi);
CurrencyDataSource provideLocalCurrencyDataSource();
CurrencyRepository provideCurrencyRepository(@Named("local") CurrencyDataSource localSource,
@Named("remote") CurrencyDataSource remoteSource);
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyRepository.java
// public interface CurrencyRepository {
//
// Observable<CurrencyData> getCurrencies(final Date date);
//
// Observable<SingleValue> getSeries(Date from, Date to, String currencyCode);
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/PreferencesData.java
// public interface PreferencesData {
// void setCurrenciesExchangeDate(Date date);
// Optional<Date> getCurrenciesExchangeDate();
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/CurrencyDataApi.java
// public interface CurrencyDataApi {
//
// @GET("/historical/{date}.json")
// Observable<Response<CurrencyList>> getCurrencies(@Path("date") String date,
// @Query("app_id") String appId);
// }
//
// Path: presentation/src/main/java/eu/rampsoftware/er/properties/ApplicationProperties.java
// public interface ApplicationProperties {
// String baseUrl();
//
// boolean logsEnabled();
//
// String getOerAppId();
//
// String sharedPreferencesName();
// }
// Path: presentation/src/main/java/eu/rampsoftware/er/di/IApplicationModule.java
import android.content.Context;
import javax.inject.Named;
import eu.rampsoftware.er.data.CurrencyRepository;
import eu.rampsoftware.er.data.PreferencesData;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.CurrencyDataApi;
import eu.rampsoftware.er.properties.ApplicationProperties;
package eu.rampsoftware.er.di;
interface IApplicationModule {
String provideExampleString();
Context provideContext();
ApplicationProperties provideApplicationProperties(Context context);
CurrencyDataSource provideRemoteCurrencyDataSource(ApplicationProperties properties, CurrencyDataApi currencyDataApi);
CurrencyDataSource provideLocalCurrencyDataSource();
CurrencyRepository provideCurrencyRepository(@Named("local") CurrencyDataSource localSource,
@Named("remote") CurrencyDataSource remoteSource);
| PreferencesData providePreferencesData(ApplicationProperties properties); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
| import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response; | package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response;
package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override | public Observable<CurrencyData> getCurrencies(Date date) { |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
| import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response; | package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override
public Observable<CurrencyData> getCurrencies(Date date) {
| // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response;
package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override
public Observable<CurrencyData> getCurrencies(Date date) {
| final Observable<Response<CurrencyList>> request = mCurrencyDataApi.getCurrencies(mDateFormatter.format(date), mAppId); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
| import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response; | package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override
public Observable<CurrencyData> getCurrencies(Date date) {
final Observable<Response<CurrencyList>> request = mCurrencyDataApi.getCurrencies(mDateFormatter.format(date), mAppId);
return request
.flatMap(entryListDtoResponse -> Observable.just(entryListDtoResponse.body())) | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response;
package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override
public Observable<CurrencyData> getCurrencies(Date date) {
final Observable<Response<CurrencyList>> request = mCurrencyDataApi.getCurrencies(mDateFormatter.format(date), mAppId);
return request
.flatMap(entryListDtoResponse -> Observable.just(entryListDtoResponse.body())) | .flatMap(currencyList -> Observable.just(CurrencyListMapper.toCurrencyData(currencyList))); |
krokers/exchange-rates-mvvm | data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
| import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response; | package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override
public Observable<CurrencyData> getCurrencies(Date date) {
final Observable<Response<CurrencyList>> request = mCurrencyDataApi.getCurrencies(mDateFormatter.format(date), mAppId);
return request
.flatMap(entryListDtoResponse -> Observable.just(entryListDtoResponse.body()))
.flatMap(currencyList -> Observable.just(CurrencyListMapper.toCurrencyData(currencyList)));
}
@Override
public boolean containsCurrencyValue(final Date date, final String currencyCode) {
return false;
}
@Override
public boolean containsCurrencyValues(final Date date) {
return false;
}
@Override | // Path: databoundary/src/main/java/eu/rampsoftware/er/data/CurrencyData.java
// public class CurrencyData {
// private final String mBaseCurrency;
// private Date mDate;
// private Map<String, Double> mCurrencies;
//
// public CurrencyData(final Date date, final Map<String, Double> currencies, final String baseCurrency) {
// mDate = date;
// mCurrencies = currencies;
// mBaseCurrency = baseCurrency;
// }
//
// public String getBaseCurrency() {
// return mBaseCurrency;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public Map<String, Double> getCurrencies() {
// return mCurrencies;
// }
// }
//
// Path: databoundary/src/main/java/eu/rampsoftware/er/data/SingleValue.java
// public class SingleValue {
// private Date mDate;
// private double mValue;
//
// public SingleValue(final Date date, final double value) {
// mDate = date;
// mValue = value;
// }
//
// public Date getDate() {
// return mDate;
// }
//
// public double getValue() {
// return mValue;
// }
//
// @Override
// public String toString() {
// return "SingleValue{" +
// "mDate=" + mDate +
// ", mValue=" + mValue +
// '}';
// }
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/CurrencyDataSource.java
// public interface CurrencyDataSource {
//
// Observable<CurrencyData> getCurrencies(Date date);
//
// boolean containsCurrencyValue(Date date, String currencyCode);
//
// boolean containsCurrencyValues(Date date);
//
// Observable<SingleValue> getCurrencyValues(Date startDate, Date endDate, String currencyCode);
//
// void storeCurrencies(CurrencyData currencyData);
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/dto/CurrencyList.java
// public class CurrencyList {
//
// @SerializedName("disclaimer")
// @Expose
// private String disclaimer;
// @SerializedName("license")
// @Expose
// private String license;
// @SerializedName("timestamp")
// @Expose
// private Long timestamp;
// @SerializedName("base")
// @Expose
// private String base;
// @SerializedName("rates")
// @Expose
// private HashMap<String, Double> rates;
//
// public String getDisclaimer() {
// return disclaimer;
// }
//
// public void setDisclaimer(String disclaimer) {
// this.disclaimer = disclaimer;
// }
//
// public String getLicense() {
// return license;
// }
//
// public void setLicense(String license) {
// this.license = license;
// }
//
// public Long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(Long timestamp) {
// this.timestamp = timestamp;
// }
//
// public String getBase() {
// return base;
// }
//
// public void setBase(String base) {
// this.base = base;
// }
//
// public HashMap<String, Double> getRates() {
// return rates;
// }
//
// public void setRates(HashMap<String, Double> rates) {
// this.rates = rates;
// }
//
//
// }
//
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/mapper/CurrencyListMapper.java
// public class CurrencyListMapper {
//
// public static CurrencyData toCurrencyData(final CurrencyList currencyList) {
// return new CurrencyData(new Date(currencyList.getTimestamp() * 1000), currencyList.getRates(), currencyList.getBase());
// }
// }
// Path: data/src/main/java/eu/rampsoftware/er/data/datasource/remote/RetrofitCurrencyDataSource.java
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import eu.rampsoftware.er.data.CurrencyData;
import eu.rampsoftware.er.data.SingleValue;
import eu.rampsoftware.er.data.datasource.CurrencyDataSource;
import eu.rampsoftware.er.data.datasource.remote.dto.CurrencyList;
import eu.rampsoftware.er.data.datasource.remote.mapper.CurrencyListMapper;
import io.reactivex.Observable;
import retrofit2.Response;
package eu.rampsoftware.er.data.datasource.remote;
public class RetrofitCurrencyDataSource implements CurrencyDataSource {
private final String mAppId;
private CurrencyDataApi mCurrencyDataApi;
private SimpleDateFormat mDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
public RetrofitCurrencyDataSource(final CurrencyDataApi currencyDataApi,
String appId){
mCurrencyDataApi = currencyDataApi;
mAppId = appId;
}
@Override
public Observable<CurrencyData> getCurrencies(Date date) {
final Observable<Response<CurrencyList>> request = mCurrencyDataApi.getCurrencies(mDateFormatter.format(date), mAppId);
return request
.flatMap(entryListDtoResponse -> Observable.just(entryListDtoResponse.body()))
.flatMap(currencyList -> Observable.just(CurrencyListMapper.toCurrencyData(currencyList)));
}
@Override
public boolean containsCurrencyValue(final Date date, final String currencyCode) {
return false;
}
@Override
public boolean containsCurrencyValues(final Date date) {
return false;
}
@Override | public Observable<SingleValue> getCurrencyValues(final Date startDate, final Date endDate, final String currencyCode) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/App.java | // Path: app/src/main/java/com/example/offline/domain/services/jobs/JobManagerFactory.java
// public class JobManagerFactory {
//
// private static JobManager jobManager;
//
// public static synchronized JobManager getJobManager() {
// return jobManager;
// }
//
// public static synchronized JobManager getJobManager(Context context) {
// if (jobManager == null) {
// jobManager = configureJobManager(context);
// }
// return jobManager;
// }
//
// private static CustomLogger customLogger = new CustomLogger() {
//
// @Override
// public boolean isDebugEnabled() {
// return true;
// }
//
// @Override
// public void d(String text, Object... args) {
// Timber.d(String.format(text, args));
// }
//
// @Override
// public void e(Throwable t, String text, Object... args) {
// Timber.e(t, String.format(text, args));
// }
//
// @Override
// public void e(String text, Object... args) {
// Timber.e(String.format(text, args));
// }
//
// @Override
// public void v(String text, Object... args) {
// // no-op
// }
// };
//
// private static JobManager configureJobManager(Context context) {
// Configuration.Builder builder = new Configuration.Builder(context)
// .minConsumerCount(1)//always keep at least one consumer alive
// .maxConsumerCount(3)//up to 3 consumers at a time
// .loadFactor(3)//3 jobs per consumer
// .consumerKeepAlive(120)//wait 2 minutes
// .customLogger(customLogger);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// builder.scheduler(FrameworkJobSchedulerService.createSchedulerFor(context,
// SchedulerJobService.class), true);
// } else {
// int enableGcm = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
// if (enableGcm == ConnectionResult.SUCCESS) {
// builder.scheduler(GcmJobSchedulerService.createSchedulerFor(context,
// GcmJobSchedulerService.class), true);
// }
// }
// return new JobManager(builder.build());
// }
// }
| import android.app.Activity;
import android.app.Application;
import com.example.offline.di.DaggerAppComponent;
import com.example.offline.domain.services.jobs.JobManagerFactory;
import javax.inject.Inject;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import timber.log.Timber; | package com.example.offline;
public class App extends Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
DaggerAppComponent
.builder()
.application(this)
.build()
.inject(this);
| // Path: app/src/main/java/com/example/offline/domain/services/jobs/JobManagerFactory.java
// public class JobManagerFactory {
//
// private static JobManager jobManager;
//
// public static synchronized JobManager getJobManager() {
// return jobManager;
// }
//
// public static synchronized JobManager getJobManager(Context context) {
// if (jobManager == null) {
// jobManager = configureJobManager(context);
// }
// return jobManager;
// }
//
// private static CustomLogger customLogger = new CustomLogger() {
//
// @Override
// public boolean isDebugEnabled() {
// return true;
// }
//
// @Override
// public void d(String text, Object... args) {
// Timber.d(String.format(text, args));
// }
//
// @Override
// public void e(Throwable t, String text, Object... args) {
// Timber.e(t, String.format(text, args));
// }
//
// @Override
// public void e(String text, Object... args) {
// Timber.e(String.format(text, args));
// }
//
// @Override
// public void v(String text, Object... args) {
// // no-op
// }
// };
//
// private static JobManager configureJobManager(Context context) {
// Configuration.Builder builder = new Configuration.Builder(context)
// .minConsumerCount(1)//always keep at least one consumer alive
// .maxConsumerCount(3)//up to 3 consumers at a time
// .loadFactor(3)//3 jobs per consumer
// .consumerKeepAlive(120)//wait 2 minutes
// .customLogger(customLogger);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// builder.scheduler(FrameworkJobSchedulerService.createSchedulerFor(context,
// SchedulerJobService.class), true);
// } else {
// int enableGcm = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
// if (enableGcm == ConnectionResult.SUCCESS) {
// builder.scheduler(GcmJobSchedulerService.createSchedulerFor(context,
// GcmJobSchedulerService.class), true);
// }
// }
// return new JobManager(builder.build());
// }
// }
// Path: app/src/main/java/com/example/offline/App.java
import android.app.Activity;
import android.app.Application;
import com.example.offline.di.DaggerAppComponent;
import com.example.offline.domain.services.jobs.JobManagerFactory;
import javax.inject.Inject;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import timber.log.Timber;
package com.example.offline;
public class App extends Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
DaggerAppComponent
.builder()
.application(this)
.build()
.inject(this);
| JobManagerFactory.getJobManager(this); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/networking/RemoteCommentService.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.BuildConfig;
import com.example.offline.model.Comment;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import timber.log.Timber; | package com.example.offline.domain.services.networking;
public final class RemoteCommentService {
private static RemoteCommentService instance;
private final Retrofit retrofit;
public RemoteCommentService() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.create();
retrofit = new Retrofit.Builder()
.client(httpClient)
.baseUrl(BuildConfig.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
public static synchronized RemoteCommentService getInstance() {
if (instance == null) {
instance = new RemoteCommentService();
}
return instance;
}
| // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/networking/RemoteCommentService.java
import com.example.offline.BuildConfig;
import com.example.offline.model.Comment;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import timber.log.Timber;
package com.example.offline.domain.services.networking;
public final class RemoteCommentService {
private static RemoteCommentService instance;
private final Retrofit retrofit;
public RemoteCommentService() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.create();
retrofit = new Retrofit.Builder()
.client(httpClient)
.baseUrl(BuildConfig.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
public static synchronized RemoteCommentService getInstance() {
if (instance == null) {
instance = new RemoteCommentService();
}
return instance;
}
| public void addComment(Comment comment) throws IOException, RemoteException { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/data/CommentDao.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import com.example.offline.model.Comment;
import java.util.List;
import io.reactivex.Flowable; | package com.example.offline.data;
@Dao
public interface CommentDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import com.example.offline.model.Comment;
import java.util.List;
import io.reactivex.Flowable;
package com.example.offline.data;
@Dao
public interface CommentDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) | long add(Comment comment); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/SyncCommentResponse.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.model.Comment; | package com.example.offline.domain.services;
public class SyncCommentResponse {
public final SyncResponseEventType eventType; | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/SyncCommentResponse.java
import com.example.offline.model.Comment;
package com.example.offline.domain.services;
public class SyncCommentResponse {
public final SyncResponseEventType eventType; | public final Comment comment; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java | // Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
// public class AddCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
// private final SyncCommentUseCase syncCommentUseCase;
//
// public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
// this.localCommentRepository = localCommentRepository;
// this.syncCommentUseCase = syncCommentUseCase;
// }
//
// public Completable addComment(String commentText) {
// return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText)
// .flatMapCompletable(syncCommentUseCase::syncComment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
// public class GetCommentsUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Flowable<List<Comment>> getComments() {
// return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID);
// }
// }
| import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProvider;
import com.example.offline.domain.AddCommentUseCase;
import com.example.offline.domain.GetCommentsUseCase; | package com.example.offline.presentation;
public class CommentsViewModelFactory implements ViewModelProvider.Factory {
private final GetCommentsUseCase getCommentsUseCase; | // Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
// public class AddCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
// private final SyncCommentUseCase syncCommentUseCase;
//
// public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
// this.localCommentRepository = localCommentRepository;
// this.syncCommentUseCase = syncCommentUseCase;
// }
//
// public Completable addComment(String commentText) {
// return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText)
// .flatMapCompletable(syncCommentUseCase::syncComment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
// public class GetCommentsUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Flowable<List<Comment>> getComments() {
// return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID);
// }
// }
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProvider;
import com.example.offline.domain.AddCommentUseCase;
import com.example.offline.domain.GetCommentsUseCase;
package com.example.offline.presentation;
public class CommentsViewModelFactory implements ViewModelProvider.Factory {
private final GetCommentsUseCase getCommentsUseCase; | private final AddCommentUseCase addCommentUseCase; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/jobs/SyncCommentJob.java | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentRxBus.java
// public class SyncCommentRxBus {
//
// private static SyncCommentRxBus instance;
// private final PublishRelay<SyncCommentResponse> relay;
//
// public static synchronized SyncCommentRxBus getInstance() {
// if (instance == null) {
// instance = new SyncCommentRxBus();
// }
// return instance;
// }
//
// private SyncCommentRxBus() {
// relay = PublishRelay.create();
// }
//
// public void post(SyncResponseEventType eventType, Comment comment) {
// relay.accept(new SyncCommentResponse(eventType, comment));
// }
//
// public Observable<SyncCommentResponse> toObservable() {
// return relay;
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/SyncResponseEventType.java
// public enum SyncResponseEventType {
// SUCCESS,
// FAILED
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
// public static Comment clone(Comment from, boolean syncPending) {
// return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), syncPending);
// }
//
// public static Comment clone(Comment from, long id) {
// return new Comment(id, from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), from.isSyncPending());
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/networking/RemoteCommentService.java
// public final class RemoteCommentService {
//
// private static RemoteCommentService instance;
//
// private final Retrofit retrofit;
//
// public RemoteCommentService() {
//
// HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
//
// OkHttpClient httpClient = new OkHttpClient.Builder()
// .addInterceptor(loggingInterceptor)
// .build();
//
// Gson gson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// retrofit = new Retrofit.Builder()
// .client(httpClient)
// .baseUrl(BuildConfig.API_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .build();
// }
//
// public static synchronized RemoteCommentService getInstance() {
// if (instance == null) {
// instance = new RemoteCommentService();
// }
// return instance;
// }
//
// public void addComment(Comment comment) throws IOException, RemoteException {
// RemoteCommentEndpoint service = retrofit.create(RemoteCommentEndpoint.class);
//
// // Remote call can be executed synchronously since the job calling it is already backgrounded.
// Response<Comment> response = service.addComment(comment).execute();
//
// if (response == null || !response.isSuccessful() || response.errorBody() != null) {
// throw new RemoteException(response);
// }
//
// Timber.d("successful remote response: " + response.body());
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/networking/RemoteException.java
// public class RemoteException extends Exception {
//
// private final Response response;
//
// public RemoteException(Response response) {
// this.response = response;
// }
//
// public Response getResponse() {
// return response;
// }
// }
| import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.birbit.android.jobqueue.Job;
import com.birbit.android.jobqueue.Params;
import com.birbit.android.jobqueue.RetryConstraint;
import com.example.offline.domain.services.SyncCommentRxBus;
import com.example.offline.domain.services.SyncResponseEventType;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import com.example.offline.domain.services.networking.RemoteCommentService;
import com.example.offline.domain.services.networking.RemoteException;
import timber.log.Timber; | package com.example.offline.domain.services.jobs;
public class SyncCommentJob extends Job {
private static final String TAG = SyncCommentJob.class.getCanonicalName(); | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentRxBus.java
// public class SyncCommentRxBus {
//
// private static SyncCommentRxBus instance;
// private final PublishRelay<SyncCommentResponse> relay;
//
// public static synchronized SyncCommentRxBus getInstance() {
// if (instance == null) {
// instance = new SyncCommentRxBus();
// }
// return instance;
// }
//
// private SyncCommentRxBus() {
// relay = PublishRelay.create();
// }
//
// public void post(SyncResponseEventType eventType, Comment comment) {
// relay.accept(new SyncCommentResponse(eventType, comment));
// }
//
// public Observable<SyncCommentResponse> toObservable() {
// return relay;
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/SyncResponseEventType.java
// public enum SyncResponseEventType {
// SUCCESS,
// FAILED
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
// public static Comment clone(Comment from, boolean syncPending) {
// return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), syncPending);
// }
//
// public static Comment clone(Comment from, long id) {
// return new Comment(id, from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), from.isSyncPending());
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/networking/RemoteCommentService.java
// public final class RemoteCommentService {
//
// private static RemoteCommentService instance;
//
// private final Retrofit retrofit;
//
// public RemoteCommentService() {
//
// HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
//
// OkHttpClient httpClient = new OkHttpClient.Builder()
// .addInterceptor(loggingInterceptor)
// .build();
//
// Gson gson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// retrofit = new Retrofit.Builder()
// .client(httpClient)
// .baseUrl(BuildConfig.API_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .build();
// }
//
// public static synchronized RemoteCommentService getInstance() {
// if (instance == null) {
// instance = new RemoteCommentService();
// }
// return instance;
// }
//
// public void addComment(Comment comment) throws IOException, RemoteException {
// RemoteCommentEndpoint service = retrofit.create(RemoteCommentEndpoint.class);
//
// // Remote call can be executed synchronously since the job calling it is already backgrounded.
// Response<Comment> response = service.addComment(comment).execute();
//
// if (response == null || !response.isSuccessful() || response.errorBody() != null) {
// throw new RemoteException(response);
// }
//
// Timber.d("successful remote response: " + response.body());
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/networking/RemoteException.java
// public class RemoteException extends Exception {
//
// private final Response response;
//
// public RemoteException(Response response) {
// this.response = response;
// }
//
// public Response getResponse() {
// return response;
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SyncCommentJob.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.birbit.android.jobqueue.Job;
import com.birbit.android.jobqueue.Params;
import com.birbit.android.jobqueue.RetryConstraint;
import com.example.offline.domain.services.SyncCommentRxBus;
import com.example.offline.domain.services.SyncResponseEventType;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import com.example.offline.domain.services.networking.RemoteCommentService;
import com.example.offline.domain.services.networking.RemoteException;
import timber.log.Timber;
package com.example.offline.domain.services.jobs;
public class SyncCommentJob extends Job {
private static final String TAG = SyncCommentJob.class.getCanonicalName(); | private final Comment comment; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java | // Path: app/src/main/java/com/example/offline/domain/DeleteCommentUseCase.java
// public class DeleteCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public DeleteCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable deleteComment(Comment comment) {
// return localCommentRepository.delete(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/UpdateCommentUseCase.java
// public class UpdateCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public UpdateCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable updateComment(Comment comment) {
// return localCommentRepository.update(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import com.example.offline.domain.DeleteCommentUseCase;
import com.example.offline.domain.UpdateCommentUseCase;
import com.example.offline.model.Comment;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber; | package com.example.offline.domain.services;
/**
* Updates local database after remote comment sync requests
*/
public class SyncCommentLifecycleObserver implements LifecycleObserver {
private final UpdateCommentUseCase updateCommentUseCase; | // Path: app/src/main/java/com/example/offline/domain/DeleteCommentUseCase.java
// public class DeleteCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public DeleteCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable deleteComment(Comment comment) {
// return localCommentRepository.delete(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/UpdateCommentUseCase.java
// public class UpdateCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public UpdateCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable updateComment(Comment comment) {
// return localCommentRepository.update(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import com.example.offline.domain.DeleteCommentUseCase;
import com.example.offline.domain.UpdateCommentUseCase;
import com.example.offline.model.Comment;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
package com.example.offline.domain.services;
/**
* Updates local database after remote comment sync requests
*/
public class SyncCommentLifecycleObserver implements LifecycleObserver {
private final UpdateCommentUseCase updateCommentUseCase; | private final DeleteCommentUseCase deleteCommentUseCase; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java | // Path: app/src/main/java/com/example/offline/domain/DeleteCommentUseCase.java
// public class DeleteCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public DeleteCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable deleteComment(Comment comment) {
// return localCommentRepository.delete(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/UpdateCommentUseCase.java
// public class UpdateCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public UpdateCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable updateComment(Comment comment) {
// return localCommentRepository.update(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import com.example.offline.domain.DeleteCommentUseCase;
import com.example.offline.domain.UpdateCommentUseCase;
import com.example.offline.model.Comment;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber; | package com.example.offline.domain.services;
/**
* Updates local database after remote comment sync requests
*/
public class SyncCommentLifecycleObserver implements LifecycleObserver {
private final UpdateCommentUseCase updateCommentUseCase;
private final DeleteCommentUseCase deleteCommentUseCase;
private final CompositeDisposable disposables = new CompositeDisposable();
public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
DeleteCommentUseCase deleteCommentUseCase) {
this.updateCommentUseCase = updateCommentUseCase;
this.deleteCommentUseCase = deleteCommentUseCase;
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
Timber.d("onResume lifecycle event.");
disposables.add(SyncCommentRxBus.getInstance().toObservable()
.subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onPause() {
Timber.d("onPause lifecycle event.");
disposables.clear();
}
private void handleSyncResponse(SyncCommentResponse response) {
if (response.eventType == SyncResponseEventType.SUCCESS) {
onSyncCommentSuccess(response.comment);
} else {
onSyncCommentFailed(response.comment);
}
}
| // Path: app/src/main/java/com/example/offline/domain/DeleteCommentUseCase.java
// public class DeleteCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public DeleteCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable deleteComment(Comment comment) {
// return localCommentRepository.delete(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/UpdateCommentUseCase.java
// public class UpdateCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public UpdateCommentUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Completable updateComment(Comment comment) {
// return localCommentRepository.update(comment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import com.example.offline.domain.DeleteCommentUseCase;
import com.example.offline.domain.UpdateCommentUseCase;
import com.example.offline.model.Comment;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
package com.example.offline.domain.services;
/**
* Updates local database after remote comment sync requests
*/
public class SyncCommentLifecycleObserver implements LifecycleObserver {
private final UpdateCommentUseCase updateCommentUseCase;
private final DeleteCommentUseCase deleteCommentUseCase;
private final CompositeDisposable disposables = new CompositeDisposable();
public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
DeleteCommentUseCase deleteCommentUseCase) {
this.updateCommentUseCase = updateCommentUseCase;
this.deleteCommentUseCase = deleteCommentUseCase;
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
Timber.d("onResume lifecycle event.");
disposables.add(SyncCommentRxBus.getInstance().toObservable()
.subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onPause() {
Timber.d("onPause lifecycle event.");
disposables.clear();
}
private void handleSyncResponse(SyncCommentResponse response) {
if (response.eventType == SyncResponseEventType.SUCCESS) {
onSyncCommentSuccess(response.comment);
} else {
onSyncCommentFailed(response.comment);
}
}
| private void onSyncCommentSuccess(Comment comment) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/DeleteCommentUseCase.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.model.Comment;
import io.reactivex.Completable; | package com.example.offline.domain;
public class DeleteCommentUseCase {
private final LocalCommentRepository localCommentRepository;
public DeleteCommentUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
| // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/DeleteCommentUseCase.java
import com.example.offline.model.Comment;
import io.reactivex.Completable;
package com.example.offline.domain;
public class DeleteCommentUseCase {
private final LocalCommentRepository localCommentRepository;
public DeleteCommentUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
| public Completable deleteComment(Comment comment) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppComponent.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
| import com.example.offline.App;
import javax.inject.Singleton;
import dagger.BindsInstance;
import dagger.Component;
import dagger.android.support.AndroidSupportInjectionModule; | package com.example.offline.di;
@Singleton
@Component(modules = {
/* Use AndroidInjectionModule.class if you're not using support library */
AndroidSupportInjectionModule.class,
AppModule.class,
BuildersModule.class})
public interface AppComponent {
@Component.Builder
interface Builder {
@BindsInstance | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppComponent.java
import com.example.offline.App;
import javax.inject.Singleton;
import dagger.BindsInstance;
import dagger.Component;
import dagger.android.support.AndroidSupportInjectionModule;
package com.example.offline.di;
@Singleton
@Component(modules = {
/* Use AndroidInjectionModule.class if you're not using support library */
AndroidSupportInjectionModule.class,
AppModule.class,
BuildersModule.class})
public interface AppComponent {
@Component.Builder
interface Builder {
@BindsInstance | Builder application(App application); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/presentation/CommentsViewModel.java | // Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
// public class AddCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
// private final SyncCommentUseCase syncCommentUseCase;
//
// public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
// this.localCommentRepository = localCommentRepository;
// this.syncCommentUseCase = syncCommentUseCase;
// }
//
// public Completable addComment(String commentText) {
// return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText)
// .flatMapCompletable(syncCommentUseCase::syncComment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
// public class GetCommentsUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Flowable<List<Comment>> getComments() {
// return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import com.example.offline.domain.AddCommentUseCase;
import com.example.offline.domain.GetCommentsUseCase;
import com.example.offline.model.Comment;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber; | package com.example.offline.presentation;
public class CommentsViewModel extends ViewModel {
private final GetCommentsUseCase getCommentsUseCase; | // Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
// public class AddCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
// private final SyncCommentUseCase syncCommentUseCase;
//
// public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
// this.localCommentRepository = localCommentRepository;
// this.syncCommentUseCase = syncCommentUseCase;
// }
//
// public Completable addComment(String commentText) {
// return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText)
// .flatMapCompletable(syncCommentUseCase::syncComment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
// public class GetCommentsUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Flowable<List<Comment>> getComments() {
// return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import com.example.offline.domain.AddCommentUseCase;
import com.example.offline.domain.GetCommentsUseCase;
import com.example.offline.model.Comment;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
package com.example.offline.presentation;
public class CommentsViewModel extends ViewModel {
private final GetCommentsUseCase getCommentsUseCase; | private final AddCommentUseCase addCommentUseCase; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/presentation/CommentsViewModel.java | // Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
// public class AddCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
// private final SyncCommentUseCase syncCommentUseCase;
//
// public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
// this.localCommentRepository = localCommentRepository;
// this.syncCommentUseCase = syncCommentUseCase;
// }
//
// public Completable addComment(String commentText) {
// return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText)
// .flatMapCompletable(syncCommentUseCase::syncComment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
// public class GetCommentsUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Flowable<List<Comment>> getComments() {
// return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import com.example.offline.domain.AddCommentUseCase;
import com.example.offline.domain.GetCommentsUseCase;
import com.example.offline.model.Comment;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber; | package com.example.offline.presentation;
public class CommentsViewModel extends ViewModel {
private final GetCommentsUseCase getCommentsUseCase;
private final AddCommentUseCase addCommentUseCase;
private final CompositeDisposable disposables = new CompositeDisposable(); | // Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
// public class AddCommentUseCase {
// private final LocalCommentRepository localCommentRepository;
// private final SyncCommentUseCase syncCommentUseCase;
//
// public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
// this.localCommentRepository = localCommentRepository;
// this.syncCommentUseCase = syncCommentUseCase;
// }
//
// public Completable addComment(String commentText) {
// return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText)
// .flatMapCompletable(syncCommentUseCase::syncComment);
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
// public class GetCommentsUseCase {
// private final LocalCommentRepository localCommentRepository;
//
// public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
// this.localCommentRepository = localCommentRepository;
// }
//
// public Flowable<List<Comment>> getComments() {
// return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import com.example.offline.domain.AddCommentUseCase;
import com.example.offline.domain.GetCommentsUseCase;
import com.example.offline.model.Comment;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
package com.example.offline.presentation;
public class CommentsViewModel extends ViewModel {
private final GetCommentsUseCase getCommentsUseCase;
private final AddCommentUseCase addCommentUseCase;
private final CompositeDisposable disposables = new CompositeDisposable(); | private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>(); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/AddCommentUseCase.java | // Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
| import com.example.offline.model.ModelConstants;
import io.reactivex.Completable; | package com.example.offline.domain;
public class AddCommentUseCase {
private final LocalCommentRepository localCommentRepository;
private final SyncCommentUseCase syncCommentUseCase;
public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
this.localCommentRepository = localCommentRepository;
this.syncCommentUseCase = syncCommentUseCase;
}
public Completable addComment(String commentText) { | // Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
// Path: app/src/main/java/com/example/offline/domain/AddCommentUseCase.java
import com.example.offline.model.ModelConstants;
import io.reactivex.Completable;
package com.example.offline.domain;
public class AddCommentUseCase {
private final LocalCommentRepository localCommentRepository;
private final SyncCommentUseCase syncCommentUseCase;
public AddCommentUseCase(LocalCommentRepository localCommentRepository, SyncCommentUseCase syncCommentUseCase) {
this.localCommentRepository = localCommentRepository;
this.syncCommentUseCase = syncCommentUseCase;
}
public Completable addComment(String commentText) { | return localCommentRepository.add(ModelConstants.DUMMY_PHOTO_ID, commentText) |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/data/LocalCommentDataStore.java | // Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
// public static Comment clone(Comment from, boolean syncPending) {
// return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), syncPending);
// }
//
// public static Comment clone(Comment from, long id) {
// return new Comment(id, from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), from.isSyncPending());
// }
// }
| import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import timber.log.Timber; | package com.example.offline.data;
public class LocalCommentDataStore implements LocalCommentRepository {
private final CommentDao commentDao;
public LocalCommentDataStore(CommentDao commentDao) {
this.commentDao = commentDao;
}
/**
* Adds a comment to a given photo
*/ | // Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
// public static Comment clone(Comment from, boolean syncPending) {
// return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), syncPending);
// }
//
// public static Comment clone(Comment from, long id) {
// return new Comment(id, from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), from.isSyncPending());
// }
// }
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import timber.log.Timber;
package com.example.offline.data;
public class LocalCommentDataStore implements LocalCommentRepository {
private final CommentDao commentDao;
public LocalCommentDataStore(CommentDao commentDao) {
this.commentDao = commentDao;
}
/**
* Adds a comment to a given photo
*/ | public Single<Comment> add(long photoId, String commentText) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/data/LocalCommentDataStore.java | // Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
// public static Comment clone(Comment from, boolean syncPending) {
// return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), syncPending);
// }
//
// public static Comment clone(Comment from, long id) {
// return new Comment(id, from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), from.isSyncPending());
// }
// }
| import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import timber.log.Timber; | package com.example.offline.data;
public class LocalCommentDataStore implements LocalCommentRepository {
private final CommentDao commentDao;
public LocalCommentDataStore(CommentDao commentDao) {
this.commentDao = commentDao;
}
/**
* Adds a comment to a given photo
*/
public Single<Comment> add(long photoId, String commentText) {
Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
Comment comment = new Comment(photoId, commentText);
return Single.fromCallable(() -> {
long rowId = commentDao.add(comment);
Timber.d("comment stored " + rowId); | // Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/CommentUtils.java
// public class CommentUtils {
// public static Comment clone(Comment from, boolean syncPending) {
// return new Comment(from.getId(), from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), syncPending);
// }
//
// public static Comment clone(Comment from, long id) {
// return new Comment(id, from.getPhotoId(), from.getCommentText(),
// from.getTimestamp(), from.isSyncPending());
// }
// }
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.model.Comment;
import com.example.offline.model.CommentUtils;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import timber.log.Timber;
package com.example.offline.data;
public class LocalCommentDataStore implements LocalCommentRepository {
private final CommentDao commentDao;
public LocalCommentDataStore(CommentDao commentDao) {
this.commentDao = commentDao;
}
/**
* Adds a comment to a given photo
*/
public Single<Comment> add(long photoId, String commentText) {
Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
Comment comment = new Comment(photoId, commentText);
return Single.fromCallable(() -> {
long rowId = commentDao.add(comment);
Timber.d("comment stored " + rowId); | return CommentUtils.clone(comment, rowId); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/view/CommentsActivity.java | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
// public class SyncCommentLifecycleObserver implements LifecycleObserver {
// private final UpdateCommentUseCase updateCommentUseCase;
// private final DeleteCommentUseCase deleteCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
//
// public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
// DeleteCommentUseCase deleteCommentUseCase) {
// this.updateCommentUseCase = updateCommentUseCase;
// this.deleteCommentUseCase = deleteCommentUseCase;
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
// public void onResume() {
// Timber.d("onResume lifecycle event.");
// disposables.add(SyncCommentRxBus.getInstance().toObservable()
// .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// public void onPause() {
// Timber.d("onPause lifecycle event.");
// disposables.clear();
// }
//
// private void handleSyncResponse(SyncCommentResponse response) {
// if (response.eventType == SyncResponseEventType.SUCCESS) {
// onSyncCommentSuccess(response.comment);
// } else {
// onSyncCommentFailed(response.comment);
// }
// }
//
// private void onSyncCommentSuccess(Comment comment) {
// Timber.d("received sync comment success event for comment %s", comment);
// disposables.add(updateCommentUseCase.updateComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("update comment success"),
// t -> Timber.e(t, "update comment error")));
// }
//
// private void onSyncCommentFailed(Comment comment) {
// Timber.d("received sync comment failed event for comment %s", comment);
// disposables.add(deleteCommentUseCase.deleteComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("delete comment success"),
// t -> Timber.e(t, "delete comment error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
// public class CommentsViewModel extends ViewModel {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
// private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>();
//
// public CommentsViewModel(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
//
// loadComments();
// }
//
// @Override
// protected void onCleared() {
// disposables.clear();
// }
//
// /**
// * Adds new comment
// */
// public void addComment(String commentText) {
// disposables.add(addCommentUseCase.addComment(commentText)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("add comment success"),
// t -> Timber.e(t, "add comment error")));
// }
//
// /**
// * Exposes the latest comments so the UI can observe it
// */
// public LiveData<List<Comment>> comments() {
// return commentsLiveData;
// }
//
// void loadComments() {
// disposables.add(getCommentsUseCase.getComments()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(commentsLiveData::setValue,
// t -> Timber.e(t, "get comments error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
// public class CommentsViewModelFactory implements ViewModelProvider.Factory {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
//
// public CommentsViewModelFactory(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
// }
//
// @Override
// public <T extends ViewModel> T create(Class<T> modelClass) {
// if (modelClass.isAssignableFrom(CommentsViewModel.class)) {
// return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase);
// }
// throw new IllegalArgumentException("Unknown ViewModel class");
// }
// }
| import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.example.offline.R;
import com.example.offline.domain.services.SyncCommentLifecycleObserver;
import com.example.offline.presentation.CommentsViewModel;
import com.example.offline.presentation.CommentsViewModelFactory;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dagger.android.AndroidInjection; | package com.example.offline.view;
public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
@Inject | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
// public class SyncCommentLifecycleObserver implements LifecycleObserver {
// private final UpdateCommentUseCase updateCommentUseCase;
// private final DeleteCommentUseCase deleteCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
//
// public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
// DeleteCommentUseCase deleteCommentUseCase) {
// this.updateCommentUseCase = updateCommentUseCase;
// this.deleteCommentUseCase = deleteCommentUseCase;
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
// public void onResume() {
// Timber.d("onResume lifecycle event.");
// disposables.add(SyncCommentRxBus.getInstance().toObservable()
// .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// public void onPause() {
// Timber.d("onPause lifecycle event.");
// disposables.clear();
// }
//
// private void handleSyncResponse(SyncCommentResponse response) {
// if (response.eventType == SyncResponseEventType.SUCCESS) {
// onSyncCommentSuccess(response.comment);
// } else {
// onSyncCommentFailed(response.comment);
// }
// }
//
// private void onSyncCommentSuccess(Comment comment) {
// Timber.d("received sync comment success event for comment %s", comment);
// disposables.add(updateCommentUseCase.updateComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("update comment success"),
// t -> Timber.e(t, "update comment error")));
// }
//
// private void onSyncCommentFailed(Comment comment) {
// Timber.d("received sync comment failed event for comment %s", comment);
// disposables.add(deleteCommentUseCase.deleteComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("delete comment success"),
// t -> Timber.e(t, "delete comment error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
// public class CommentsViewModel extends ViewModel {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
// private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>();
//
// public CommentsViewModel(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
//
// loadComments();
// }
//
// @Override
// protected void onCleared() {
// disposables.clear();
// }
//
// /**
// * Adds new comment
// */
// public void addComment(String commentText) {
// disposables.add(addCommentUseCase.addComment(commentText)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("add comment success"),
// t -> Timber.e(t, "add comment error")));
// }
//
// /**
// * Exposes the latest comments so the UI can observe it
// */
// public LiveData<List<Comment>> comments() {
// return commentsLiveData;
// }
//
// void loadComments() {
// disposables.add(getCommentsUseCase.getComments()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(commentsLiveData::setValue,
// t -> Timber.e(t, "get comments error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
// public class CommentsViewModelFactory implements ViewModelProvider.Factory {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
//
// public CommentsViewModelFactory(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
// }
//
// @Override
// public <T extends ViewModel> T create(Class<T> modelClass) {
// if (modelClass.isAssignableFrom(CommentsViewModel.class)) {
// return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase);
// }
// throw new IllegalArgumentException("Unknown ViewModel class");
// }
// }
// Path: app/src/main/java/com/example/offline/view/CommentsActivity.java
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.example.offline.R;
import com.example.offline.domain.services.SyncCommentLifecycleObserver;
import com.example.offline.presentation.CommentsViewModel;
import com.example.offline.presentation.CommentsViewModelFactory;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dagger.android.AndroidInjection;
package com.example.offline.view;
public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
@Inject | CommentsViewModelFactory viewModelFactory; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/view/CommentsActivity.java | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
// public class SyncCommentLifecycleObserver implements LifecycleObserver {
// private final UpdateCommentUseCase updateCommentUseCase;
// private final DeleteCommentUseCase deleteCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
//
// public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
// DeleteCommentUseCase deleteCommentUseCase) {
// this.updateCommentUseCase = updateCommentUseCase;
// this.deleteCommentUseCase = deleteCommentUseCase;
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
// public void onResume() {
// Timber.d("onResume lifecycle event.");
// disposables.add(SyncCommentRxBus.getInstance().toObservable()
// .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// public void onPause() {
// Timber.d("onPause lifecycle event.");
// disposables.clear();
// }
//
// private void handleSyncResponse(SyncCommentResponse response) {
// if (response.eventType == SyncResponseEventType.SUCCESS) {
// onSyncCommentSuccess(response.comment);
// } else {
// onSyncCommentFailed(response.comment);
// }
// }
//
// private void onSyncCommentSuccess(Comment comment) {
// Timber.d("received sync comment success event for comment %s", comment);
// disposables.add(updateCommentUseCase.updateComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("update comment success"),
// t -> Timber.e(t, "update comment error")));
// }
//
// private void onSyncCommentFailed(Comment comment) {
// Timber.d("received sync comment failed event for comment %s", comment);
// disposables.add(deleteCommentUseCase.deleteComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("delete comment success"),
// t -> Timber.e(t, "delete comment error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
// public class CommentsViewModel extends ViewModel {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
// private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>();
//
// public CommentsViewModel(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
//
// loadComments();
// }
//
// @Override
// protected void onCleared() {
// disposables.clear();
// }
//
// /**
// * Adds new comment
// */
// public void addComment(String commentText) {
// disposables.add(addCommentUseCase.addComment(commentText)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("add comment success"),
// t -> Timber.e(t, "add comment error")));
// }
//
// /**
// * Exposes the latest comments so the UI can observe it
// */
// public LiveData<List<Comment>> comments() {
// return commentsLiveData;
// }
//
// void loadComments() {
// disposables.add(getCommentsUseCase.getComments()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(commentsLiveData::setValue,
// t -> Timber.e(t, "get comments error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
// public class CommentsViewModelFactory implements ViewModelProvider.Factory {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
//
// public CommentsViewModelFactory(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
// }
//
// @Override
// public <T extends ViewModel> T create(Class<T> modelClass) {
// if (modelClass.isAssignableFrom(CommentsViewModel.class)) {
// return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase);
// }
// throw new IllegalArgumentException("Unknown ViewModel class");
// }
// }
| import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.example.offline.R;
import com.example.offline.domain.services.SyncCommentLifecycleObserver;
import com.example.offline.presentation.CommentsViewModel;
import com.example.offline.presentation.CommentsViewModelFactory;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dagger.android.AndroidInjection; | package com.example.offline.view;
public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
@Inject
CommentsViewModelFactory viewModelFactory;
@Inject | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
// public class SyncCommentLifecycleObserver implements LifecycleObserver {
// private final UpdateCommentUseCase updateCommentUseCase;
// private final DeleteCommentUseCase deleteCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
//
// public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
// DeleteCommentUseCase deleteCommentUseCase) {
// this.updateCommentUseCase = updateCommentUseCase;
// this.deleteCommentUseCase = deleteCommentUseCase;
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
// public void onResume() {
// Timber.d("onResume lifecycle event.");
// disposables.add(SyncCommentRxBus.getInstance().toObservable()
// .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// public void onPause() {
// Timber.d("onPause lifecycle event.");
// disposables.clear();
// }
//
// private void handleSyncResponse(SyncCommentResponse response) {
// if (response.eventType == SyncResponseEventType.SUCCESS) {
// onSyncCommentSuccess(response.comment);
// } else {
// onSyncCommentFailed(response.comment);
// }
// }
//
// private void onSyncCommentSuccess(Comment comment) {
// Timber.d("received sync comment success event for comment %s", comment);
// disposables.add(updateCommentUseCase.updateComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("update comment success"),
// t -> Timber.e(t, "update comment error")));
// }
//
// private void onSyncCommentFailed(Comment comment) {
// Timber.d("received sync comment failed event for comment %s", comment);
// disposables.add(deleteCommentUseCase.deleteComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("delete comment success"),
// t -> Timber.e(t, "delete comment error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
// public class CommentsViewModel extends ViewModel {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
// private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>();
//
// public CommentsViewModel(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
//
// loadComments();
// }
//
// @Override
// protected void onCleared() {
// disposables.clear();
// }
//
// /**
// * Adds new comment
// */
// public void addComment(String commentText) {
// disposables.add(addCommentUseCase.addComment(commentText)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("add comment success"),
// t -> Timber.e(t, "add comment error")));
// }
//
// /**
// * Exposes the latest comments so the UI can observe it
// */
// public LiveData<List<Comment>> comments() {
// return commentsLiveData;
// }
//
// void loadComments() {
// disposables.add(getCommentsUseCase.getComments()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(commentsLiveData::setValue,
// t -> Timber.e(t, "get comments error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
// public class CommentsViewModelFactory implements ViewModelProvider.Factory {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
//
// public CommentsViewModelFactory(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
// }
//
// @Override
// public <T extends ViewModel> T create(Class<T> modelClass) {
// if (modelClass.isAssignableFrom(CommentsViewModel.class)) {
// return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase);
// }
// throw new IllegalArgumentException("Unknown ViewModel class");
// }
// }
// Path: app/src/main/java/com/example/offline/view/CommentsActivity.java
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.example.offline.R;
import com.example.offline.domain.services.SyncCommentLifecycleObserver;
import com.example.offline.presentation.CommentsViewModel;
import com.example.offline.presentation.CommentsViewModelFactory;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dagger.android.AndroidInjection;
package com.example.offline.view;
public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
@Inject
CommentsViewModelFactory viewModelFactory;
@Inject | SyncCommentLifecycleObserver syncCommentLifecycleObserver; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/view/CommentsActivity.java | // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
// public class SyncCommentLifecycleObserver implements LifecycleObserver {
// private final UpdateCommentUseCase updateCommentUseCase;
// private final DeleteCommentUseCase deleteCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
//
// public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
// DeleteCommentUseCase deleteCommentUseCase) {
// this.updateCommentUseCase = updateCommentUseCase;
// this.deleteCommentUseCase = deleteCommentUseCase;
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
// public void onResume() {
// Timber.d("onResume lifecycle event.");
// disposables.add(SyncCommentRxBus.getInstance().toObservable()
// .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// public void onPause() {
// Timber.d("onPause lifecycle event.");
// disposables.clear();
// }
//
// private void handleSyncResponse(SyncCommentResponse response) {
// if (response.eventType == SyncResponseEventType.SUCCESS) {
// onSyncCommentSuccess(response.comment);
// } else {
// onSyncCommentFailed(response.comment);
// }
// }
//
// private void onSyncCommentSuccess(Comment comment) {
// Timber.d("received sync comment success event for comment %s", comment);
// disposables.add(updateCommentUseCase.updateComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("update comment success"),
// t -> Timber.e(t, "update comment error")));
// }
//
// private void onSyncCommentFailed(Comment comment) {
// Timber.d("received sync comment failed event for comment %s", comment);
// disposables.add(deleteCommentUseCase.deleteComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("delete comment success"),
// t -> Timber.e(t, "delete comment error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
// public class CommentsViewModel extends ViewModel {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
// private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>();
//
// public CommentsViewModel(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
//
// loadComments();
// }
//
// @Override
// protected void onCleared() {
// disposables.clear();
// }
//
// /**
// * Adds new comment
// */
// public void addComment(String commentText) {
// disposables.add(addCommentUseCase.addComment(commentText)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("add comment success"),
// t -> Timber.e(t, "add comment error")));
// }
//
// /**
// * Exposes the latest comments so the UI can observe it
// */
// public LiveData<List<Comment>> comments() {
// return commentsLiveData;
// }
//
// void loadComments() {
// disposables.add(getCommentsUseCase.getComments()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(commentsLiveData::setValue,
// t -> Timber.e(t, "get comments error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
// public class CommentsViewModelFactory implements ViewModelProvider.Factory {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
//
// public CommentsViewModelFactory(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
// }
//
// @Override
// public <T extends ViewModel> T create(Class<T> modelClass) {
// if (modelClass.isAssignableFrom(CommentsViewModel.class)) {
// return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase);
// }
// throw new IllegalArgumentException("Unknown ViewModel class");
// }
// }
| import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.example.offline.R;
import com.example.offline.domain.services.SyncCommentLifecycleObserver;
import com.example.offline.presentation.CommentsViewModel;
import com.example.offline.presentation.CommentsViewModelFactory;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dagger.android.AndroidInjection; | package com.example.offline.view;
public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
@Inject
CommentsViewModelFactory viewModelFactory;
@Inject
SyncCommentLifecycleObserver syncCommentLifecycleObserver;
@BindView(R.id.add_comment_edittext)
EditText addCommentEditText;
@BindView(R.id.comments_recycler_view)
RecyclerView recyclerView;
private CommentListAdapter recyclerViewAdapter;
| // Path: app/src/main/java/com/example/offline/domain/services/SyncCommentLifecycleObserver.java
// public class SyncCommentLifecycleObserver implements LifecycleObserver {
// private final UpdateCommentUseCase updateCommentUseCase;
// private final DeleteCommentUseCase deleteCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
//
// public SyncCommentLifecycleObserver(UpdateCommentUseCase updateCommentUseCase,
// DeleteCommentUseCase deleteCommentUseCase) {
// this.updateCommentUseCase = updateCommentUseCase;
// this.deleteCommentUseCase = deleteCommentUseCase;
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
// public void onResume() {
// Timber.d("onResume lifecycle event.");
// disposables.add(SyncCommentRxBus.getInstance().toObservable()
// .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response")));
// }
//
// @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
// public void onPause() {
// Timber.d("onPause lifecycle event.");
// disposables.clear();
// }
//
// private void handleSyncResponse(SyncCommentResponse response) {
// if (response.eventType == SyncResponseEventType.SUCCESS) {
// onSyncCommentSuccess(response.comment);
// } else {
// onSyncCommentFailed(response.comment);
// }
// }
//
// private void onSyncCommentSuccess(Comment comment) {
// Timber.d("received sync comment success event for comment %s", comment);
// disposables.add(updateCommentUseCase.updateComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("update comment success"),
// t -> Timber.e(t, "update comment error")));
// }
//
// private void onSyncCommentFailed(Comment comment) {
// Timber.d("received sync comment failed event for comment %s", comment);
// disposables.add(deleteCommentUseCase.deleteComment(comment)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("delete comment success"),
// t -> Timber.e(t, "delete comment error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModel.java
// public class CommentsViewModel extends ViewModel {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
// private final CompositeDisposable disposables = new CompositeDisposable();
// private MutableLiveData<List<Comment>> commentsLiveData = new MutableLiveData<>();
//
// public CommentsViewModel(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
//
// loadComments();
// }
//
// @Override
// protected void onCleared() {
// disposables.clear();
// }
//
// /**
// * Adds new comment
// */
// public void addComment(String commentText) {
// disposables.add(addCommentUseCase.addComment(commentText)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(() -> Timber.d("add comment success"),
// t -> Timber.e(t, "add comment error")));
// }
//
// /**
// * Exposes the latest comments so the UI can observe it
// */
// public LiveData<List<Comment>> comments() {
// return commentsLiveData;
// }
//
// void loadComments() {
// disposables.add(getCommentsUseCase.getComments()
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(commentsLiveData::setValue,
// t -> Timber.e(t, "get comments error")));
// }
// }
//
// Path: app/src/main/java/com/example/offline/presentation/CommentsViewModelFactory.java
// public class CommentsViewModelFactory implements ViewModelProvider.Factory {
//
// private final GetCommentsUseCase getCommentsUseCase;
// private final AddCommentUseCase addCommentUseCase;
//
// public CommentsViewModelFactory(GetCommentsUseCase getCommentsUseCase,
// AddCommentUseCase addCommentUseCase) {
// this.getCommentsUseCase = getCommentsUseCase;
// this.addCommentUseCase = addCommentUseCase;
// }
//
// @Override
// public <T extends ViewModel> T create(Class<T> modelClass) {
// if (modelClass.isAssignableFrom(CommentsViewModel.class)) {
// return (T) new CommentsViewModel(getCommentsUseCase, addCommentUseCase);
// }
// throw new IllegalArgumentException("Unknown ViewModel class");
// }
// }
// Path: app/src/main/java/com/example/offline/view/CommentsActivity.java
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.example.offline.R;
import com.example.offline.domain.services.SyncCommentLifecycleObserver;
import com.example.offline.presentation.CommentsViewModel;
import com.example.offline.presentation.CommentsViewModelFactory;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dagger.android.AndroidInjection;
package com.example.offline.view;
public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
@Inject
CommentsViewModelFactory viewModelFactory;
@Inject
SyncCommentLifecycleObserver syncCommentLifecycleObserver;
@BindView(R.id.add_comment_edittext)
EditText addCommentEditText;
@BindView(R.id.comments_recycler_view)
RecyclerView recyclerView;
private CommentListAdapter recyclerViewAdapter;
| private CommentsViewModel viewModel; |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/data/CommentDatabase.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
| import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;
import com.example.offline.model.Comment;
import com.example.offline.model.ModelConstants; | package com.example.offline.data;
@Database(entities = {Comment.class}, version = 1, exportSchema = false)
public abstract class CommentDatabase extends RoomDatabase {
private static CommentDatabase instance;
public static synchronized CommentDatabase getInstance(Context context) {
if (instance == null) {
instance = Room | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;
import com.example.offline.model.Comment;
import com.example.offline.model.ModelConstants;
package com.example.offline.data;
@Database(entities = {Comment.class}, version = 1, exportSchema = false)
public abstract class CommentDatabase extends RoomDatabase {
private static CommentDatabase instance;
public static synchronized CommentDatabase getInstance(Context context) {
if (instance == null) {
instance = Room | .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME) |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/UpdateCommentUseCase.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.model.Comment;
import io.reactivex.Completable; | package com.example.offline.domain;
public class UpdateCommentUseCase {
private final LocalCommentRepository localCommentRepository;
public UpdateCommentUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
| // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/UpdateCommentUseCase.java
import com.example.offline.model.Comment;
import io.reactivex.Completable;
package com.example.offline.domain;
public class UpdateCommentUseCase {
private final LocalCommentRepository localCommentRepository;
public UpdateCommentUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
| public Completable updateComment(Comment comment) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/networking/RemoteCommentEndpoint.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.model.Comment;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST; | package com.example.offline.domain.services.networking;
interface RemoteCommentEndpoint {
@POST("/posts") | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/networking/RemoteCommentEndpoint.java
import com.example.offline.model.Comment;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
package com.example.offline.domain.services.networking;
interface RemoteCommentEndpoint {
@POST("/posts") | Call<Comment> addComment(@Body Comment comment); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides | Context provideContext(App application) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides | SchedulerJobService provideSchedulerJobService() { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides | GcmJobService provideGcmJobService() { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides | CommentDao provideCommentDao(Context context) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides
CommentDao provideCommentDao(Context context) { | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides
CommentDao provideCommentDao(Context context) { | return CommentDatabase.getInstance(context).commentDao(); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides
CommentDao provideCommentDao(Context context) {
return CommentDatabase.getInstance(context).commentDao();
}
@Singleton
@Provides | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides
CommentDao provideCommentDao(Context context) {
return CommentDatabase.getInstance(context).commentDao();
}
@Singleton
@Provides | LocalCommentRepository provideLocalCommentRepository(CommentDao commentDao) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/AppModule.java | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
| import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides; | package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides
CommentDao provideCommentDao(Context context) {
return CommentDatabase.getInstance(context).commentDao();
}
@Singleton
@Provides
LocalCommentRepository provideLocalCommentRepository(CommentDao commentDao) { | // Path: app/src/main/java/com/example/offline/App.java
// public class App extends Application implements HasActivityInjector {
// @Inject
// DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
//
// @Override
// public void onCreate() {
// super.onCreate();
//
// if (BuildConfig.DEBUG) {
// Timber.plant(new Timber.DebugTree());
// }
//
// DaggerAppComponent
// .builder()
// .application(this)
// .build()
// .inject(this);
//
// JobManagerFactory.getJobManager(this);
// }
//
// @Override
// public AndroidInjector<Activity> activityInjector() {
// return dispatchingAndroidInjector;
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDao.java
// @Dao
// public interface CommentDao {
// @Insert(onConflict = OnConflictStrategy.REPLACE)
// long add(Comment comment);
//
// @Update
// void update(Comment comment);
//
// @Delete
// void delete(Comment comment);
//
// @Query("SELECT * FROM comment WHERE photo_id = :photoId ORDER BY timestamp DESC")
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/data/CommentDatabase.java
// @Database(entities = {Comment.class}, version = 1, exportSchema = false)
// public abstract class CommentDatabase extends RoomDatabase {
// private static CommentDatabase instance;
//
// public static synchronized CommentDatabase getInstance(Context context) {
// if (instance == null) {
// instance = Room
// .databaseBuilder(context.getApplicationContext(), CommentDatabase.class, ModelConstants.DB_NAME)
// .build();
// }
// return instance;
// }
//
// public abstract CommentDao commentDao();
// }
//
// Path: app/src/main/java/com/example/offline/data/LocalCommentDataStore.java
// public class LocalCommentDataStore implements LocalCommentRepository {
//
// private final CommentDao commentDao;
//
// public LocalCommentDataStore(CommentDao commentDao) {
// this.commentDao = commentDao;
// }
//
// /**
// * Adds a comment to a given photo
// */
// public Single<Comment> add(long photoId, String commentText) {
// Timber.d("creating comment for photo id %s, comment text %s", photoId, commentText);
// Comment comment = new Comment(photoId, commentText);
//
// return Single.fromCallable(() -> {
// long rowId = commentDao.add(comment);
// Timber.d("comment stored " + rowId);
// return CommentUtils.clone(comment, rowId);
// });
// }
//
// /**
// * Updates a comment
// */
// public Completable update(Comment comment) {
// Timber.d("updating comment sync status for comment id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.update(comment));
// }
//
// /**
// * Deletes a comment
// */
// public Completable delete(Comment comment) {
// Timber.d("deleting comment with id %s", comment.getId());
//
// return Completable.fromAction(() -> commentDao.delete(comment));
// }
//
// /**
// * Returns Flowable stream of comments for a given photo
// */
// public Flowable<List<Comment>> getComments(long photoId) {
// Timber.d("getting comments for photo id %s", photoId);
// return commentDao.getComments(photoId);
// }
// }
//
// Path: app/src/main/java/com/example/offline/data/RemoteCommentDataStore.java
// public class RemoteCommentDataStore implements RemoteCommentRepository {
//
// @Override
// public Completable sync(Comment comment) {
// return Completable.fromAction(() ->
// JobManagerFactory.getJobManager().addJobInBackground(new SyncCommentJob(comment)));
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/LocalCommentRepository.java
// public interface LocalCommentRepository {
// Single<Comment> add(long photoId, String commentText);
// Completable update(Comment comment);
// Completable delete(Comment comment);
// Flowable<List<Comment>> getComments(long photoId);
// }
//
// Path: app/src/main/java/com/example/offline/domain/RemoteCommentRepository.java
// public interface RemoteCommentRepository {
// Completable sync(Comment comment);
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/GcmJobService.java
// public class GcmJobService extends GcmJobSchedulerService {
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
//
// Path: app/src/main/java/com/example/offline/domain/services/jobs/SchedulerJobService.java
// public class SchedulerJobService extends FrameworkJobSchedulerService {
//
// @NonNull
// @Override
// protected JobManager getJobManager() {
// return JobManagerFactory.getJobManager();
// }
// }
// Path: app/src/main/java/com/example/offline/di/AppModule.java
import android.content.Context;
import com.example.offline.App;
import com.example.offline.data.CommentDao;
import com.example.offline.data.CommentDatabase;
import com.example.offline.data.LocalCommentDataStore;
import com.example.offline.data.RemoteCommentDataStore;
import com.example.offline.domain.LocalCommentRepository;
import com.example.offline.domain.RemoteCommentRepository;
import com.example.offline.domain.services.jobs.GcmJobService;
import com.example.offline.domain.services.jobs.SchedulerJobService;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
package com.example.offline.di;
/**
* This is where you will inject application-wide dependencies.
*/
@Module
public class AppModule {
@Provides
Context provideContext(App application) {
return application.getApplicationContext();
}
@Singleton
@Provides
SchedulerJobService provideSchedulerJobService() {
return new SchedulerJobService();
}
@Singleton
@Provides
GcmJobService provideGcmJobService() {
return new GcmJobService();
}
@Singleton
@Provides
CommentDao provideCommentDao(Context context) {
return CommentDatabase.getInstance(context).commentDao();
}
@Singleton
@Provides
LocalCommentRepository provideLocalCommentRepository(CommentDao commentDao) { | return new LocalCommentDataStore(commentDao); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/services/SyncCommentRxBus.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.model.Comment;
import com.jakewharton.rxrelay2.PublishRelay;
import io.reactivex.Observable; | package com.example.offline.domain.services;
public class SyncCommentRxBus {
private static SyncCommentRxBus instance;
private final PublishRelay<SyncCommentResponse> relay;
public static synchronized SyncCommentRxBus getInstance() {
if (instance == null) {
instance = new SyncCommentRxBus();
}
return instance;
}
private SyncCommentRxBus() {
relay = PublishRelay.create();
}
| // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/services/SyncCommentRxBus.java
import com.example.offline.model.Comment;
import com.jakewharton.rxrelay2.PublishRelay;
import io.reactivex.Observable;
package com.example.offline.domain.services;
public class SyncCommentRxBus {
private static SyncCommentRxBus instance;
private final PublishRelay<SyncCommentResponse> relay;
public static synchronized SyncCommentRxBus getInstance() {
if (instance == null) {
instance = new SyncCommentRxBus();
}
return instance;
}
private SyncCommentRxBus() {
relay = PublishRelay.create();
}
| public void post(SyncResponseEventType eventType, Comment comment) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/SyncCommentUseCase.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
| import com.example.offline.model.Comment;
import io.reactivex.Completable; | package com.example.offline.domain;
/**
* Responsible for syncing a comment with remote repository.
*/
public class SyncCommentUseCase {
private final RemoteCommentRepository remoteCommentRepository;
public SyncCommentUseCase(RemoteCommentRepository remoteCommentRepository) {
this.remoteCommentRepository = remoteCommentRepository;
}
| // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
// Path: app/src/main/java/com/example/offline/domain/SyncCommentUseCase.java
import com.example.offline.model.Comment;
import io.reactivex.Completable;
package com.example.offline.domain;
/**
* Responsible for syncing a comment with remote repository.
*/
public class SyncCommentUseCase {
private final RemoteCommentRepository remoteCommentRepository;
public SyncCommentUseCase(RemoteCommentRepository remoteCommentRepository) {
this.remoteCommentRepository = remoteCommentRepository;
}
| public Completable syncComment(Comment comment) { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
| import com.example.offline.model.Comment;
import com.example.offline.model.ModelConstants;
import java.util.List;
import io.reactivex.Flowable; | package com.example.offline.domain;
public class GetCommentsUseCase {
private final LocalCommentRepository localCommentRepository;
public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
| // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
import com.example.offline.model.Comment;
import com.example.offline.model.ModelConstants;
import java.util.List;
import io.reactivex.Flowable;
package com.example.offline.domain;
public class GetCommentsUseCase {
private final LocalCommentRepository localCommentRepository;
public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
| public Flowable<List<Comment>> getComments() { |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
| import com.example.offline.model.Comment;
import com.example.offline.model.ModelConstants;
import java.util.List;
import io.reactivex.Flowable; | package com.example.offline.domain;
public class GetCommentsUseCase {
private final LocalCommentRepository localCommentRepository;
public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
public Flowable<List<Comment>> getComments() { | // Path: app/src/main/java/com/example/offline/model/Comment.java
// @Entity
// public class Comment implements Serializable {
//
// @PrimaryKey(autoGenerate = true)
// private long id;
//
// @ColumnInfo(name = "photo_id")
// private long photoId;
//
// @SerializedName("body")
// @ColumnInfo(name = "comment_text")
// private String commentText;
//
// @ColumnInfo(name = "timestamp")
// private long timestamp;
//
// @ColumnInfo(name = "sync_pending")
// private boolean syncPending;
//
// public long getId() {
// return id;
// }
//
// public long getPhotoId() {
// return photoId;
// }
//
// public String getCommentText() {
// return commentText;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public boolean isSyncPending() {
// return syncPending;
// }
//
// @Ignore
// public Comment(long photoId, String commentText) {
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = System.currentTimeMillis();
// this.syncPending = true;
// }
//
// public Comment(long id, long photoId, String commentText, long timestamp, boolean syncPending) {
// this.id = id;
// this.photoId = photoId;
// this.commentText = commentText;
// this.timestamp = timestamp;
// this.syncPending = syncPending;
// }
//
// @Override
// public String toString() {
// return String.format("Comment id: %s, text: %s, syncPending: %s", id, commentText, syncPending);
// }
// }
//
// Path: app/src/main/java/com/example/offline/model/ModelConstants.java
// public class ModelConstants {
// public static final String DB_NAME = "offlinedb";
// public static final long DUMMY_PHOTO_ID = 1L;
// }
// Path: app/src/main/java/com/example/offline/domain/GetCommentsUseCase.java
import com.example.offline.model.Comment;
import com.example.offline.model.ModelConstants;
import java.util.List;
import io.reactivex.Flowable;
package com.example.offline.domain;
public class GetCommentsUseCase {
private final LocalCommentRepository localCommentRepository;
public GetCommentsUseCase(LocalCommentRepository localCommentRepository) {
this.localCommentRepository = localCommentRepository;
}
public Flowable<List<Comment>> getComments() { | return localCommentRepository.getComments(ModelConstants.DUMMY_PHOTO_ID); |
jshvarts/OfflineSampleApp | app/src/main/java/com/example/offline/di/BuildersModule.java | // Path: app/src/main/java/com/example/offline/view/CommentsActivity.java
// public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
//
// @Inject
// CommentsViewModelFactory viewModelFactory;
//
// @Inject
// SyncCommentLifecycleObserver syncCommentLifecycleObserver;
//
// @BindView(R.id.add_comment_edittext)
// EditText addCommentEditText;
//
// @BindView(R.id.comments_recycler_view)
// RecyclerView recyclerView;
//
// private CommentListAdapter recyclerViewAdapter;
//
// private CommentsViewModel viewModel;
//
// private LifecycleRegistry registry = new LifecycleRegistry(this);
//
// @Override
// public LifecycleRegistry getLifecycle() {
// return registry;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// AndroidInjection.inject(this);
// super.onCreate(savedInstanceState);
// setContentView(R.layout.comments_activity);
//
// ButterKnife.bind(this);
//
// initRecyclerView();
//
// getLifecycle().addObserver(syncCommentLifecycleObserver);
//
// viewModel = ViewModelProviders.of(this, viewModelFactory).get(CommentsViewModel.class);
//
// viewModel.comments().observe(this, recyclerViewAdapter::updateCommentList);
// }
//
// @OnClick(R.id.add_comment_button)
// void onAddCommentButtonClicked() {
//
// hideKeyboard();
//
// // TODO add comment validation
// viewModel.addComment(addCommentEditText.getText().toString());
//
// clearEditText();
// }
//
// private void hideKeyboard() {
// InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// if (getCurrentFocus() != null) {
// imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
// }
// }
//
// private void clearEditText() {
// addCommentEditText.getText().clear();
// }
//
// private void initRecyclerView() {
// recyclerView.setHasFixedSize(true);
//
// RecyclerView.LayoutManager recyclerViewLayoutManager = new LinearLayoutManager(this);
// recyclerView.setLayoutManager(recyclerViewLayoutManager);
//
// recyclerViewAdapter = new CommentListAdapter(new ArrayList<>());
// recyclerView.setAdapter(recyclerViewAdapter);
// }
// }
| import com.example.offline.view.CommentsActivity;
import dagger.Module;
import dagger.android.ContributesAndroidInjector; | package com.example.offline.di;
/**
* Binds all sub-components within the app.
*/
@Module
public abstract class BuildersModule {
@ContributesAndroidInjector(modules = CommentsActivityModule.class) | // Path: app/src/main/java/com/example/offline/view/CommentsActivity.java
// public class CommentsActivity extends AppCompatActivity implements LifecycleRegistryOwner {
//
// @Inject
// CommentsViewModelFactory viewModelFactory;
//
// @Inject
// SyncCommentLifecycleObserver syncCommentLifecycleObserver;
//
// @BindView(R.id.add_comment_edittext)
// EditText addCommentEditText;
//
// @BindView(R.id.comments_recycler_view)
// RecyclerView recyclerView;
//
// private CommentListAdapter recyclerViewAdapter;
//
// private CommentsViewModel viewModel;
//
// private LifecycleRegistry registry = new LifecycleRegistry(this);
//
// @Override
// public LifecycleRegistry getLifecycle() {
// return registry;
// }
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// AndroidInjection.inject(this);
// super.onCreate(savedInstanceState);
// setContentView(R.layout.comments_activity);
//
// ButterKnife.bind(this);
//
// initRecyclerView();
//
// getLifecycle().addObserver(syncCommentLifecycleObserver);
//
// viewModel = ViewModelProviders.of(this, viewModelFactory).get(CommentsViewModel.class);
//
// viewModel.comments().observe(this, recyclerViewAdapter::updateCommentList);
// }
//
// @OnClick(R.id.add_comment_button)
// void onAddCommentButtonClicked() {
//
// hideKeyboard();
//
// // TODO add comment validation
// viewModel.addComment(addCommentEditText.getText().toString());
//
// clearEditText();
// }
//
// private void hideKeyboard() {
// InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// if (getCurrentFocus() != null) {
// imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
// }
// }
//
// private void clearEditText() {
// addCommentEditText.getText().clear();
// }
//
// private void initRecyclerView() {
// recyclerView.setHasFixedSize(true);
//
// RecyclerView.LayoutManager recyclerViewLayoutManager = new LinearLayoutManager(this);
// recyclerView.setLayoutManager(recyclerViewLayoutManager);
//
// recyclerViewAdapter = new CommentListAdapter(new ArrayList<>());
// recyclerView.setAdapter(recyclerViewAdapter);
// }
// }
// Path: app/src/main/java/com/example/offline/di/BuildersModule.java
import com.example.offline.view.CommentsActivity;
import dagger.Module;
import dagger.android.ContributesAndroidInjector;
package com.example.offline.di;
/**
* Binds all sub-components within the app.
*/
@Module
public abstract class BuildersModule {
@ContributesAndroidInjector(modules = CommentsActivityModule.class) | abstract CommentsActivity bindCommentsActivity(); |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/SortedTurtlePredicateList.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/IRIComparator.java
// public class IRIComparator implements Comparator<IRI> {
//
// @Override
// public int compare(IRI iri1, IRI iri2) {
// return compare(iri1, iri2, new ArrayList<>());
// }
//
// public int compare(IRI iri1, IRI iri2, List<Object> excludedList) {
// if ((iri1 == null) || excludedList.contains(iri1)) {
// if ((iri2 == null) || excludedList.contains(iri2)) {
// return 0; // two null/excluded IRIs are equal
// } else {
// return -1; // null/excluded IRI comes before non-null/excluded IRI
// }
// } else {
// if ((iri2 == null) || excludedList.contains(iri2)) {
// return 1; // non-null/excluded IRI comes before null/excluded IRI
// } else {
// if (iri1 == iri2) {
// return 0;
// } else {
// return iri1.stringValue().compareTo(iri2.stringValue());
// }
// }
// }
// }
// }
| import org.eclipse.rdf4j.model.IRI;
import org.edmcouncil.rdf_toolkit.comparator.IRIComparator;
import java.util.TreeSet; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A sorted list of RDF IRI values.
*/
public class SortedTurtlePredicateList extends TreeSet<IRI> {
public SortedTurtlePredicateList() { | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/IRIComparator.java
// public class IRIComparator implements Comparator<IRI> {
//
// @Override
// public int compare(IRI iri1, IRI iri2) {
// return compare(iri1, iri2, new ArrayList<>());
// }
//
// public int compare(IRI iri1, IRI iri2, List<Object> excludedList) {
// if ((iri1 == null) || excludedList.contains(iri1)) {
// if ((iri2 == null) || excludedList.contains(iri2)) {
// return 0; // two null/excluded IRIs are equal
// } else {
// return -1; // null/excluded IRI comes before non-null/excluded IRI
// }
// } else {
// if ((iri2 == null) || excludedList.contains(iri2)) {
// return 1; // non-null/excluded IRI comes before null/excluded IRI
// } else {
// if (iri1 == iri2) {
// return 0;
// } else {
// return iri1.stringValue().compareTo(iri2.stringValue());
// }
// }
// }
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/SortedTurtlePredicateList.java
import org.eclipse.rdf4j.model.IRI;
import org.edmcouncil.rdf_toolkit.comparator.IRIComparator;
import java.util.TreeSet;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A sorted list of RDF IRI values.
*/
public class SortedTurtlePredicateList extends TreeSet<IRI> {
public SortedTurtlePredicateList() { | super(new IRIComparator()); |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/ReverseNamespaceTable.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/StringLengthComparator.java
// public class StringLengthComparator implements Comparator<String> {
//
// @Override
// public int compare(String str1, String str2) {
// if (str1 == null) {
// throw new NullPointerException("cannot compare null to String");
// }
// if (str2 == null) {
// throw new NullPointerException("cannot compare String to null");
// }
// if (str1.length() > str2.length()) {
// return -1;
// } else if (str1.length() < str2.length()) {
// return 1;
// } else { // if same length
// return str1.compareTo(str2);
// }
// }
// }
| import org.edmcouncil.rdf_toolkit.comparator.StringLengthComparator;
import java.util.TreeMap; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A reverse namespace table with which returns the longest namespace IRIs first. Key is IRI string, value is prefix string.
*/
public class ReverseNamespaceTable extends TreeMap<String, String> {
public ReverseNamespaceTable() { | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/StringLengthComparator.java
// public class StringLengthComparator implements Comparator<String> {
//
// @Override
// public int compare(String str1, String str2) {
// if (str1 == null) {
// throw new NullPointerException("cannot compare null to String");
// }
// if (str2 == null) {
// throw new NullPointerException("cannot compare String to null");
// }
// if (str1.length() > str2.length()) {
// return -1;
// } else if (str1.length() < str2.length()) {
// return 1;
// } else { // if same length
// return str1.compareTo(str2);
// }
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/ReverseNamespaceTable.java
import org.edmcouncil.rdf_toolkit.comparator.StringLengthComparator;
import java.util.TreeMap;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A reverse namespace table with which returns the longest namespace IRIs first. Key is IRI string, value is prefix string.
*/
public class ReverseNamespaceTable extends TreeMap<String, String> {
public ReverseNamespaceTable() { | super(new StringLengthComparator()); |
edmcouncil/rdf-toolkit | src/test/java/org/edmcouncil/rdf_toolkit/comparator/AbstractComparatorTest.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleObjectList.java
// public class UnsortedTurtleObjectList extends HashSet<Value> {
//
// public SortedTurtleObjectList toSorted(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// var sortedObjectList = new SortedTurtleObjectList(collectionClass, comparisonContext);
// sortedObjectList.addAll(this);
// return sortedObjectList;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
// public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
//
// public SortedTurtleObjectList getSorted(IRI predicate,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(predicate)) {
// return get(predicate).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtlePredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// SortedTurtlePredicateObjectMap sortedPOMap = new SortedTurtlePredicateObjectMap();
// for (IRI predicate : keySet()) {
// sortedPOMap.put(predicate, getSorted(predicate, collectionClass, comparisonContext));
// }
// return sortedPOMap;
// }
//
// public int fullSize() {
// int result = 0;
// for (Resource pred : keySet()) {
// result += get(pred).size();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (IRI predicate : keySet()) {
// if (get(predicate) == null) {
// return false;
// }
// }
// return true;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
| import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleObjectList;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtlePredicateObjectMap;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
abstract public class AbstractComparatorTest {
public static final String IRI_PREFIX = "http://example.com/ont1/";
protected ComparisonContext prepareComparisonContext(Model model, boolean shouldInlineBlankNodes) { | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleObjectList.java
// public class UnsortedTurtleObjectList extends HashSet<Value> {
//
// public SortedTurtleObjectList toSorted(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// var sortedObjectList = new SortedTurtleObjectList(collectionClass, comparisonContext);
// sortedObjectList.addAll(this);
// return sortedObjectList;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
// public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
//
// public SortedTurtleObjectList getSorted(IRI predicate,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(predicate)) {
// return get(predicate).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtlePredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// SortedTurtlePredicateObjectMap sortedPOMap = new SortedTurtlePredicateObjectMap();
// for (IRI predicate : keySet()) {
// sortedPOMap.put(predicate, getSorted(predicate, collectionClass, comparisonContext));
// }
// return sortedPOMap;
// }
//
// public int fullSize() {
// int result = 0;
// for (Resource pred : keySet()) {
// result += get(pred).size();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (IRI predicate : keySet()) {
// if (get(predicate) == null) {
// return false;
// }
// }
// return true;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
// Path: src/test/java/org/edmcouncil/rdf_toolkit/comparator/AbstractComparatorTest.java
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleObjectList;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtlePredicateObjectMap;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
abstract public class AbstractComparatorTest {
public static final String IRI_PREFIX = "http://example.com/ont1/";
protected ComparisonContext prepareComparisonContext(Model model, boolean shouldInlineBlankNodes) { | var tripleMap = new UnsortedTurtleSubjectPredicateObjectMap(); |
edmcouncil/rdf-toolkit | src/test/java/org/edmcouncil/rdf_toolkit/comparator/AbstractComparatorTest.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleObjectList.java
// public class UnsortedTurtleObjectList extends HashSet<Value> {
//
// public SortedTurtleObjectList toSorted(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// var sortedObjectList = new SortedTurtleObjectList(collectionClass, comparisonContext);
// sortedObjectList.addAll(this);
// return sortedObjectList;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
// public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
//
// public SortedTurtleObjectList getSorted(IRI predicate,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(predicate)) {
// return get(predicate).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtlePredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// SortedTurtlePredicateObjectMap sortedPOMap = new SortedTurtlePredicateObjectMap();
// for (IRI predicate : keySet()) {
// sortedPOMap.put(predicate, getSorted(predicate, collectionClass, comparisonContext));
// }
// return sortedPOMap;
// }
//
// public int fullSize() {
// int result = 0;
// for (Resource pred : keySet()) {
// result += get(pred).size();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (IRI predicate : keySet()) {
// if (get(predicate) == null) {
// return false;
// }
// }
// return true;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
| import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleObjectList;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtlePredicateObjectMap;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
abstract public class AbstractComparatorTest {
public static final String IRI_PREFIX = "http://example.com/ont1/";
protected ComparisonContext prepareComparisonContext(Model model, boolean shouldInlineBlankNodes) {
var tripleMap = new UnsortedTurtleSubjectPredicateObjectMap();
for (Statement statement : model) {
Resource subject = statement.getSubject();
if (!tripleMap.containsKey(subject)) { | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleObjectList.java
// public class UnsortedTurtleObjectList extends HashSet<Value> {
//
// public SortedTurtleObjectList toSorted(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// var sortedObjectList = new SortedTurtleObjectList(collectionClass, comparisonContext);
// sortedObjectList.addAll(this);
// return sortedObjectList;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
// public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
//
// public SortedTurtleObjectList getSorted(IRI predicate,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(predicate)) {
// return get(predicate).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtlePredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// SortedTurtlePredicateObjectMap sortedPOMap = new SortedTurtlePredicateObjectMap();
// for (IRI predicate : keySet()) {
// sortedPOMap.put(predicate, getSorted(predicate, collectionClass, comparisonContext));
// }
// return sortedPOMap;
// }
//
// public int fullSize() {
// int result = 0;
// for (Resource pred : keySet()) {
// result += get(pred).size();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (IRI predicate : keySet()) {
// if (get(predicate) == null) {
// return false;
// }
// }
// return true;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
// Path: src/test/java/org/edmcouncil/rdf_toolkit/comparator/AbstractComparatorTest.java
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleObjectList;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtlePredicateObjectMap;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
abstract public class AbstractComparatorTest {
public static final String IRI_PREFIX = "http://example.com/ont1/";
protected ComparisonContext prepareComparisonContext(Model model, boolean shouldInlineBlankNodes) {
var tripleMap = new UnsortedTurtleSubjectPredicateObjectMap();
for (Statement statement : model) {
Resource subject = statement.getSubject();
if (!tripleMap.containsKey(subject)) { | tripleMap.put(subject, new UnsortedTurtlePredicateObjectMap()); |
edmcouncil/rdf-toolkit | src/test/java/org/edmcouncil/rdf_toolkit/comparator/AbstractComparatorTest.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleObjectList.java
// public class UnsortedTurtleObjectList extends HashSet<Value> {
//
// public SortedTurtleObjectList toSorted(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// var sortedObjectList = new SortedTurtleObjectList(collectionClass, comparisonContext);
// sortedObjectList.addAll(this);
// return sortedObjectList;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
// public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
//
// public SortedTurtleObjectList getSorted(IRI predicate,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(predicate)) {
// return get(predicate).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtlePredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// SortedTurtlePredicateObjectMap sortedPOMap = new SortedTurtlePredicateObjectMap();
// for (IRI predicate : keySet()) {
// sortedPOMap.put(predicate, getSorted(predicate, collectionClass, comparisonContext));
// }
// return sortedPOMap;
// }
//
// public int fullSize() {
// int result = 0;
// for (Resource pred : keySet()) {
// result += get(pred).size();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (IRI predicate : keySet()) {
// if (get(predicate) == null) {
// return false;
// }
// }
// return true;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
| import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleObjectList;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtlePredicateObjectMap;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
abstract public class AbstractComparatorTest {
public static final String IRI_PREFIX = "http://example.com/ont1/";
protected ComparisonContext prepareComparisonContext(Model model, boolean shouldInlineBlankNodes) {
var tripleMap = new UnsortedTurtleSubjectPredicateObjectMap();
for (Statement statement : model) {
Resource subject = statement.getSubject();
if (!tripleMap.containsKey(subject)) {
tripleMap.put(subject, new UnsortedTurtlePredicateObjectMap());
}
addStatement(tripleMap.get(subject), statement);
}
return new ComparisonContext(shouldInlineBlankNodes, tripleMap);
}
protected void addStatement(UnsortedTurtlePredicateObjectMap predicateObjectMap, Statement statement) {
var predicate = statement.getPredicate();
if (!predicateObjectMap.containsKey(predicate)) { | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleObjectList.java
// public class UnsortedTurtleObjectList extends HashSet<Value> {
//
// public SortedTurtleObjectList toSorted(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// var sortedObjectList = new SortedTurtleObjectList(collectionClass, comparisonContext);
// sortedObjectList.addAll(this);
// return sortedObjectList;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
// public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
//
// public SortedTurtleObjectList getSorted(IRI predicate,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(predicate)) {
// return get(predicate).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtlePredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// SortedTurtlePredicateObjectMap sortedPOMap = new SortedTurtlePredicateObjectMap();
// for (IRI predicate : keySet()) {
// sortedPOMap.put(predicate, getSorted(predicate, collectionClass, comparisonContext));
// }
// return sortedPOMap;
// }
//
// public int fullSize() {
// int result = 0;
// for (Resource pred : keySet()) {
// result += get(pred).size();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (IRI predicate : keySet()) {
// if (get(predicate) == null) {
// return false;
// }
// }
// return true;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
// Path: src/test/java/org/edmcouncil/rdf_toolkit/comparator/AbstractComparatorTest.java
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleObjectList;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtlePredicateObjectMap;
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
abstract public class AbstractComparatorTest {
public static final String IRI_PREFIX = "http://example.com/ont1/";
protected ComparisonContext prepareComparisonContext(Model model, boolean shouldInlineBlankNodes) {
var tripleMap = new UnsortedTurtleSubjectPredicateObjectMap();
for (Statement statement : model) {
Resource subject = statement.getSubject();
if (!tripleMap.containsKey(subject)) {
tripleMap.put(subject, new UnsortedTurtlePredicateObjectMap());
}
addStatement(tripleMap.get(subject), statement);
}
return new ComparisonContext(shouldInlineBlankNodes, tripleMap);
}
protected void addStatement(UnsortedTurtlePredicateObjectMap predicateObjectMap, Statement statement) {
var predicate = statement.getPredicate();
if (!predicateObjectMap.containsKey(predicate)) { | predicateObjectMap.put(predicate, new UnsortedTurtleObjectList()); |
edmcouncil/rdf-toolkit | src/test/java/org/edmcouncil/rdf_toolkit/TestComparisonsUtils.java | // Path: src/test/java/org/edmcouncil/rdf_toolkit/FileSystemUtils.java
// public static List<String> readFileLines(File file, String encoding) throws IOException {
// return Files.readAllLines(file.toPath(), Charset.forName(encoding));
// }
| import org.eclipse.rdf4j.model.Namespace;
import org.eclipse.rdf4j.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.edmcouncil.rdf_toolkit.FileSystemUtils.readFileLines;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Model; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit;
public class TestComparisonsUtils {
private static final Map<IRI, String> EXPANDED_QNAMES = new HashMap<>();
private static final Logger LOGGER = LoggerFactory.getLogger(TestComparisonsUtils.class);
public static boolean compareFiles(File file1, File file2, String encoding) throws IOException {
// MAYBE: Log debugging info | // Path: src/test/java/org/edmcouncil/rdf_toolkit/FileSystemUtils.java
// public static List<String> readFileLines(File file, String encoding) throws IOException {
// return Files.readAllLines(file.toPath(), Charset.forName(encoding));
// }
// Path: src/test/java/org/edmcouncil/rdf_toolkit/TestComparisonsUtils.java
import org.eclipse.rdf4j.model.Namespace;
import org.eclipse.rdf4j.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.edmcouncil.rdf_toolkit.FileSystemUtils.readFileLines;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Model;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit;
public class TestComparisonsUtils {
private static final Map<IRI, String> EXPANDED_QNAMES = new HashMap<>();
private static final Logger LOGGER = LoggerFactory.getLogger(TestComparisonsUtils.class);
public static boolean compareFiles(File file1, File file2, String encoding) throws IOException {
// MAYBE: Log debugging info | var source1Lines = readFileLines(file1, encoding).iterator(); |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/SortedTurtleSubjectPredicateObjectMap.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/CachedResourceComparator.java
// public class CachedResourceComparator implements Comparator<Resource> {
//
// private final Map<Pair<Resource, Resource>, Integer> cache = new HashMap<>();
// private final ResourceComparator comparator;
//
// public CachedResourceComparator(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// this.comparator = new ResourceComparator(collectionClass, comparisonContext);
// }
//
// @Override
// public int compare(Resource resource1, Resource resource2) {
// Pair<Resource, Resource> key = new Pair<>(resource1, resource2);
// if (cache.containsKey(key)) {
// return cache.get(key);
// } else {
// int result = comparator.compare(resource1, resource2);
// cache.put(key, result);
// return result;
// }
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
| import org.eclipse.rdf4j.model.Resource;
import org.edmcouncil.rdf_toolkit.comparator.CachedResourceComparator;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A sorted map from subject resources to predicate/object pairs.
*/
public class SortedTurtleSubjectPredicateObjectMap extends SortedHashMap<Resource, SortedTurtlePredicateObjectMap> {
public SortedTurtleSubjectPredicateObjectMap(Class collectionClass, ComparisonContext comparisonContext) { // TODO | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/CachedResourceComparator.java
// public class CachedResourceComparator implements Comparator<Resource> {
//
// private final Map<Pair<Resource, Resource>, Integer> cache = new HashMap<>();
// private final ResourceComparator comparator;
//
// public CachedResourceComparator(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// this.comparator = new ResourceComparator(collectionClass, comparisonContext);
// }
//
// @Override
// public int compare(Resource resource1, Resource resource2) {
// Pair<Resource, Resource> key = new Pair<>(resource1, resource2);
// if (cache.containsKey(key)) {
// return cache.get(key);
// } else {
// int result = comparator.compare(resource1, resource2);
// cache.put(key, result);
// return result;
// }
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/SortedTurtleSubjectPredicateObjectMap.java
import org.eclipse.rdf4j.model.Resource;
import org.edmcouncil.rdf_toolkit.comparator.CachedResourceComparator;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A sorted map from subject resources to predicate/object pairs.
*/
public class SortedTurtleSubjectPredicateObjectMap extends SortedHashMap<Resource, SortedTurtlePredicateObjectMap> {
public SortedTurtleSubjectPredicateObjectMap(Class collectionClass, ComparisonContext comparisonContext) { // TODO | super(new CachedResourceComparator(collectionClass, comparisonContext)); |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/writer/SortedRdfWriterFactory.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/io/format/TargetFormats.java
// public enum TargetFormats {
// JSON_LD("json-ld", "(JSON-LD)", RDFFormat.JSONLD),
// RDF_XML("rdf-xml", "(RDF/XML)", RDFFormat.RDFXML),
// TURTLE("turtle", "(Turtle)", RDFFormat.TURTLE);
//
// public static final TargetFormats DEFAULT_FORMAT = TURTLE;
//
// private final String optionValue;
// private final String optionComment;
// private final RDFFormat rdfFormat;
//
// TargetFormats(String optionValue, String optionComment, RDFFormat rdfFormat) {
// this.optionValue = optionValue;
// this.optionComment = optionComment;
// this.rdfFormat = rdfFormat;
// }
//
// public String getOptionValue() {
// return optionValue;
// }
//
// public String getOptionComment() {
// return optionComment;
// }
//
// public RDFFormat getRDFFormat() {
// return rdfFormat;
// }
//
// public static TargetFormats getByOptionValue(String optionValue) {
// if (optionValue == null) {
// return null;
// }
// for (TargetFormats tfmt : values()) {
// if (optionValue.equals(tfmt.optionValue)) {
// return tfmt;
// }
// }
// return null;
// }
//
// public static String summarise() {
// ArrayList<String> result = new ArrayList<>();
// for (TargetFormats tfmt : values()) {
// String value = tfmt.optionValue;
// if (tfmt.optionComment != null) {
// value += " " + tfmt.optionComment;
// }
// if (DEFAULT_FORMAT.equals(tfmt)) {
// value += " [default]";
// }
// result.add(value);
// }
// return String.join(", ", result);
// }
// }
| import java.io.OutputStream;
import java.io.Writer;
import java.util.Map;
import java.util.Objects;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.RDFWriterFactory;
import org.edmcouncil.rdf_toolkit.io.format.TargetFormats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.writer;
/**
* Factory class for creating Sesame writers which generate sorted RDF.
*/
public class SortedRdfWriterFactory implements RDFWriterFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(SortedRdfWriterFactory.class);
| // Path: src/main/java/org/edmcouncil/rdf_toolkit/io/format/TargetFormats.java
// public enum TargetFormats {
// JSON_LD("json-ld", "(JSON-LD)", RDFFormat.JSONLD),
// RDF_XML("rdf-xml", "(RDF/XML)", RDFFormat.RDFXML),
// TURTLE("turtle", "(Turtle)", RDFFormat.TURTLE);
//
// public static final TargetFormats DEFAULT_FORMAT = TURTLE;
//
// private final String optionValue;
// private final String optionComment;
// private final RDFFormat rdfFormat;
//
// TargetFormats(String optionValue, String optionComment, RDFFormat rdfFormat) {
// this.optionValue = optionValue;
// this.optionComment = optionComment;
// this.rdfFormat = rdfFormat;
// }
//
// public String getOptionValue() {
// return optionValue;
// }
//
// public String getOptionComment() {
// return optionComment;
// }
//
// public RDFFormat getRDFFormat() {
// return rdfFormat;
// }
//
// public static TargetFormats getByOptionValue(String optionValue) {
// if (optionValue == null) {
// return null;
// }
// for (TargetFormats tfmt : values()) {
// if (optionValue.equals(tfmt.optionValue)) {
// return tfmt;
// }
// }
// return null;
// }
//
// public static String summarise() {
// ArrayList<String> result = new ArrayList<>();
// for (TargetFormats tfmt : values()) {
// String value = tfmt.optionValue;
// if (tfmt.optionComment != null) {
// value += " " + tfmt.optionComment;
// }
// if (DEFAULT_FORMAT.equals(tfmt)) {
// value += " [default]";
// }
// result.add(value);
// }
// return String.join(", ", result);
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/writer/SortedRdfWriterFactory.java
import java.io.OutputStream;
import java.io.Writer;
import java.util.Map;
import java.util.Objects;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.RDFWriterFactory;
import org.edmcouncil.rdf_toolkit.io.format.TargetFormats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.writer;
/**
* Factory class for creating Sesame writers which generate sorted RDF.
*/
public class SortedRdfWriterFactory implements RDFWriterFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(SortedRdfWriterFactory.class);
| private TargetFormats targetFormat = TargetFormats.DEFAULT_FORMAT; |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleResourceList.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
| import org.eclipse.rdf4j.model.Resource;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import java.util.HashSet; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* An unsorted list of RDF resource values.
*/
public class UnsortedTurtleResourceList extends HashSet<Resource> {
public SortedTurtleResourceList toSorted(Class collectionClass, // TODO | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleResourceList.java
import org.eclipse.rdf4j.model.Resource;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import java.util.HashSet;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* An unsorted list of RDF resource values.
*/
public class UnsortedTurtleResourceList extends HashSet<Resource> {
public SortedTurtleResourceList toSorted(Class collectionClass, // TODO | ComparisonContext comparisonContext) { |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
| import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Value;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import java.util.HashMap; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* An unsorted map from predicate IRIs to lists of object values.
*/
public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
public SortedTurtleObjectList getSorted(IRI predicate,
Class<Value> collectionClass, | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtlePredicateObjectMap.java
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Value;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import java.util.HashMap;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* An unsorted map from predicate IRIs to lists of object values.
*/
public class UnsortedTurtlePredicateObjectMap extends HashMap<IRI, UnsortedTurtleObjectList> {
public SortedTurtleObjectList getSorted(IRI predicate,
Class<Value> collectionClass, | ComparisonContext comparisonContext) { |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/SortedTurtleObjectList.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ValueComparator.java
// public class ValueComparator implements Comparator<Value> {
//
// private final Class<Value> collectionClass;
// private final ComparisonContext comparisonContext;
// private BNodeComparator blankNodeComparator;
//
// public ValueComparator(ComparisonContext comparisonContext) {
// this(Value.class, comparisonContext);
// }
//
// public ValueComparator(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// this.collectionClass = collectionClass;
// this.comparisonContext = comparisonContext;
// }
//
// @Override
// public int compare(Value value1, Value value2) {
// return compare(value1, value2, new ArrayList<>());
// }
//
// public int compare(Value value1, Value value2, List<Object> excludedList) {
// if (value1 == value2) {
// return 0;
// }
//
// if ((value1 == null) || excludedList.contains(value1)) {
// if ((value2 == null) || excludedList.contains(value2)) {
// return 0; // two null/excluded values are equal
// } else {
// return -1; // null/excluded value comes before non-null/excluded value
// }
// } else {
// if ((value2 == null) || excludedList.contains(value2)) {
// return 1; // non-null/excluded value comes before null/excluded value
// }
// }
//
// return compareExistingValues(value1, value2, excludedList);
// }
//
// public int compareExistingValues(Value value1, Value value2, List<Object> excludedList) {
// // We assume here that both blank nodes are non-null/excluded
// if (value1 == null || value2 == null || excludedList.contains(value1) || excludedList.contains(value2)) {
// throw new IllegalStateException("value1 and value2 should not be null or in the excluded list.");
// }
//
// // Order blank nodes so that they come after other values.
// if (value1 instanceof BNode) {
// if (value2 instanceof BNode) {
// return compareTwoBlankNodes((BNode) value1, (BNode) value2, excludedList);
// } else {
// return 1; // blank node value1 comes after value2.
// }
// } else {
// if (value2 instanceof BNode) {
// return -1; // value1 comes before blank node value2.
// } else { // compare non-blank-node values.
// if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
// return compareSimpleValue((Literal) value1, (Literal) value2);
// } else {
// return compareSimpleValue(value1, value2);
// }
// }
// }
// }
//
// private int compareTwoBlankNodes(BNode value1, BNode value2, List<Object> excludedList) {
// if (this.blankNodeComparator == null) {
// this.blankNodeComparator = new BNodeComparator(collectionClass, comparisonContext);
// }
// int cmp = blankNodeComparator.compare(value1, value2, excludedList);
// if (cmp != 0) {
// return cmp;
// } else {
// // to make sure that the sorted blank node list doesn't exclude a blank node just because it has the
// // same content as another
// return value1.stringValue().compareTo(value2.stringValue());
// }
// }
// }
| import org.eclipse.rdf4j.model.Value;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import org.edmcouncil.rdf_toolkit.comparator.ValueComparator;
import java.util.TreeSet; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A sorted list of RDF object values.
*/
public class SortedTurtleObjectList extends TreeSet<Value> {
public SortedTurtleObjectList(ComparisonContext comparisonContext) { | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
//
// Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ValueComparator.java
// public class ValueComparator implements Comparator<Value> {
//
// private final Class<Value> collectionClass;
// private final ComparisonContext comparisonContext;
// private BNodeComparator blankNodeComparator;
//
// public ValueComparator(ComparisonContext comparisonContext) {
// this(Value.class, comparisonContext);
// }
//
// public ValueComparator(Class<Value> collectionClass, ComparisonContext comparisonContext) {
// this.collectionClass = collectionClass;
// this.comparisonContext = comparisonContext;
// }
//
// @Override
// public int compare(Value value1, Value value2) {
// return compare(value1, value2, new ArrayList<>());
// }
//
// public int compare(Value value1, Value value2, List<Object> excludedList) {
// if (value1 == value2) {
// return 0;
// }
//
// if ((value1 == null) || excludedList.contains(value1)) {
// if ((value2 == null) || excludedList.contains(value2)) {
// return 0; // two null/excluded values are equal
// } else {
// return -1; // null/excluded value comes before non-null/excluded value
// }
// } else {
// if ((value2 == null) || excludedList.contains(value2)) {
// return 1; // non-null/excluded value comes before null/excluded value
// }
// }
//
// return compareExistingValues(value1, value2, excludedList);
// }
//
// public int compareExistingValues(Value value1, Value value2, List<Object> excludedList) {
// // We assume here that both blank nodes are non-null/excluded
// if (value1 == null || value2 == null || excludedList.contains(value1) || excludedList.contains(value2)) {
// throw new IllegalStateException("value1 and value2 should not be null or in the excluded list.");
// }
//
// // Order blank nodes so that they come after other values.
// if (value1 instanceof BNode) {
// if (value2 instanceof BNode) {
// return compareTwoBlankNodes((BNode) value1, (BNode) value2, excludedList);
// } else {
// return 1; // blank node value1 comes after value2.
// }
// } else {
// if (value2 instanceof BNode) {
// return -1; // value1 comes before blank node value2.
// } else { // compare non-blank-node values.
// if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
// return compareSimpleValue((Literal) value1, (Literal) value2);
// } else {
// return compareSimpleValue(value1, value2);
// }
// }
// }
// }
//
// private int compareTwoBlankNodes(BNode value1, BNode value2, List<Object> excludedList) {
// if (this.blankNodeComparator == null) {
// this.blankNodeComparator = new BNodeComparator(collectionClass, comparisonContext);
// }
// int cmp = blankNodeComparator.compare(value1, value2, excludedList);
// if (cmp != 0) {
// return cmp;
// } else {
// // to make sure that the sorted blank node list doesn't exclude a blank node just because it has the
// // same content as another
// return value1.stringValue().compareTo(value2.stringValue());
// }
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/SortedTurtleObjectList.java
import org.eclipse.rdf4j.model.Value;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import org.edmcouncil.rdf_toolkit.comparator.ValueComparator;
import java.util.TreeSet;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* A sorted list of RDF object values.
*/
public class SortedTurtleObjectList extends TreeSet<Value> {
public SortedTurtleObjectList(ComparisonContext comparisonContext) { | super(new ValueComparator(comparisonContext)); |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
| import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
public class ComparisonContext {
private final boolean shouldInlineBlankNodes; | // Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleSubjectPredicateObjectMap.java
// public class UnsortedTurtleSubjectPredicateObjectMap extends HashMap<Resource, UnsortedTurtlePredicateObjectMap> {
//
// public SortedTurtlePredicateObjectMap getSorted(Resource subject,
// Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// if (containsKey(subject)) {
// return get(subject).toSorted(collectionClass, comparisonContext);
// } else {
// return null;
// }
// }
//
// public SortedTurtleSubjectPredicateObjectMap toSorted(Class<Value> collectionClass,
// ComparisonContext comparisonContext) {
// var sortedSPOMap = new SortedTurtleSubjectPredicateObjectMap(collectionClass, comparisonContext);
// for (Resource subject : keySet()) {
// sortedSPOMap.put(subject, getSorted(subject, collectionClass, comparisonContext));
// }
// return sortedSPOMap;
// }
//
// public int fullSize() {
// var result = 0;
// for (UnsortedTurtlePredicateObjectMap value : values()) {
// result += value.fullSize();
// }
// return result;
// }
//
// public boolean checkValid() {
// for (Resource subject : keySet()) {
// if ((get(subject) == null) || !get(subject).checkValid()) {
// return false;
// }
// }
// return true;
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
import org.edmcouncil.rdf_toolkit.model.UnsortedTurtleSubjectPredicateObjectMap;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.comparator;
public class ComparisonContext {
private final boolean shouldInlineBlankNodes; | private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap; |
edmcouncil/rdf-toolkit | src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleBNodeList.java | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
| import org.eclipse.rdf4j.model.BNode;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import java.util.HashSet; | /*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* An unsorted list of RDF blank nodes.
*/
// TODO: why is this not a subclass of UnsortedTurtleResourceList?
public class UnsortedTurtleBNodeList extends HashSet<BNode> {
public SortedTurtleBNodeList toSorted(Class collectionClass, // TODO | // Path: src/main/java/org/edmcouncil/rdf_toolkit/comparator/ComparisonContext.java
// public class ComparisonContext {
//
// private final boolean shouldInlineBlankNodes;
// private final UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap;
//
// public ComparisonContext(boolean shouldInlineBlankNodesX, UnsortedTurtleSubjectPredicateObjectMap unsortedTripleMap) {
// this.shouldInlineBlankNodes = shouldInlineBlankNodesX;
// this.unsortedTripleMap = unsortedTripleMap;
// }
//
// public boolean getShouldInlineBlankNodes() {
// return shouldInlineBlankNodes;
// }
//
// public UnsortedTurtleSubjectPredicateObjectMap getUnsortedTripleMap() {
// return unsortedTripleMap;
// }
// }
// Path: src/main/java/org/edmcouncil/rdf_toolkit/model/UnsortedTurtleBNodeList.java
import org.eclipse.rdf4j.model.BNode;
import org.edmcouncil.rdf_toolkit.comparator.ComparisonContext;
import java.util.HashSet;
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Enterprise Data Management Council
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.edmcouncil.rdf_toolkit.model;
/**
* An unsorted list of RDF blank nodes.
*/
// TODO: why is this not a subclass of UnsortedTurtleResourceList?
public class UnsortedTurtleBNodeList extends HashSet<BNode> {
public SortedTurtleBNodeList toSorted(Class collectionClass, // TODO | ComparisonContext comparisonContext) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.