yeg
2026-08-31 9bd8e752b5d7ba7177fa16d74565b741699f5c22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.ruoyi.system.service.impl;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
 
/** 按单个接收区间检查历史序号;暂停和区间边界由调用方分组后自然排除。 */
final class IntervalIntegrityChecker
{
    record Gap(long from, long to) { }
 
    private IntervalIntegrityChecker() { }
 
    static List<Gap> gaps(Collection<Long> sequenceIds)
    {
        if (sequenceIds == null || sequenceIds.isEmpty()) return List.of();
        Set<Long> unique = new LinkedHashSet<>();
        sequenceIds.stream().filter(value -> value != null && value > 0).forEach(unique::add);
        List<Long> ordered = new ArrayList<>(unique);
        ordered.sort(Comparator.naturalOrder());
        List<Gap> result = new ArrayList<>();
        for (int index = 1; index < ordered.size(); index++)
        {
            long previous = ordered.get(index - 1);
            long current = ordered.get(index);
            if (current > previous + 1) result.add(new Gap(previous + 1, current - 1));
        }
        return List.copyOf(result);
    }
}