Class Deserializer

java.lang.Object
com.github.tommyettinger.random.Deserializer

public final class Deserializer extends Object
Allows deserializing any type of EnhancedRandom by looking up its tag in a registry. The main way of using this is the deserialize(String) (or deserialize(String, Base)) method. By default, all EnhancedRandom types in this library are registered by default, and can be deserialized.
  • Method Details

    • register

      public static void register(EnhancedRandom random)
      Given a (typically freshly-constructed and never-reused) EnhancedRandom, this registers that instance by its EnhancedRandom.getTag() in a Map, so that this type of EnhancedRandom can be deserialized correctly by deserialize(String, Base).
      Parameters:
      random - a (typically freshly-constructed) EnhancedRandom that should never be reused elsewhere
    • register

      public static void register(Distribution distribution)
      Given a (typically freshly-constructed and never-reused) Distribution, this registers that instance by its Distribution.getTag() in a Map, so that this type of Distribution can be deserialized correctly by deserializeDistribution(String, Base).
      Parameters:
      distribution - a (typically freshly-constructed) Distribution that should never be reused elsewhere
    • get

      public static EnhancedRandom get(String tag)
      Gets a copy of the EnhancedRandom registered with the given tag, or null if this has nothing registered for the given tag.
      Parameters:
      tag - a non-null String that could be used as a tag for an EnhancedRandom registered with this class
      Returns:
      a new copy of the corresponding EnhancedRandom, or null if none was found
    • getDistribution

      public static Distribution getDistribution(String tag)
      Gets a copy of the Distribution registered with the given tag, or null if this has nothing registered for the given tag.
      Parameters:
      tag - a non-null String that could be used as a tag for a Distribution registered with this class
      Returns:
      a new copy of the corresponding Distribution, or null if none was found
    • deserialize

      public static EnhancedRandom deserialize(String data)
      Given a String produced by calling EnhancedRandom.stringSerialize() on any registered implementation (as with register(EnhancedRandom)), this reads in the deserialized data and returns a new EnhancedRandom of the appropriate type. This relies on the tag of the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time.
      Parameters:
      data - serialized String data probably produced by EnhancedRandom.stringSerialize()
      Returns:
      a new EnhancedRandom with the appropriate type internally, using the state from data
    • deserialize

      public static EnhancedRandom deserialize(String data, com.github.tommyettinger.digital.Base base)
      Given a String produced by calling EnhancedRandom.stringSerialize(Base) on any registered implementation (as with register(EnhancedRandom)), this reads in the deserialized data and returns a new EnhancedRandom of the appropriate type. This relies on the tag of the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time. This overload allows specifying a Base, which must match the Base used to serialize the data (the Base defaults to Base.BASE16).
      Parameters:
      data - serialized String data probably produced by EnhancedRandom.stringSerialize(Base)
      base - which Base to use, from the "digital" library, such as Base.BASE10
      Returns:
      a new EnhancedRandom with the appropriate type internally, using the state from data
    • deserializeDistribution

      public static Distribution deserializeDistribution(String data)
      Given a String produced by calling Distribution.stringSerialize() on any registered implementation (as with register(Distribution)), this reads in the deserialized data and returns a new Distribution of the appropriate type. This relies on the tag of the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time.
      Parameters:
      data - serialized String data probably produced by Distribution.stringSerialize()
      Returns:
      a new Distribution with the appropriate type internally, using the state from data
    • deserializeDistribution

      public static Distribution deserializeDistribution(String data, com.github.tommyettinger.digital.Base base)
      Given a String produced by calling Distribution.stringSerialize(Base) on any registered implementation (as with register(Distribution)), this reads in the deserialized data and returns a new Distribution of the appropriate type. This relies on the tag of the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time. This overload allows specifying a Base, which must match the Base used to serialize the data (the Base defaults to Base.BASE16).
      Parameters:
      data - serialized String data probably produced by Distribution.stringSerialize(Base)
      base - which Base to use, from the "digital" library, such as Base.BASE10
      Returns:
      a new Distribution with the appropriate type internally, using the state from data
    • copyTags

      public static HashSet<String> copyTags()
      Creates an unordered Set of all String tags for EnhancedRandom types Deserializer knows, and returns it.
      Returns:
      a Set of all String tags for EnhancedRandom types this knows
    • copyRandoms

      public static ArrayList<EnhancedRandom> copyRandoms()
      Returns an unordered List of copies of the EnhancedRandom "prototype" objects this uses during deserialization. Each EnhancedRandom copy is seeded with -1L before it is put in the List.
      Returns:
      a List of copies of the EnhancedRandom instances this knows
    • copyDistributionTags

      public static HashSet<String> copyDistributionTags()
      Creates an unordered Set of all String tags for Distribution types Deserializer knows, and returns it.
      Returns:
      a Set of all String tags for Distribution types this knows
    • copyDistributions

      public static ArrayList<Distribution> copyDistributions()
      Returns an unordered List of copies of the Distribution "prototype" objects this uses during deserialization. Each Distribution copy's generator is seeded with 1L before it is put in the List.
      Returns:
      a List of copies of the Distribution instances this knows