本文整理汇总了Java中rx.functions.Action2类的典型用法代码示例。如果您正苦于以下问题:Java Action2类的具体用法?Java Action2怎么用?Java Action2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Action2类属于rx.functions包,在下文中一共展示了Action2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSet
import rx.functions.Action2; //导入依赖的package包/类
public static <T> Transformer<T, Set<T>> toSet() {
return new Transformer<T, Set<T>>() {
@Override
public Observable<Set<T>> call(Observable<T> o) {
return o.collect(new Func0<Set<T>>() {
@Override
public Set<T> call() {
return new HashSet<T>();
}
}, new Action2<Set<T>, T>() {
@Override
public void call(Set<T> set, T t) {
set.add(t);
}
});
}
};
}
示例2: initActions
import rx.functions.Action2; //导入依赖的package包/类
private void initActions() {
onReviewItemClick = new Action2<Boolean, Review>() {
@Override
public void call(Boolean lastOne, Review review) {
// 如果是最后一项,则跳到评论列表,否则跳到评论详情
Intent intent;
if (lastOne) {
intent = DoubanMovieMoreReviewActivity.intentFor(getContext());
intent.putExtra(Constant.EXTRA_DOUBAN_MOVIE_ID, id);
} else {
intent = DoubanMovieReviewActivity.intentFor(getContext());
intent.putExtra(Constant.EXTRA_DOUBAN_MOVIE_REVIEW, review);
}
intent.putExtra(Constant.EXTRA_DOUBAN_MOVIE_TITLE, title);
getContext().startActivity(intent);
}
};
}
示例3: adapt
import rx.functions.Action2; //导入依赖的package包/类
@Override
public Observable<T> adapt(final Call<T> call) {
return Observable.<T>create(SyncOnSubscribe.createSingleState(new Func0<Call<T>>() {
@Override
public Call<T> call() {
return call.clone();
}
}, new Action2<Call<T>, Observer<? super T>>() {
@Override
public void call(Call<T> callClone, Observer<? super T> observer) {
try {
observer.onNext(callClone.execute());
observer.onCompleted();
} catch (Throwable throwable) {
observer.onError(throwable);
}
}
}, new Action1<Call<T>>() {
@Override
public void call(Call<T> tCall) {
tCall.cancel();
}
}));
}
示例4: getQuery
import rx.functions.Action2; //导入依赖的package包/类
private <T> Observable<T> getQuery(Query query, Action2<Subscriber<? super T>, DataSnapshot> onNextAction, boolean subscribeForSingleEvent) {
return Observable.create(subscriber -> {
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
onNextAction.call(subscriber, dataSnapshot);
}
@Override
public void onCancelled(DatabaseError databaseError) {
subscriber.onError(new FirebaseException(databaseError.getMessage()));
}
};
if (subscribeForSingleEvent) {
query.addListenerForSingleValueEvent(eventListener);
} else {
query.addValueEventListener(eventListener);
}
subscriber.add(Subscriptions.create(() -> query.removeEventListener(eventListener)));
});
}
示例5: createSyncOnSubscribe
import rx.functions.Action2; //导入依赖的package包/类
@NonNull
private static SyncOnSubscribe<ByteBuffer, byte[]> createSyncOnSubscribe(final byte[] bytes, final int maxBatchSize) {
return SyncOnSubscribe.createSingleState(
new Func0<ByteBuffer>() {
@Override
public ByteBuffer call() {
return ByteBuffer.wrap(bytes);
}
},
new Action2<ByteBuffer, Observer<? super byte[]>>() {
@Override
public void call(ByteBuffer byteBuffer, Observer<? super byte[]> observer) {
int nextBatchSize = Math.min(byteBuffer.remaining(), maxBatchSize);
if (nextBatchSize == 0) {
observer.onCompleted();
return;
}
final byte[] nextBatch = new byte[nextBatchSize];
byteBuffer.get(nextBatch);
observer.onNext(nextBatch);
}
}
);
}
示例6: combine
import rx.functions.Action2; //导入依赖的package包/类
/**
* Combines provided actions into a single action stream
*
* @param a1 Action
* @param a2 Action
* @param a3 Action
* @param a4 Action
* @param a5 Action
* @param a6 Action
* @return Single action stream combined from provided actions
*/
@CheckResult
@NonNull
public static <T1, T2> Action2<? super T1, ? super T2> combine(@NonNull final Action2<? super T1, ? super T2> a1, @NonNull final Action2<? super T1, ? super T2> a2, @NonNull final Action2<? super T1, ? super T2> a3, @NonNull final Action2<? super T1, ? super T2> a4, @NonNull final Action2<? super T1, ? super T2> a5, @NonNull final Action2<? super T1, ? super T2> a6) {
return new Action2<T1, T2>() {
@Override
public void call(T1 t1, T2 t2) {
a1.call(t1, t2);
a2.call(t1, t2);
a3.call(t1, t2);
a4.call(t1, t2);
a5.call(t1, t2);
a6.call(t1, t2);
}
};
}
示例7: updateEnergyValues
import rx.functions.Action2; //导入依赖的package包/类
private void updateEnergyValues(EnergyViewHolder holder, EnergyModel energy) {
holder.linearLayoutEnergyValues.setVisibility(View.VISIBLE);
holder.imageViewCardAlert.setVisibility(View.INVISIBLE);
if (energy.getInstantaneousPower() == null &&
energy.getDailyPower() == null &&
energy.getMonthlyPower() == null) {
log.warn("energy values are null or invalid: unable to update");
holder.linearLayoutEnergyValues.setVisibility(View.GONE);
holder.imageViewCardAlert.setVisibility(View.VISIBLE);
return;
}
Action2<TextView, String> updateEnergy = (textView, value) ->
textView.setText(TextUtils.isEmpty(value) ? utilityService.getString(R.string.energy_none) :
value + " " + utilityService.getString(R.string.energy_power_unit));
updateEnergy.call(holder.textViewEnergyInstantaneousPower, energy.getInstantaneousPower());
updateEnergy.call(holder.textViewEnergyDailyPower, energy.getDailyPower());
updateEnergy.call(holder.textViewEnergyMonthlyPower, energy.getMonthlyPower());
}
示例8: testCollectToString
import rx.functions.Action2; //导入依赖的package包/类
@Test
public void testCollectToString() {
String value = Observable.just(1, 2, 3).collect(new Supplier<StringBuilder>() {
@Override
public StringBuilder call() {
return new StringBuilder();
}
}, new Action2<StringBuilder, Integer>() {
@Override
public void call(StringBuilder sb, Integer v) {
if (sb.length() > 0) {
sb.append("-");
}
sb.append(v);
}
}).toBlocking().last().toString();
assertEquals("1-2-3", value);
}
示例9: testSeedFactory
import rx.functions.Action2; //导入依赖的package包/类
/**
* This uses the public API collect which uses scan under the covers.
*/
@Test
public void testSeedFactory() {
Observable<List<Integer>> o = Observable.range(1, 10)
.collect(new Supplier<List<Integer>>() {
@Override
public List<Integer> call() {
return new ArrayList<Integer>();
}
}, new Action2<List<Integer>, Integer>() {
@Override
public void call(List<Integer> list, Integer t2) {
list.add(t2);
}
}).takeLast(1);
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), o.toBlocking().single());
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), o.toBlocking().single());
}
示例10: testType
import rx.functions.Action2; //导入依赖的package包/类
private <T> void testType(String methodName, T getValue, T setValue,
Func1<SharedPreferences.Editor, SharedPreferences.Editor> whenPut,
Action2<SharedPreferences.Editor, T> verifyPut,
Func1<TestTypes, T> doGet, Action2<TestTypes, T> doSet) {
SharedPreferences pref = mock(SharedPreferences.class);
TestTypes test = ProxyPreferences.build(TestTypes.class, pref);
when(pref.getAll())
.thenAnswer(answerMapValue(methodName, getValue));
assertEquals(getValue, doGet.call(test));
SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
when(pref.edit())
.thenReturn(editor);
when(whenPut.call(editor))
.thenReturn(editor);
doSet.call(test, setValue);
InOrder order = inOrder(pref, editor);
order.verify(pref, times(1)).edit();
verifyPut.call(order.verify(editor, times(1)), setValue);
order.verify(editor, times(1)).apply();
}
示例11: toListWhile
import rx.functions.Action2; //导入依赖的package包/类
/**
* <p>
* Returns a {@link Transformer} that returns an {@link Observable} that is
* a buffering of the source Observable into lists of sequential items that
* satisfy the condition {@code condition}.
*
* <p>
* <img src=
* "https://github.com/davidmoten/rxjava-extras/blob/master/src/docs/toListWhile.png?raw=true"
* alt="marble diagram">
*
* @param condition
* condition function that must return true if an item is to be
* part of the list being prepared for emission
* @param <T>
* the generic type of the source Observable
* @return transformer as above
*/
public static <T> Transformer<T, List<T>> toListWhile(
final Func2<? super List<T>, ? super T, Boolean> condition) {
Func0<List<T>> initialState = new Func0<List<T>>() {
@Override
public List<T> call() {
return new ArrayList<T>();
}
};
Action2<List<T>, T> collect = new Action2<List<T>, T>() {
@Override
public void call(List<T> list, T n) {
list.add(n);
}
};
return collectWhile(initialState, collect, condition);
}
示例12: createServerSocketObservable
import rx.functions.Action2; //导入依赖的package包/类
private static Observable<Observable<byte[]>> createServerSocketObservable(
ServerSocket serverSocket, final long timeoutMs, final int bufferSize,
final Action0 preAcceptAction, final Func1<? super Socket, Boolean> acceptSocket) {
return Observable.create( //
SyncOnSubscribe.<ServerSocket, Observable<byte[]>> createSingleState( //
Functions.constant0(serverSocket), //
new Action2<ServerSocket, Observer<? super Observable<byte[]>>>() {
@Override
public void call(ServerSocket ss,
Observer<? super Observable<byte[]>> observer) {
acceptConnection(timeoutMs, bufferSize, ss, observer,
preAcceptAction, acceptSocket);
}
}));
}
示例13: chainAction
import rx.functions.Action2; //导入依赖的package包/类
private static <T> Func1<Action1<T>, Action1<T>> chainAction(
final Action2<Action1<T>, T> action2) {
return new Func1<Action1<T>, Action1<T>>() {
@Override
public Action1<T> call(final Action1<T> action) {
return new Action1<T>() {
@Override
public void call(T t) {
action2.call(action, t);
}
};
}
};
}
示例14: testCollectToString
import rx.functions.Action2; //导入依赖的package包/类
@Test
public void testCollectToString() {
String value = Observable.just(1, 2, 3).collect(new Func0<StringBuilder>() {
@Override
public StringBuilder call() {
return new StringBuilder();
}
}, new Action2<StringBuilder, Integer>() {
@Override
public void call(StringBuilder sb, Integer v) {
if (sb.length() > 0) {
sb.append("-");
}
sb.append(v);
}
}).toBlocking().last().toString();
assertEquals("1-2-3", value);
}
示例15: providePresenterConfig
import rx.functions.Action2; //导入依赖的package包/类
@Provides @ScreenScope
public BundleablePresenterConfig providePresenterConfig(
ItemClickListener itemClickListener,
MenuHandler menuConfig
) {
return BundleablePresenterConfig.builder()
.setWantsGrid(true)
.setAllowLongPressSelection(false)
.setItemClickListener(itemClickListener)
.setMenuConfig(menuConfig)
.setFabClickAction(new Action2<Context, BundleablePresenter>() {
@Override
public void call(Context context, final BundleablePresenter presenter) {
UtilsCommon.addTracksToQueue(context,
Collections.singletonList(screen.genre.getTracksUri()),
new Action1<List<Uri>>() {
@Override
public void call(List<Uri> uris) {
presenter.getPlaybackController().playAll(uris, 0);
}
});
}
})
.build();
}