• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trydofor / professional-mirana / #112

19 Mar 2025 04:46AM UTC coverage: 87.128% (+2.7%) from 84.4%
#112

push

web-flow
Merge pull request #53 from trydofor/develop

bump 3.0.0 to semver

1645 of 1747 new or added lines in 25 files covered. (94.16%)

2 existing lines in 1 file now uncovered.

7141 of 8196 relevant lines covered (87.13%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/src/main/java/pro/fessional/mirana/id/LightId.java
1
package pro.fessional.mirana.id;
2

3
import org.jetbrains.annotations.NotNull;
4

5
/**
6
 * <pre>
7
 * 64 bit = 1bit(0 fixed) + 8bit (CRC8) + 1bit(Layout) + 54bit(block+sequence)
8
 * 8bit reserved for Crc8Long encode, default 0
9
 * 1bit whole-seq(0); block-seq(1)
10
 * whole-seq(0) = sequence(54bit=18014398509481983)
11
 * block-seq(1) = block(9bit=512) + sequence((54-9=45)bit=35184372088831)
12
 * for 512 block unstopped 50000 id/second, running
13
 * (2^45 -1)/(365*24*3600*50000) = 22.3 years
14
 * </pre>
15
 *
16
 * @author trydofor
17
 * @see pro.fessional.mirana.code.Crc8Long
18
 * @since 2019-05-20
19
 */
20
public class LightId {
21

22
    public static final LightId NONE = new LightId(-1, -1);
1✔
23
    public static final LightId ZERO = new LightId(0, 0);
1✔
24

25
    public static final int BIT_LIGHT = 55;
26

27
    public static final int BIT_BLOCK = 9;
28
    public static final int MIN_BLOCK = 0;
29
    public static final int MAX_BLOCK = 1 << BIT_BLOCK;
30

31
    public static final int BIT_SEQ_WHOLE = BIT_LIGHT - 1;
32
    public static final int BIT_SEQ_BLOCK = BIT_SEQ_WHOLE - BIT_BLOCK;
33
    public static final long MIN_SEQ = 0L;
34
    public static final long MAX_SEQ_WHOLE = (1L << BIT_SEQ_WHOLE) - 1;
35
    public static final long MAX_SEQ_BLOCK = (1L << BIT_SEQ_BLOCK) - 1;
36

37
    public static final long TKN_LAYOUT = 1L << BIT_SEQ_WHOLE;
38

39
    private final int block;
40
    private final long sequence;
41

42
    /**
43
     * Constructed by block and sequence.
44
     * The default value of block is from 0 to 512, which can be modified by LightIdUtil.forceBlockBit.
45
     * 0 means whole-seq layout, above 1 is block-seq layout.
46
     */
47
    public LightId(int block, long sequence) {
1✔
48
        this.block = block;
1✔
49
        this.sequence = sequence;
1✔
50
    }
1✔
51

52
    /**
53
     * Get block, 0 means whole-seq layout, above 1 is block-seq layout
54
     */
55
    public int getBlock() {
56
        return block;
1✔
57
    }
58

59
    public long getSequence() {
60
        return sequence;
1✔
61
    }
62

63
    public final int component1() {
64
        return block;
1✔
65
    }
66

67
    public final long component2() {
68
        return sequence;
1✔
69
    }
70

71
    public long toLong() {
72
        return LightIdUtil.toId(block, sequence);
1✔
73
    }
74

75
    @NotNull
76
    @Override
77
    public String toString() {
78
        return "LightId(block=" + block + ", sequence=" + sequence + ")";
1✔
79
    }
80

81
    @Override
82
    public boolean equals(Object o) {
83
        if (this == o) return true;
1✔
84
        if (!(o instanceof LightId)) return false;
1✔
85

86
        LightId lightId = (LightId) o;
1✔
87

88
        // None
89
        if ((block < 0 || sequence < 0) && (lightId.block < 0 || lightId.sequence < 0)) return true;
1✔
90

91
        if (block != lightId.block) return false;
1✔
92
        return sequence == lightId.sequence;
1✔
93
    }
94

95
    @Override
96
    public int hashCode() {
97
        // None
98
        if (block < 0 || sequence < 0) return -1;
1✔
99

100
        int result = block;
×
NEW
101
        result = 31 * result + Long.hashCode(sequence);
×
102
        return result;
×
103
    }
104
}
105

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc