use of io.reactivex.rxjava3.functions.Supplier in project radixdlt by radixdlt.
the class RecoveryLivenessTest method setup.
@Before
public void setup() {
this.messageMutator = MessageMutator.nothing();
this.network = new DeterministicNetwork(nodeKeys.stream().map(k -> BFTNode.create(k.getPublicKey())).toList(), MessageSelector.firstSelector(), this::mutate);
var allNodes = nodeKeys.stream().map(k -> BFTNode.create(k.getPublicKey())).toList();
this.nodeCreators = nodeKeys.stream().<Supplier<Injector>>map(k -> () -> createRunner(k, allNodes)).toList();
for (Supplier<Injector> nodeCreator : nodeCreators) {
this.nodes.add(nodeCreator.get());
}
this.nodes.forEach(i -> i.getInstance(DeterministicProcessor.class).start());
}
use of io.reactivex.rxjava3.functions.Supplier in project xxf_android by NBXXF.
the class StringFileService method writeFileString.
/**
* 写
*
* @param file
* @param content
* @param append
* @return
*/
default Observable<File> writeFileString(File file, String content, boolean append) {
return Observable.defer(new Supplier<ObservableSource<? extends File>>() {
@Override
public ObservableSource<? extends File> get() throws Throwable {
FileUtils.createOrExistsFile(file);
try (FileWriter fw = new FileWriter(file, append)) {
fw.write(content);
fw.flush();
}
return Observable.just(file);
}
}).subscribeOn(Schedulers.io());
}
use of io.reactivex.rxjava3.functions.Supplier in project xxf_android by NBXXF.
the class StringFileService method readFileString.
/**
* 读取
*
* @return
*/
default Observable<String> readFileString(File file) {
return Observable.defer(new Supplier<ObservableSource<? extends String>>() {
@Override
public ObservableSource<? extends String> get() throws Throwable {
if (FileUtils.isFileExists(ApplicationProvider.applicationContext, file)) {
try (FileReader fr = new FileReader(file)) {
char[] bt = new char[1024];
StringBuffer sb = new StringBuffer();
while (fr.read(bt) != -1) {
sb.append(bt);
java.util.Arrays.fill(bt, (char) 0);
}
return Observable.just(sb.toString());
}
}
return Observable.empty();
}
}).subscribeOn(Schedulers.io());
}
use of io.reactivex.rxjava3.functions.Supplier in project xxf_android by NBXXF.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Throwable {
}
});
Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Throwable {
Log.d("========>测试 开始执行重试:", "" + pageIndex);
return Observable.just(pageIndex).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer integer) throws Throwable {
if (integer < 3) {
Log.d("========>测试 异常:", "" + integer);
throw new RuntimeException("");
}
return integer;
}
});
}
}).retry(3, new Predicate<Throwable>() {
@Override
public boolean test(Throwable throwable) throws Throwable {
if (throwable instanceof RuntimeException) {
Log.d("========>测试 重试:", "" + System.currentTimeMillis());
pageIndex += 1;
return true;
}
return false;
}
}).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Throwable {
Log.d("========>测试 结果:", "" + integer);
}
});
binding = ActivityMainBinding.inflate(getLayoutInflater());
binding.change.setText("normal");
binding.change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(v.getContext(), NormalRecyclerViewActivity.class).putExtra("xx", "77463"));
}
});
setContentView(binding.getRoot());
System.out.println("==========>onChildViewAttachedToWindow init");
// adapter.setHasStableIds(true);
binding.recyclerView.setAdapter(adapter);
// 删除-> 改变焦点(上一个) 后删除当前
// binding.recyclerView.find
// 创建第五条
binding.recyclerView.setEdgeEffectFactory(new EdgeSpringEffectFactory(0.5f, 0.5f));
binding.recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(@NonNull View view) {
RecyclerView.ViewHolder containingViewHolder = binding.recyclerView.findContainingViewHolder(view);
if (containingViewHolder.getAdapterPosition() == 5) {
// requestfoucs
binding.recyclerView.removeOnChildAttachStateChangeListener(this);
}
System.out.println("==========>onChildViewAttachedToWindow:AdapterPosition:" + containingViewHolder.getAdapterPosition() + " LayoutPosition:" + containingViewHolder.getLayoutPosition() + " hash:" + containingViewHolder.itemView);
}
@Override
public void onChildViewDetachedFromWindow(@NonNull View view) {
}
});
sectionMap.clear();
sectionMap.put(0, "第一个分组");
sectionMap.put(3, "第2个分组");
Paint paint = new Paint();
paint.setTextSize(DensityUtil.sp2px(13));
paint.setColor(Color.RED);
paint.setAntiAlias(true);
Paint background = new Paint();
background.setColor(Color.WHITE);
binding.recyclerView.addItemDecoration(new SectionItemDecoration(new SectionProvider() {
@NotNull
@Override
public TreeMap<Integer, String> onProvideSection() {
return sectionMap;
}
}, paint, background, DensityUtil.sp2px(30), DensityUtil.sp2px(16)));
List<String> list = new ArrayList<>();
int count = new Random().nextInt(50);
for (int i = 0; i < count; i++) {
// list.add("i" + new Random().nextInt(100));
list.add("i" + i);
}
adapter.bindData(true, list);
binding.refresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<String> list = new ArrayList<>();
int count = new Random().nextInt(50);
for (int i = 0; i < count; i++) {
// list.add("i" + new Random().nextInt(100));
list.add("i" + i);
}
adapter.bindData(true, list);
Log.d("=======>list:", "" + list);
}
});
binding.insert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.addItem(0, "hello");
}
});
binding.insertLast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.addItem("hello foo");
}
});
binding.delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.removeItem(0);
}
});
binding.loadMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<String> list = new ArrayList<>();
int count = new Random().nextInt(50);
for (int i = 0; i < count; i++) {
// list.add("i" + new Random().nextInt(100));
list.add("i" + i);
}
adapter.addItems(list);
}
});
}
use of io.reactivex.rxjava3.functions.Supplier in project RxJava by ReactiveX.
the class ObservableCollectWithCollectorTest method collectorAccumulatorCrashToObservable.
@Test
public void collectorAccumulatorCrashToObservable() {
BehaviorProcessor<Integer> source = BehaviorProcessor.createDefault(1);
source.collect(new Collector<Integer, Integer, Integer>() {
@Override
public Supplier<Integer> supplier() {
return () -> 1;
}
@Override
public BiConsumer<Integer, Integer> accumulator() {
return (a, b) -> {
throw new TestException();
};
}
@Override
public BinaryOperator<Integer> combiner() {
return (a, b) -> a + b;
}
@Override
public Function<Integer, Integer> finisher() {
return a -> a;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
}).toObservable().test().assertFailure(TestException.class);
assertFalse(source.hasSubscribers());
}
Aggregations