Java Code Examples for rx.functions.Action1#call()

The following examples show how to use rx.functions.Action1#call() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxNotification.java    From satellite with MIT License 6 votes vote down vote up
/**
 * Returns an {@link Action1} that can be used to split {@link Notification} to appropriate
 * dematerialized onNext and onError calls.
 *
 * @param onNext  a method that will be called in case of onNext notification, or null.
 * @param onError a method that will be called in case of onError notification, or null.
 * @param <T>     a type of onNext value.
 * @return an {@link Action1} that can be used to split a {@link Notification} into appropriate
 * onNext, onError calls.
 */
public static <T> Action1<Notification<T>> split(
    @Nullable final Action1<T> onNext,
    @Nullable final Action1<Throwable> onError) {

    return new Action1<Notification<T>>() {
        @Override
        public void call(Notification<T> notification) {
            if (notification.isOnNext()) {
                if (onNext != null)
                    onNext.call(notification.getValue());
            }
            else if (notification.isOnError()) {
                if (onError != null)
                    onError.call(notification.getThrowable());
                else
                    throw new OnErrorNotImplementedException(notification.getThrowable());
            }
        }
    };
}
 
Example 2
Source File: RealmUtil.java    From photosearcher with Apache License 2.0 6 votes vote down vote up
public static void executeTransaction(Action1<Realm> transaction, Action1<Throwable> onFailure) {
    Realm realm = null;

    try {
        realm = Realm.getDefaultInstance();
        realm.beginTransaction();

        transaction.call(realm);

        realm.commitTransaction();
    } catch (Exception e) {
        if (realm != null) {
            realm.cancelTransaction();
        }
        onFailure.call(e);
    } finally {
        if (realm != null) {
            realm.close();
        }
    }
}
 
Example 3
Source File: RxNotificationTest.java    From satellite with MIT License 5 votes vote down vote up
@Test
public void testSplit2() throws Exception {
    Action1<Integer> onNext = Mockito.mock(Action1.class);
    Action1<Throwable> onError = Mockito.mock(Action1.class);

    Action1<Notification<Integer>> split = RxNotification.split(onNext, onError);

    split.call(Notification.createOnNext(1));
    RuntimeException exception = new RuntimeException();
    split.call(Notification.<Integer>createOnError(exception));
    split.call(Notification.<Integer>createOnCompleted());
    verify(onNext, times(1)).call(1);
    verify(onError, times(1)).call(exception);
    verifyNoMoreInteractions(onNext, onError);
}
 
Example 4
Source File: AwsObservableExt.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public <REQ extends AmazonWebServiceRequest, RES> AsyncHandler<REQ, RES> handler(Action2<REQ, RES> onSuccessAction, Action1<Exception> onErrorAction) {
    return new AsyncHandler<REQ, RES>() {
        @Override
        public void onError(Exception exception) {
            onErrorAction.call(exception);
            subscriber.onError(exception);
        }

        @Override
        public void onSuccess(REQ request, RES result) {
            onSuccessAction.call(request, result);
            subscriber.onCompleted();
        }
    };
}
 
Example 5
Source File: SecondActivityEspressoTest.java    From AndroidEspressoIdlingResourcePlayground with MIT License 5 votes vote down vote up
@Override
public void doLongRunningOpAndReturnResult(Action1<String> action) {
    isRunning = true;
    super.doLongRunningOpAndReturnResult(new Action1<String>() {
        @Override
        public void call(String realResult) {
            action.call(realResult);
            isRunning = false;
            resourceCallback.onTransitionToIdle();
        }
    });
}
 
Example 6
Source File: ResponseUtilsTest.java    From mesos-rxjava with Apache License 2.0 5 votes vote down vote up
private static HttpClientResponse<ByteBuf> response(
    @NotNull final ByteBuf content,
    @NotNull final Action1<HttpHeaders> headerTransformer
) {
    final DefaultHttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    headerTransformer.call(nettyResponse.headers());
    final UnicastContentSubject<ByteBuf> subject = UnicastContentSubject.create(1000, TimeUnit.MILLISECONDS);
    subject.onNext(content);
    return new HttpClientResponse<>(
        nettyResponse,
        subject
    );
}
 
Example 7
Source File: RXSubscriptionUtil.java    From RXBus with Apache License 2.0 5 votes vote down vote up
public static <T> Action1<T> wrapQueueAction(Action1<T> action, IRXBusQueue isResumedProvider)
{
    return new Action1<T>()
    {
        @Override
        public void call(T t)
        {
            if (RXUtil.safetyQueueCheck(t, isResumedProvider))
                action.call(t);
        }
    };
}
 
Example 8
Source File: RXBusUtil.java    From RXBus with Apache License 2.0 5 votes vote down vote up
public static <T> Action1<T> wrapQueueAction(Action1<T> action, IRXBusQueue isResumedProvider)
{
    return new Action1<T>()
    {
        @Override
        public void call(T t)
        {
            if (RXUtil.safetyQueueCheck(t, isResumedProvider))
                action.call(t);
        }
    };
}
 
Example 9
Source File: RXBusUtil.java    From RXBus with Apache License 2.0 5 votes vote down vote up
protected static <T> Action1<T> wrapQueueAction(Action1<T> action, IRXBusQueue isResumedProvider)
{
    return new Action1<T>()
    {
        @Override
        public void call(T t)
        {
            if (RXUtil.safetyQueueCheck(t, isResumedProvider))
                action.call(t);
        }
    };
}
 
Example 10
Source File: AptoideApplication.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public <T> List<T> combineLists(List<T> list1, List<T> list2, @Nullable Action1<T> transformer) {
  List<T> toReturn = new ArrayList<>(list1.size() + list2.size());
  toReturn.addAll(list1);
  for (T item : list2) {
    if (!toReturn.contains(item)) {
      if (transformer != null) {
        transformer.call(item);
      }
      toReturn.add(item);
    }
  }

  return toReturn;
}
 
Example 11
Source File: MetricsClientImpl.java    From mantis with Apache License 2.0 5 votes vote down vote up
private void closeOut(Action1<WorkerConnection<T>> onClose) {
    synchronized (workerConnections) {
        isClosed = true;
    }
    for (WorkerConnection<T> workerConnection : workerConnections.values()) {
        logger.info("Closing " + workerConnection.getName());
        onClose.call(workerConnection);
    }
}
 
Example 12
Source File: AutoRemoveSubscription.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
public static <T> void subscribeAutoRelease(
        Observable<T> source, 
        final Action1<T> onNext, 
        CompositeSubscription composite) {
    Subscriber<T> subscriber = new Subscriber<T>() {
        @Override
        public void onCompleted() {
            composite.remove(this);
        }
        @Override
        public void onError(Throwable e) {
            composite.remove(this);
            RxJavaHooks.onError(e);
        }
        @Override
        public void onNext(T t) {
            try {
                onNext.call(t);
            } catch (Throwable ex) {
                unsubscribe();
                onError(ex);
            }
        }
    };
    composite.add(subscriber);
    source.subscribe(subscriber);
}
 
Example 13
Source File: JsonObject.java    From datamill with ISC License 5 votes vote down vote up
@Override
public DeepStructuredInput forEach(String name, Action1<Value> action) {
    Object child = object.opt(name);
    if (child instanceof JSONArray) {
        JSONArray array = (JSONArray) child;
        for (int i = 0; i < array.length(); i++) {
            action.call(new JsonElement(array, i));
        }
    } else {
        action.call(new JsonProperty(name));
    }

    return this;
}
 
Example 14
Source File: PropertySources.java    From datamill with ISC License 5 votes vote down vote up
/**
 * @see PropertySourceChain#orImmediate(Action1, Func1)
 */
public static PropertySourceChain fromImmediate(
        Action1<ImmediatePropertySource> initializer,
        Func1<String, String> transformer) {
    ImmediatePropertySourceImpl immediateSource = new ImmediatePropertySourceImpl();
    initializer.call(immediateSource);

    return from(immediateSource, transformer);
}
 
Example 15
Source File: BasePresenter.java    From RxAnimations with Apache License 2.0 4 votes vote down vote up
protected void doIfViewNotNull(final Action1<T> whenViewNotNull) {
    final T view = getNullableView();
    if (view != null) {
        whenViewNotNull.call(view);
    }
}
 
Example 16
Source File: RxNotificationTest.java    From satellite with MIT License 4 votes vote down vote up
@Test
public void testNull() throws Exception {
    Action1<Notification<Integer>> split = RxNotification.split(null, null);
    split.call(Notification.createOnNext(1));
    split.call(Notification.<Integer>createOnCompleted());
}
 
Example 17
Source File: SoundActivity.java    From openwebnet-android with MIT License 4 votes vote down vote up
private void initSoundType(SoundSystem.Type type) {
    Action1<Integer> initView = visibility -> {
        editTextSoundWhere.setVisibility(visibility);
        textViewSoundSuffix.setVisibility(visibility);
        textViewSoundInfo.setVisibility(visibility);
    };

    Action1<String> initWhereValue = value -> {
        editTextSoundWhere.setError(null);

        // initialize all subsequent calls except the first time
        if (!initSoundTypeFirstTime) {
            editTextSoundWhere.setText(value);
        }
        // from now on every time reset editTextSoundWhere
        initSoundTypeFirstTime = false;
    };

    switch (type) {
        case AMPLIFIER_GENERAL:
            textViewSoundPrefix.setText(getString(R.string.sound_value_general_amplifier_stereo));
            initView.call(View.GONE);
            textViewSoundInfo.setVisibility(View.INVISIBLE);
            initWhereValue.call(SoundSystem.Type.AMPLIFIER_GENERAL_COMMAND);
            break;
        case AMPLIFIER_GROUP:
            textViewSoundPrefix.setText(getString(R.string.sound_prefix_stereo_group));
            textViewSoundInfo.setText(getString(R.string.sound_info_amplifier_group));
            initView.call(View.VISIBLE);
            initWhereValue.call("");
            break;
        case AMPLIFIER_P2P:
            textViewSoundPrefix.setText(getString(R.string.sound_prefix_stereo));
            textViewSoundInfo.setText(getString(R.string.sound_info_amplifier_point_to_point));
            initView.call(View.VISIBLE);
            initWhereValue.call("");
            break;
        case SOURCE_GENERAL:
            textViewSoundPrefix.setText(getString(R.string.sound_value_general_source_stereo));
            initView.call(View.GONE);
            textViewSoundInfo.setVisibility(View.INVISIBLE);
            initWhereValue.call(SoundSystem.Type.SOURCE_GENERAL_COMMAND);
            break;
        case SOURCE_P2P:
            textViewSoundPrefix.setText(getString(R.string.sound_prefix_stereo));
            textViewSoundInfo.setText(getString(R.string.sound_info_source_point_to_point));
            initView.call(View.VISIBLE);
            initWhereValue.call("");
            break;
        default: {
            throw new IllegalArgumentException("invalid sound type");
        }
    }
}
 
Example 18
Source File: AnimateOnSubscribe.java    From RxAnimations with Apache License 2.0 4 votes vote down vote up
private void applyActions(final List<Action1<ViewPropertyAnimatorCompat>> actions, final ViewPropertyAnimatorCompat animator) {
    for (final Action1<ViewPropertyAnimatorCompat> action : actions) {
        action.call(animator);
    }
}
 
Example 19
Source File: RxNotificationTest.java    From satellite with MIT License 4 votes vote down vote up
@Test(expected = OnErrorNotImplementedException.class)
public void testOnErrorNotImplemented() throws Exception {
    Action1<Notification<Integer>> split = RxNotification.split(null, null);
    split.call(Notification.<Integer>createOnError(new Exception()));
}
 
Example 20
Source File: ServerClientContext.java    From mantis with Apache License 2.0 4 votes vote down vote up
public Observable<HttpClientResponse<E>> newResponse(Action1<ServerInfo> connectionAttemptedCallback) {
    CONNECTION_ATTEMPTED.newEvent(sourceObserver, getServer());
    connectionAttemptedCallback.call(getServer());
    return getClient().submit(requestFactory.create());
}