美文网首页
java8-stream-应用demo

java8-stream-应用demo

作者: 海德堡绝尘 | 来源:发表于2019-12-13 15:27 被阅读0次
    package com.niewj.stream;
    
    import lombok.Getter;
    import lombok.Setter;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * @Author weijun.nie
     * @Date 2019/12/13 14:28
     * @Version 1.0
     */
    public class StreamDemo {
    
        public static void main(String[] args) {
            doDone();
        }
    
        private static void doDone() {
            List<Book> books = new ArrayList<>();
            books.add(Book.of("9787500652045", "城南旧事", 198, "中国青年出版社", 16.00f, 9.0f, new Author("林海音", 100)));
            books.add(Book.of("10019-1979", "呐喊", 160, "人民文学出版社", 0.36f, 8.9f, new Author("鲁迅", 1)));
            books.add(Book.of("9787506022583", "十年光阴", 306, "人民文学出版社", 28.00f, 8.5f, new Author("阿南", 10000)));
            books.add(Book.of("9787532740291", "变形记", 457, "上海译文出版社", 28.00f, 8.7f, new Author("卡夫卡", 0)));
            books.add(Book.of("9787500652045", "百年孤独", 360, "南海出版公司", 39.50f, 9.0f, new Author("马尔克斯", 2)));
            books.add(Book.of("9787020036509", "茶馆", 142, "人民文学出版社", 9.80f, 9.0f, new Author("老舍", 3)));
            books.add(Book.of("9787500601593", "红岩", 596, "中国青年出版社", 22.00f, 7.6f, new Author("罗广斌", 80)));
            books.add(Book.of("10019-1985", "朝花夕拾", 92, "人民文学出版社", 0.25f, 8.7f, new Author("鲁迅", 1)));
    
            // 1. 找出 最 薄/贵/高分 的一本书
    
            // 2. 获取所有出版社集合
    
            // 3. 所有书按照评分降序排序, 评分相同的按照价格升序
    
            // 4. 拿到所有作者集合
    
            // 5. 所有书按照作者排名降序排列
    
            // 6. 计算所有书的页数和以及平均页数
    
            // 7. 按照书名的长度升序排列
    
            // 8. 按照书名的长度升序排列并得到书名集合
    
        }
    }
    
    @Setter
    @Getter
    class Book {
        private String isbn;
        private String name;
        private int pages;
        private String press;
        private float price;
        private float score;
        private Author author;
    
        public static Book of(String isbn, String name, int pages, String press, float price, float score, Author author) {
            Book book = new Book();
            book.isbn = isbn;
            book.name = name;
            book.pages = pages;
            book.press = press;
            book.price = price;
            book.score = score;
            book.author = author;
            return book;
        }
    
    }
    
    @Setter
    @Getter
    class Author {
        /**
         * 作家笔名
         */
        private String penName;
    
        /**
         * 作家榜-排名
         */
        private int rank;
    
        public Author(String penName, int rank) {
            this.penName = penName;
            this.rank = rank;
        }
    
        @Override
        public String toString() {
            return rank + " --> [" + this.penName + "]";
        }
    }
    
    

    相关文章

      网友评论

          本文标题:java8-stream-应用demo

          本文链接:https://www.haomeiwen.com/subject/mfifnctx.html