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
This can be serialized by custom serializers in squidstore.core for libGDX Json or squidfreeze.core for Kryo. Fory doesn't need a serializer registered.
UniqueIdentifier.GENERATOR, and can be used independently via generate().
This can be serialized by custom serializers in squidstore.core for libGDX Json or squidfreeze.core for Kryo. Fory doesn't need a serializer registered.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.github.tommyettinger.ds.support.util.PartialParser<UniqueIdentifier.Generator> A jdkgdxds PartialParser that can be used to read Generator values from String-serialized data structures containing them. -
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.Generator(CharSequence serialized) Given a CharSequence containing the output ofstringSerialize(), this creates a new UniqueIdentifier.Generator with the same data as the UniqueIdentifier.Generator that was serialized.Generator(CharSequence data, int start) Given a CharSequence containing the output ofstringSerialize(), this creates a new UniqueIdentifier.Generator with the same data as the UniqueIdentifier.Generator that was serialized. -
Method Summary
Modifier and TypeMethodDescription<S extends CharSequence & Appendable>
SappendTo(S sb) Appends the serialized String format for this Generator to the given Appendable CharSequence, such as aStringBuilderorCharList.generate()Creates a new UniqueIdentifier, advancing the state of this Generator in the process.intgetA()intgetB()intgetC()intgetD()Loads the state of another serialized Generator (or UniqueIdentifier) into this.stringDeserialize(CharSequence data, int start) Loads the state of another serialized Generator (or UniqueIdentifier) into this.
-
Field Details
-
PARSER
public static final com.github.tommyettinger.ds.support.util.PartialParser<UniqueIdentifier.Generator> PARSERA jdkgdxds PartialParser that can be used to read Generator values from String-serialized data structures containing them.
-
-
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 CharSequence 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 or other CharSequence 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 CharSequence almost always produced bystringSerialize()
-
Generator
Given a CharSequence 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 or other CharSequence 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 CharSequence often produced bystringSerialize()orappendTo(CharSequence)start- the first index, inclusive, to read 35 chars from
-
-
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
-
appendTo
Appends the serialized String format for this Generator to the given Appendable CharSequence, such as aStringBuilderorCharList. This separates the fourintvalues, printed as unsigned withBase.BASE16, with dollar signs.- Type Parameters:
S- any Appendable CharSequence, such as aStringBuilderorCharList- Parameters:
sb- any Appendable CharSequence, such as aStringBuilder- Returns:
- sb, for chaining
-
stringDeserialize
Loads the state of another serialized Generator (or UniqueIdentifier) into this. This requires a 35-char CharSequence (such as a 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 CharSequence often produced bystringSerialize()orappendTo(CharSequence)- Returns:
- this Generator, after deserializing
-
stringDeserialize
Loads the state of another serialized Generator (or UniqueIdentifier) into this. This requires a 35-char CharSequence (such as a String) at minimum after start with four 8-hex-digit sections, but the delimiters between sections are permitted to be anything (such as'_'forUniqueIdentifieror'$'for this).- Parameters:
data- a CharSequence often produced bystringSerialize()orappendTo(CharSequence)start- the first index, inclusive, to read 35 chars from- Returns:
- this Generator, after deserializing
-