private static Map<String, Long> calTrimOffset(Map<String, Stream> streams,
        Iterator<ElasticStreamSegmentMeta> segments, Iterator<ElasticStreamSegmentMeta> inflightSegments) {
        Map<String, Long> trimOffsets = new HashMap<>();

        inflightSegments.forEachRemaining(segMeta -> calTrimOffset(trimOffsets, segMeta));
        segments.forEachRemaining(segMeta -> calTrimOffset(trimOffsets, segMeta));

        streams.forEach((streamName, stream) -> {
            // if we haven't seen a stream before, then it is not used by any segment, and should be trimmed to the end.
            if (!trimOffsets.containsKey(streamName)) {
                trimOffsets.put(streamName, stream.nextOffset());
            }
        });
        return trimOffsets;
    }
Calculate trim offset of each stream.

@return stream trim offset map, key is stream name, value is trim offset.
core/src/main/scala/kafka/log/streamaspect/ElasticLogSegmentManager.java