Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interceptors api #771

Merged
merged 12 commits into from
Jul 6, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @param <Result> type of result
*/
public interface PreparedOperation<Result> {
public interface PreparedOperation<Result, Data> {

/**
* Executes operation synchronously in current thread.
Expand Down Expand Up @@ -62,4 +62,7 @@ public interface PreparedOperation<Result> {
@NonNull
@CheckResult
Single<Result> asRxSingle();

@NonNull
Data getData();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically this does not help interceptors to be type-safe but gives a way to get data without need in casting PreparedOperation to some particular implementation.

I guess we'll have to ship it as 2.x then since it's addition to an interface which is a breaking change (when I was giving greenlight to that I was thinking just about , Data> generic which is not breaking but forgot that it'll add a method)

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @param <Result> type of result
*/
public interface PreparedWriteOperation<Result> extends PreparedOperation<Result> {
public interface PreparedWriteOperation<Result, Data> extends PreparedOperation<Result, Data> {

@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
* <p>
* For internal usage only!
*/
public final class MapSomethingToExecuteAsBlocking<Something, Result> implements Func1<Something, Result> {
public final class MapSomethingToExecuteAsBlocking<Something, Result, Data> implements Func1<Something, Result> {

@NonNull
private final PreparedOperation<Result> preparedOperation;
private final PreparedOperation<Result, Data> preparedOperation;

private MapSomethingToExecuteAsBlocking(@NonNull PreparedOperation<Result> preparedOperation) {
private MapSomethingToExecuteAsBlocking(@NonNull PreparedOperation<Result, Data> preparedOperation) {
this.preparedOperation = preparedOperation;
}

Expand All @@ -30,8 +30,8 @@ private MapSomethingToExecuteAsBlocking(@NonNull PreparedOperation<Result> prepa
* @return new instance of {@link MapSomethingToExecuteAsBlocking}
*/
@NonNull
public static <Something, Result> Func1<Something, Result> newInstance(@NonNull PreparedOperation<Result> preparedOperation) {
return new MapSomethingToExecuteAsBlocking<Something, Result>(preparedOperation);
public static <Something, Result, Data> Func1<Something, Result> newInstance(@NonNull PreparedOperation<Result, Data> preparedOperation) {
return new MapSomethingToExecuteAsBlocking<Something, Result, Data>(preparedOperation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* <p>
* For internal usage only!
*/
public final class OnSubscribeExecuteAsBlocking<Result> implements Observable.OnSubscribe<Result> {
public final class OnSubscribeExecuteAsBlocking<Result, Data> implements Observable.OnSubscribe<Result> {

@NonNull
private final PreparedOperation<Result> preparedOperation;
private final PreparedOperation<Result, Data> preparedOperation;

private OnSubscribeExecuteAsBlocking(@NonNull PreparedOperation<Result> preparedOperation) {
private OnSubscribeExecuteAsBlocking(@NonNull PreparedOperation<Result, Data> preparedOperation) {
this.preparedOperation = preparedOperation;
}

Expand All @@ -32,8 +32,8 @@ private OnSubscribeExecuteAsBlocking(@NonNull PreparedOperation<Result> prepared
* @return new instance of {@link OnSubscribeExecuteAsBlocking}
*/
@NonNull
public static <Result> Observable.OnSubscribe<Result> newInstance(@NonNull PreparedOperation<Result> preparedOperation) {
return new OnSubscribeExecuteAsBlocking<Result>(preparedOperation);
public static <Result, Data> Observable.OnSubscribe<Result> newInstance(@NonNull PreparedOperation<Result, Data> preparedOperation) {
return new OnSubscribeExecuteAsBlocking<Result, Data>(preparedOperation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* <p>
* For internal usage only!
*/
public final class OnSubscribeExecuteAsBlockingSingle<Result> implements Single.OnSubscribe<Result> {
public final class OnSubscribeExecuteAsBlockingSingle<Result, Data> implements Single.OnSubscribe<Result> {

@NonNull
private final PreparedOperation<Result> preparedOperation;
private final PreparedOperation<Result, Data> preparedOperation;

private OnSubscribeExecuteAsBlockingSingle(@NonNull PreparedOperation<Result> preparedOperation) {
private OnSubscribeExecuteAsBlockingSingle(@NonNull PreparedOperation<Result, Data> preparedOperation) {
this.preparedOperation = preparedOperation;
}

Expand All @@ -30,8 +30,8 @@ private OnSubscribeExecuteAsBlockingSingle(@NonNull PreparedOperation<Result> pr
* @return new instance of {@link OnSubscribeExecuteAsBlockingSingle}
*/
@NonNull
public static <Result> Single.OnSubscribe<Result> newInstance(@NonNull PreparedOperation<Result> preparedOperation) {
return new OnSubscribeExecuteAsBlockingSingle<Result>(preparedOperation);
public static <Result, Data> Single.OnSubscribe<Result> newInstance(@NonNull PreparedOperation<Result, Data> preparedOperation) {
return new OnSubscribeExecuteAsBlockingSingle<Result, Data>(preparedOperation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MapSomethingToExecuteAsBlockingTest {
@SuppressWarnings("unchecked")
@Test
public void verifyBehavior() {
final PreparedOperation<String> preparedOperation = mock(PreparedOperation.class);
final PreparedOperation<String, Object> preparedOperation = mock(PreparedOperation.class);

final String expectedMapResult = "expected_string";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class OnSubscribeExecuteAsBlockingSingleTest {
@Test
public void shouldExecuteAsBlockingAfterSubscription() {
//noinspection unchecked
final PreparedOperation<Object> preparedOperation = mock(PreparedOperation.class);
final PreparedOperation<Object, Object> preparedOperation = mock(PreparedOperation.class);

TestSubscriber<Object> testSubscriber = new TestSubscriber<Object>();

Expand All @@ -45,7 +45,7 @@ public void shouldExecuteAsBlockingAfterSubscription() {
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
//noinspection unchecked
final PreparedOperation<Object> preparedOperation = mock(PreparedOperation.class);
final PreparedOperation<Object, Object> preparedOperation = mock(PreparedOperation.class);

StorIOException expectedException = new StorIOException("test exception");

Expand All @@ -70,7 +70,7 @@ public void shouldCallOnErrorIfExceptionOccurred() {
@Test
public void shouldCallExecuteAsBlockingEvenIfSubscriberAlreadyUnsubscribed() {
//noinspection unchecked
PreparedOperation<Object> preparedOperation = mock(PreparedOperation.class);
PreparedOperation<Object, Object> preparedOperation = mock(PreparedOperation.class);

//noinspection unchecked
SingleSubscriber<Object> subscriber = new SingleSubscriber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class OnSubscribeExecuteAsBlockingTest {
@Test
public void shouldExecuteAsBlockingAfterSubscription() {
//noinspection unchecked
final PreparedOperation<String> preparedOperation = mock(PreparedOperation.class);
final PreparedOperation<String, Object> preparedOperation = mock(PreparedOperation.class);

final String expectedResult = "expected_string";

Expand All @@ -45,7 +45,7 @@ public void shouldExecuteAsBlockingAfterSubscription() {
@Test
public void shouldNotNotifySubscriberIfItsAlreadyUnsubscribed() {
//noinspection unchecked
PreparedOperation<Object> preparedOperation = mock(PreparedOperation.class);
PreparedOperation<Object, Object> preparedOperation = mock(PreparedOperation.class);

//noinspection unchecked
Subscriber<Object> subscriber = mock(Subscriber.class);
Expand All @@ -67,7 +67,7 @@ public void shouldNotNotifySubscriberIfItsAlreadyUnsubscribed() {
@Test
public void shouldCallExecuteAsBlockingEvenIfSubscriberAlreadyUnsubscribed() {
//noinspection unchecked
PreparedOperation<Object> preparedOperation = mock(PreparedOperation.class);
PreparedOperation<Object, Object> preparedOperation = mock(PreparedOperation.class);

//noinspection unchecked
Subscriber<Object> subscriber = mock(Subscriber.class);
Expand All @@ -88,7 +88,7 @@ public void shouldCallExecuteAsBlockingEvenIfSubscriberAlreadyUnsubscribed() {
public void shouldCallOnError() {
Throwable throwable = new IllegalStateException("Test exception");
//noinspection unchecked
PreparedOperation<String> preparedOperation = mock(PreparedOperation.class);
PreparedOperation<String, Object> preparedOperation = mock(PreparedOperation.class);
when(preparedOperation.executeAsBlocking()).thenThrow(throwable);

TestSubscriber<String> testSubscriber = TestSubscriber.create();
Expand All @@ -106,7 +106,7 @@ public void shouldHonorBackpressureWithMultipleSubscribeOn() {
TestSubscriber<String> testSubscriber = TestSubscriber.create();

//noinspection unchecked
PreparedOperation<String> preparedOperation = mock(PreparedOperation.class);
PreparedOperation<String, Object> preparedOperation = mock(PreparedOperation.class);
when(preparedOperation.executeAsBlocking()).thenReturn("b");

OnSubscribe<String> onSubscribe = OnSubscribeExecuteAsBlocking.newInstance(preparedOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @param <Result> type of result of Delete Operation.
*/
public abstract class PreparedDelete<Result> implements PreparedWriteOperation<Result> {
public abstract class PreparedDelete<Result, Data> implements PreparedWriteOperation<Result, Data> {

@NonNull
protected final StorIOContentResolver storIOContentResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Prepared Delete Operation for
* {@link com.pushtorefresh.storio.contentresolver.StorIOContentResolver}.
*/
public class PreparedDeleteByQuery extends PreparedDelete<DeleteResult> {
public class PreparedDeleteByQuery extends PreparedDelete<DeleteResult, DeleteQuery> {

@NonNull
private final DeleteQuery deleteQuery;
Expand Down Expand Up @@ -132,6 +132,12 @@ public Completable asRxCompletable() {
return RxJavaUtils.createCompletable(storIOContentResolver, this);
}

@NonNull
@Override
public DeleteQuery getData() {
return deleteQuery;
}

/**
* Builder for {@link PreparedDeleteByQuery}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @param <T> type of objects to delete.
*/
public class PreparedDeleteCollectionOfObjects<T> extends PreparedDelete<DeleteResults<T>> {
public class PreparedDeleteCollectionOfObjects<T> extends PreparedDelete<DeleteResults<T>, Collection<T>> {

@NonNull
private final Collection<T> objects;
Expand Down Expand Up @@ -184,6 +184,12 @@ public Completable asRxCompletable() {
return RxJavaUtils.createCompletable(storIOContentResolver, this);
}

@NonNull
@Override
public Collection<T> getData() {
return objects;
}

/**
* Builder for {@link PreparedDeleteCollectionOfObjects}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Prepared Delete Operation for
* {@link com.pushtorefresh.storio.contentresolver.StorIOContentResolver}.
*/
public class PreparedDeleteObject<T> extends PreparedDelete<DeleteResult> {
public class PreparedDeleteObject<T> extends PreparedDelete<DeleteResult, T> {

@NonNull
private final T object;
Expand Down Expand Up @@ -151,6 +151,12 @@ public Completable asRxCompletable() {
return RxJavaUtils.createCompletable(storIOContentResolver, this);
}

@NonNull
@Override
public T getData() {
return object;
}

/**
* Builder for {@link PreparedDeleteObject}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @param <Result> type of result.
*/
public abstract class PreparedGet<Result> implements PreparedOperation<Result> {
public abstract class PreparedGet<Result> implements PreparedOperation<Result, Query> {

@NonNull
protected final StorIOContentResolver storIOContentResolver;
Expand All @@ -24,6 +24,12 @@ public abstract class PreparedGet<Result> implements PreparedOperation<Result> {
this.query = query;
}

@NonNull
@Override
public Query getData() {
return query;
}

/**
* Builder for {@link PreparedGet}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ private RxJavaUtils() {

@CheckResult
@NonNull
public static <T> Observable<T> createObservable(
public static <T, Data> Observable<T> createObservable(
@NonNull StorIOContentResolver storIOContentResolver,
@NonNull PreparedOperation<T> operation
@NonNull PreparedOperation<T, Data> operation
) {
throwExceptionIfRxJavaIsNotAvailable("asRxObservable()");

Expand All @@ -38,9 +38,9 @@ public static <T> Observable<T> createObservable(

@CheckResult
@NonNull
public static <T> Single<T> createSingle(
public static <T, Data> Single<T> createSingle(
@NonNull StorIOContentResolver storIOContentResolver,
@NonNull PreparedOperation<T> operation
@NonNull PreparedOperation<T, Data> operation
) {
throwExceptionIfRxJavaIsNotAvailable("asRxSingle()");

Expand All @@ -52,9 +52,9 @@ public static <T> Single<T> createSingle(

@CheckResult
@NonNull
public static <T> Completable createCompletable(
public static <T, Data> Completable createCompletable(
@NonNull StorIOContentResolver storIOContentResolver,
@NonNull PreparedOperation<T> operation
@NonNull PreparedOperation<T, Data> operation
) {
throwExceptionIfRxJavaIsNotAvailable("asRxCompletable()");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* in {@link android.content.ContentProvider}.
*
*/
public abstract class PreparedPut<Result> implements PreparedWriteOperation<Result> {
public abstract class PreparedPut<Result, Data> implements PreparedWriteOperation<Result, Data> {

@NonNull
protected final StorIOContentResolver storIOContentResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @param <T> type of objects.
*/
public class PreparedPutCollectionOfObjects<T> extends PreparedPut<PutResults<T>> {
public class PreparedPutCollectionOfObjects<T> extends PreparedPut<PutResults<T>, Collection<T>> {

@NonNull
private final Collection<T> objects;
Expand Down Expand Up @@ -184,6 +184,12 @@ public Completable asRxCompletable() {
return RxJavaUtils.createCompletable(storIOContentResolver, this);
}

@NonNull
@Override
public Collection<T> getData() {
return objects;
}

/**
* Builder for {@link PreparedPutCollectionOfObjects}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Prepared Put Operation for {@link ContentValues}.
*/
public class PreparedPutContentValues extends PreparedPut<PutResult> {
public class PreparedPutContentValues extends PreparedPut<PutResult, ContentValues> {

@NonNull
private final ContentValues contentValues;
Expand Down Expand Up @@ -130,6 +130,12 @@ public Completable asRxCompletable() {
return RxJavaUtils.createCompletable(storIOContentResolver, this);
}

@NonNull
@Override
public ContentValues getData() {
return contentValues;
}

/**
* Builder for {@link PreparedPutContentValues}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Prepared Put Operation to perform put multiple {@link ContentValues}
* into {@link StorIOContentResolver}.
*/
public class PreparedPutContentValuesIterable extends PreparedPut<PutResults<ContentValues>> {
public class PreparedPutContentValuesIterable extends PreparedPut<PutResults<ContentValues>, Iterable<ContentValues>> {

@NonNull
private final Iterable<ContentValues> contentValues;
Expand Down Expand Up @@ -141,6 +141,12 @@ public Completable asRxCompletable() {
return RxJavaUtils.createCompletable(storIOContentResolver, this);
}

@NonNull
@Override
public Iterable<ContentValues> getData() {
return contentValues;
}

/**
* Builder for {@link PreparedPutContentValuesIterable}.
* <p>
Expand Down
Loading