Class UniqueIdentifier.Generator

java.lang.Object
com.github.yellowstonegames.core.UniqueIdentifier.Generator
Enclosing class:
UniqueIdentifier

public static final class UniqueIdentifier.Generator extends Object
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().
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 Details

    • PARSER

      public static final com.github.tommyettinger.ds.support.util.PartialParser<UniqueIdentifier.Generator> PARSER
      A 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 from Math.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 calling UniqueIdentifier.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 long
      stateB - 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 0
      b - may be any int unless all are 0
      c - may be any int unless all are 0
      d - may be any int unless all are 0
    • Generator

      public Generator(CharSequence serialized)
      Given a CharSequence containing the output of stringSerialize(), 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 '_' for UniqueIdentifier or '$' for this).
      Parameters:
      serialized - a CharSequence almost always produced by stringSerialize()
    • Generator

      public Generator(CharSequence data, int start)
      Given a CharSequence containing the output of stringSerialize(), 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 '_' for UniqueIdentifier or '$' for this).
      Parameters:
      data - a CharSequence often produced by stringSerialize() or appendTo(CharSequence)
      start - the first index, inclusive, to read 35 chars from
  • Method Details

    • generate

      public UniqueIdentifier 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

      public String stringSerialize()
    • appendTo

      public <S extends CharSequence & Appendable> S appendTo(S sb)
      Appends the serialized String format for this Generator to the given Appendable CharSequence, such as a StringBuilder or CharList. This separates the four int values, printed as unsigned with Base.BASE16, with dollar signs.
      Type Parameters:
      S - any Appendable CharSequence, such as a StringBuilder or CharList
      Parameters:
      sb - any Appendable CharSequence, such as a StringBuilder
      Returns:
      sb, for chaining
    • stringDeserialize

      public UniqueIdentifier.Generator stringDeserialize(CharSequence data)
      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 '_' for UniqueIdentifier or '$' for this).
      Parameters:
      data - a CharSequence often produced by stringSerialize() or appendTo(CharSequence)
      Returns:
      this Generator, after deserializing
    • stringDeserialize

      public UniqueIdentifier.Generator stringDeserialize(CharSequence data, int start)
      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 '_' for UniqueIdentifier or '$' for this).
      Parameters:
      data - a CharSequence often produced by stringSerialize() or appendTo(CharSequence)
      start - the first index, inclusive, to read 35 chars from
      Returns:
      this Generator, after deserializing