package stream;


import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.stream.Collectors;

public class StreamExample20 {
    public static void main(String[] args) {
        List<Transaction> transactions = Arrays.asList(
                new Transaction(1000L),
                new Transaction(2500L),
                new Transaction(1500L)
        );

        // 使用 Collectors.summarizingLong 统计金额信息
        LongSummaryStatistics amountStats = transactions.stream()
                .collect(Collectors.summarizingLong(Transaction::getAmount));

        System.out.println("Count: " + amountStats.getCount());
        System.out.println("Sum: " + amountStats.getSum());
        System.out.println("Min: " + amountStats.getMin());
        System.out.println("Max: " + amountStats.getMax());
        System.out.println("Average: " + amountStats.getAverage());
    }

    @Getter
    static class Transaction {
        private final long amount;

        public Transaction(long amount) {
            this.amount = amount;
        }
    }
}