Class UniqueIdentifier.Generator
java.lang.Object
com.github.yellowstonegames.core.UniqueIdentifier.Generator
- Enclosing class:
UniqueIdentifier
The type used as a factory to produce UniqueIdentifiers that are actually unique for a given Generator.
This is used in
UniqueIdentifier.GENERATOR, and can be used independently via generate().-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Generator with a and b states derived from the current time in nanoseconds, and one of (2 to the 48) possible random initial c and d states pulled fromMath.random().Generator(int a, int b, int c, int d) Creates a new Generator using the given 4 states verbatim, unless they are all 0 (then it treats d as 1).Generator(long stateA, long stateB) Creates a new Generator given two long values for state.Given a String containing the output ofstringSerialize(), this creates a new UniqueIdentifier.Generator with the same data as the UniqueIdentifier.Generator that was serialized. -
Method Summary
-
Constructor Details
-
Generator
public Generator()Creates a new Generator with a and b states derived from the current time in nanoseconds, and one of (2 to the 48) possible random initial c and d states pulled fromMath.random(). This means that unless trillions of Generator instances are created before the nanosecond time changes, this cannot have the same initial state as another Generator. Eventually, all valid generators will enter all valid states, but this should really only be a concern after callingUniqueIdentifier.next()for over a year continuously. -
Generator
public Generator(long stateA, long stateB) Creates a new Generator given two long values for state.- Parameters:
stateA- may be any longstateB- may be any long unless both states are 0, in which case this is treated as 1
-
Generator
public Generator(int a, int b, int c, int d) Creates a new Generator using the given 4 states verbatim, unless they are all 0 (then it treats d as 1).- Parameters:
a- may be any int unless all are 0b- may be any int unless all are 0c- may be any int unless all are 0d- may be any int unless all are 0
-
Generator
Given a String containing the output ofstringSerialize(), this creates a new UniqueIdentifier.Generator with the same data as the UniqueIdentifier.Generator that was serialized. This requires a 35-char String at minimum with four 8-hex-digit sections, but the delimiters between sections are permitted to be anything (such as'_'forUniqueIdentifieror'$'for this).- Parameters:
serialized- a String almost always produced bystringSerialize()
-
-
Method Details
-
generate
Creates a new UniqueIdentifier, advancing the state of this Generator in the process.- Returns:
- a new UniqueIdentifier that will not occur again from this Generator unless (2 to the 128) - 1 more identifiers are generated
-
getA
public int getA() -
getB
public int getB() -
getC
public int getC() -
getD
public int getD() -
stringSerialize
-
stringDeserialize
Loads the state of another serialized Generator (or UniqueIdentifier) into this. This requires a 35-char String at minimum with four 8-hex-digit sections, but the delimiters between sections are permitted to be anything (such as'_'forUniqueIdentifieror'$'for this).- Parameters:
data- a String almost always produced bystringSerialize()- Returns:
- this Generator, after deserializing
-