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

org.rx.util.IdGenerator Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.util;

public class IdGenerator {
    public static final IdGenerator DEFAULT = new IdGenerator();
    private final int min, max;
    private int val;

    public IdGenerator() {
        this(0, Integer.MAX_VALUE);
    }

    public IdGenerator(int min, int max) {
        val = this.min = min;
        this.max = max;
    }

    public synchronized int get() {
        return val;
    }

    public synchronized void set(int value) {
        val = value;
    }

    public synchronized int increment() {
        int i = ++val;
        if (i == max) {
            val = min;
        }
        return i;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy