Module com.github.f4b6a3.uuid
Interface NodeIdFunction
-
- All Superinterfaces:
LongSupplier
- All Known Implementing Classes:
DefaultNodeIdFunction,HashNodeIdFunction,MacNodeIdFunction,RandomNodeIdFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface NodeIdFunction extends LongSupplier
It must return a number between 0 and 2^48-1. UsetoExpectedRange(long)to set the output within the range 0 to 2^48-1. If necessary, usetoMulticast(long)to set the multicast bit. It also sets the output within the range 0 to 2^48-1. Examples:// A `NodeIdFunction` that always returns a random number between 0 and 2^48-1. NodeIdFunction f = () -> NodeIdFunction.getRandom();
// A `NodeIdFunction` that always returns the same number between 0 and 2^48-1. final long number = 1234567890; NodeIdFunction f = () -> NodeIdFunction.toExpectedRange(number);
-
-
Method Summary
Static Methods Modifier and Type Method Description static longgetMulticastRandom()This method return a new multicast random node identifier.static longgetRandom()This method return a new random node identifier.static booleanisMulticast(long nodeid)This method checks if the multicast bit of a node identifier is set.static longtoExpectedRange(long nodeid)This method clears the unnecessary leading bits so that the resulting number is in the range 0 to 2^48-1.static longtoMulticast(long nodeid)This method sets the multicast bit of a node identifier.-
Methods inherited from interface java.util.function.LongSupplier
getAsLong
-
-
-
-
Method Detail
-
getRandom
static long getRandom()
This method return a new random node identifier.- Returns:
- a node identifier in the range 0 to 2^48-1.
-
getMulticastRandom
static long getMulticastRandom()
This method return a new multicast random node identifier.- Returns:
- a node identifier in the range 0 to 2^48-1.
-
toExpectedRange
static long toExpectedRange(long nodeid)
This method clears the unnecessary leading bits so that the resulting number is in the range 0 to 2^48-1. The result is equivalent ton % 2^48.- Parameters:
nodeid- the node identifier- Returns:
- a node identifier in the range 0 to 2^48-1.
-
toMulticast
static long toMulticast(long nodeid)
This method sets the multicast bit of a node identifier. It also clears the unnecessary leading bits so that the resulting number is within the range 0 to 281474976710655 (2^48-1).- Parameters:
nodeid- the node identifier- Returns:
- a node identifier with the multicast bit set
-
isMulticast
static boolean isMulticast(long nodeid)
This method checks if the multicast bit of a node identifier is set.- Parameters:
nodeid- a node identifier- Returns:
- true if the node identifier is multicast
-
-