yangys
2024-05-18 040976de6f9934b99f30268a28e2ecf42260e217
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
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.qianwen.core.sequence.range;
 
import java.util.concurrent.atomic.AtomicLong;
 
 
public class SeqRange {
    private final long min;
    private final long max;
    private final AtomicLong value;
    private volatile boolean over = false;
 
    public SeqRange(long min, long max) {
        this.min = min;
        this.max = max;
        this.value = new AtomicLong(min);
    }
 
    public long getAndIncrement() {
        long currentValue = this.value.getAndIncrement();
        if (currentValue > this.max) {
            this.over = true;
            return -1L;
        }
        return currentValue;
    }
 
    public long getMin() {
        return this.min;
    }
 
    public long getMax() {
        return this.max;
    }
 
    public boolean isOver() {
        return this.over;
    }
 
    public void setOver(boolean over) {
        this.over = over;
    }
 
    public String toString() {
        return "SeqRange{min=" + this.min + ", max=" + this.max + ", value=" + this.value + ", over=" + this.over + '}';
    }
}