首页 > 其他分享 >ComplateFeature基本使用

ComplateFeature基本使用

时间:2024-03-27 12:15:04浏览次数:12  
标签:基本 list List studentFeature CompletableFuture 使用 import ComplateFeature throws

  • combine 合并feature
import cn.hutool.http.HttpUtil;
import entity.EssBptPrice;
import entity.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class AppTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Student student = new Student();
        student.setName("jzhangsan");
        EssBptPrice essBptPrice = new EssBptPrice();
        essBptPrice.setCreatedBy("wangwu");

        CompletableFuture<List<Student>> studentFeature = CompletableFuture.supplyAsync(() -> {
            List<Student> list = new ArrayList<>();
            list.add(student);
            return list;
        });

        CompletableFuture<List<EssBptPrice>> essFeature = CompletableFuture.supplyAsync(() -> {
            List<EssBptPrice> essBptPrices = new ArrayList<>();
            essBptPrices.add(essBptPrice);
            return essBptPrices;
        });
        //合并两个feature
        CompletableFuture<List<String>> commonfeature = studentFeature.thenCombine(essFeature, (s, e) -> merge(s, e));
        for (String s : commonfeature.get()) {
            System.out.println("合并后输出:" + s);
        }
    }

    public static List<String> merge(List<Student> student, List<EssBptPrice> listCompletableFuture) {
        List<String> list = new ArrayList<>();
        student.forEach(x -> list.add(x.getName()));
        listCompletableFuture.forEach(y -> list.add(y.getCreatedBy()));
        return list;
    }
}
  • thenApply
/**
     * feature 之后进行相关操作
     * @param studentFeature
     * @throws ExecutionException
     * @throws InterruptedException
     */
    public static void thenApply(CompletableFuture<List<Student>> studentFeature) throws ExecutionException, InterruptedException {
        List<Student> students = studentFeature.thenApply(x -> {
            x.forEach(y -> y.setName(y.getName() + "999"));
            return x;
        }).get();
        students.forEach(x-> System.out.println(x.getName()));
    }
  • compose
 /**
     * 生成新的feature
     * @param studentFeature
     * @throws ExecutionException
     * @throws InterruptedException
     */
    public static void thenCompose(CompletableFuture<List<Student>> studentFeature) throws ExecutionException, InterruptedException {
        List<Student> students = studentFeature.thenCompose(x -> CompletableFuture.supplyAsync(() -> {
            x.forEach(y -> y.setName(y.getName() + "8888"));
            return x;
        })).get();
        students.forEach(x-> System.out.println(x.getName()));
    }

 

标签:基本,list,List,studentFeature,CompletableFuture,使用,import,ComplateFeature,throws
From: https://www.cnblogs.com/coderdxj/p/18098640

相关文章

  • 海康威视网络摄像头,把电脑作为硬盘录像机使用。方便别人方便自己。
    第一步,到官网https://www.hikvision.com/cn/服务支持》下载中心》桌面应用软件》客户端  下载   iVMS-4200(V3.11.0.5_C)  和  存储服务器 这2个软件下载到本地第二步,安装好2个软件。第三步,添加摄像头,不知道或忘记密码就网上找方法,很好找的。说明:一个是摄像头......
  • Java对象拷贝之MapStruct使用
    gradle依赖implementationgroup:'org.mapstruct',name:'mapstruct-jdk8',version:'1.3.1.Final'annotationProcessor"org.mapstruct:mapstruct-processor:1.3.1.Final"mapper(前提是原始对象与目标对象属性一致,不一致的需要单独处理)@Mapperpublici......
  • MongoTemplate基本使用
    分页/***mongo分页*/@TestpublicvoidtestPage(){intpageSize=10;intcurrentNo=0;Queryquery=newQuery();query.addCriteria(Criteria.where("username").is("小明"));longcount=mongoTemplate.count(query,User.class);longtot......
  • Mongo Db基本查询
    gt:大于gte:大于等于lt:小于lte:小于等于SQL查询语句MongoDBfind()语句SELECT*FROMusersdb.users.find()SELECTid,user_id,statusFROMusersdb.users.find({},{user_id:1,status:1})SELECTuser_id,statusFROMusersdb.users.find({},{......
  • GeoLite2 geoip数据库下载和使用
            GeoLite2数据库是免费的IP地理定位数据库,与MaxMind的GeoIP2数据库相当,但准确度较低。GeoLite2国家、城市和ASN数据库每周更新两次,即每周二和周五。GeoLite2数据还可作为GeoLite2Country和GeoLite2CityWeb服务中的Web服务提供。GeoLite2......
  • e-chart实现上下图标使用一个tooltip移入事件
    有的需求需要一次移入事件展示多个图标的tooltip方便用户查看,效果如下链接如下:e-chart主要配置是tooltip:{trigger:'axis',axisPointer:{animation:false}},axisPointer:{link:[{xAxisIndex:'all'}]......
  • 使用K8S集群运行MongoDB7.0
    参考:https://hub.docker.com/_/mongo创建PVC创建PVC用于数据持久化#catmongodb-pvc.yamlapiVersion:v1kind:PersistentVolumeClaimmetadata:name:mongodb-pvcspec:accessModes:-ReadWriteOnceresources:requests:storage:22Gistorag......
  • 使用C++20协程和io_uring优雅地实现异步IO
    距离2020年已经过去很久了,各大编译器对于C++20各项标准的支持也日趋完善,无栈协程也是其中之一,所以我就尝试着拿协程与io_uring实现了一下proactor模式,这篇文章用来记录一下我的设计和想法。除此之外,我们能在网络上找到许多优秀的C++20协程的教程以及许多优秀的协程应用(库),但从协程......
  • cubemx使用dma实现Uart不定长数据接收
    CubeMx版本: volatileuint8_trecv_end_flag=0;volatileuint32_trx_len=0;volatileuint32_trx_len2=0;uint8_trx_buffer[BUFFER_SIZE]={0};uint8_trx_buffer2[BUFFER_SIZE]={0};voidUSART1_IRQHandler(void){/*USERCODEBEGINUSART1_IRQn0*/......
  • 在创建的Vue工程中使用el-radio定义单选框,点击不显示效果
    之前在vue工程中的组件时下面这样的<template><el-radiov-model="radio"value="0">男</el-radio><el-radiov-model="radio"value="1">女</el-radio></template> 结果是点击不显示已选中 需要在script中引入vu......