All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.lunasaw.sip.common.sequence.GenerateSequenceImpl Maven / Gradle / Ivy

There is a newer version: 1.2.4
Show newest version
package io.github.lunasaw.sip.common.sequence;

import lombok.SneakyThrows;

import java.util.HashSet;
import java.util.Set;

/**
 * @author luna
 * @date 2023/10/13
 */
public class GenerateSequenceImpl implements GenerateSequence {

    public static long getSequence() {
        long timestamp = System.currentTimeMillis();
        return (timestamp & 0x3FFF) % Integer.MAX_VALUE;
    }

    @Override
    public Long generateSequence() {
        return getSequence();
    }


    @SneakyThrows
    public static void main(String[] args) {

        Set list = new HashSet<>();
        for (int i = 0; i < 10000; i++) {
            Thread.sleep(1);
            long sequence = getSequence();
            System.out.println(sequence);
            list.add(sequence);
        }

        System.out.println(list.size());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy