Package com.github.tommyettinger.random
Class Deserializer
java.lang.Object
com.github.tommyettinger.random.Deserializer
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 Summary
Modifier and TypeMethodDescriptionstatic ArrayList<Distribution>
Returns an unordered List of copies of the Distribution "prototype" objects this uses during deserialization.Creates an unordered Set of all String tags for Distribution types Deserializer knows, and returns it.static ArrayList<EnhancedRandom>
Returns an unordered List of copies of the EnhancedRandom "prototype" objects this uses during deserialization.copyTags()
Creates an unordered Set of all String tags for EnhancedRandom types Deserializer knows, and returns it.static EnhancedRandom
deserialize
(String data) Given a String produced by callingEnhancedRandom.stringSerialize()
on any registered implementation (as withregister(EnhancedRandom)
), this reads in the deserialized data and returns a new EnhancedRandom of the appropriate type.static EnhancedRandom
deserialize
(String data, com.github.tommyettinger.digital.Base base) Given a String produced by callingEnhancedRandom.stringSerialize(Base)
on any registered implementation (as withregister(EnhancedRandom)
), this reads in the deserialized data and returns a new EnhancedRandom of the appropriate type.static Distribution
Given a String produced by callingDistribution.stringSerialize()
on any registered implementation (as withregister(Distribution)
), this reads in the deserialized data and returns a new Distribution of the appropriate type.static Distribution
deserializeDistribution
(String data, com.github.tommyettinger.digital.Base base) Given a String produced by callingDistribution.stringSerialize(Base)
on any registered implementation (as withregister(Distribution)
), this reads in the deserialized data and returns a new Distribution of the appropriate type.static EnhancedRandom
Gets a copy of the EnhancedRandom registered with the given tag, or null if this has nothing registered for the given tag.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.static void
register
(Distribution distribution) Given a (typically freshly-constructed and never-reused) Distribution, this registers that instance by itsDistribution.getTag()
in a Map, so that this type of Distribution can be deserialized correctly bydeserializeDistribution(String, Base)
.static void
register
(EnhancedRandom random) Given a (typically freshly-constructed and never-reused) EnhancedRandom, this registers that instance by itsEnhancedRandom.getTag()
in a Map, so that this type of EnhancedRandom can be deserialized correctly bydeserialize(String, Base)
.
-
Method Details
-
register
Given a (typically freshly-constructed and never-reused) EnhancedRandom, this registers that instance by itsEnhancedRandom.getTag()
in a Map, so that this type of EnhancedRandom can be deserialized correctly bydeserialize(String, Base)
.- Parameters:
random
- a (typically freshly-constructed) EnhancedRandom that should never be reused elsewhere
-
register
Given a (typically freshly-constructed and never-reused) Distribution, this registers that instance by itsDistribution.getTag()
in a Map, so that this type of Distribution can be deserialized correctly bydeserializeDistribution(String, Base)
.- Parameters:
distribution
- a (typically freshly-constructed) Distribution that should never be reused elsewhere
-
get
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
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
Given a String produced by callingEnhancedRandom.stringSerialize()
on any registered implementation (as withregister(EnhancedRandom)
), this reads in the deserialized data and returns a new EnhancedRandom of the appropriate type. This relies on thetag
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 byEnhancedRandom.stringSerialize()
- Returns:
- a new EnhancedRandom with the appropriate type internally, using the state from data
-
deserialize
Given a String produced by callingEnhancedRandom.stringSerialize(Base)
on any registered implementation (as withregister(EnhancedRandom)
), this reads in the deserialized data and returns a new EnhancedRandom of the appropriate type. This relies on thetag
of the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time. This overload allows specifying aBase
, which must match the Base used to serialize the data (the Base defaults toBase.BASE16
).- Parameters:
data
- serialized String data probably produced byEnhancedRandom.stringSerialize(Base)
base
- which Base to use, from the "digital" library, such asBase.BASE10
- Returns:
- a new EnhancedRandom with the appropriate type internally, using the state from data
-
deserializeDistribution
Given a String produced by callingDistribution.stringSerialize()
on any registered implementation (as withregister(Distribution)
), this reads in the deserialized data and returns a new Distribution of the appropriate type. This relies on thetag
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 byDistribution.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 callingDistribution.stringSerialize(Base)
on any registered implementation (as withregister(Distribution)
), this reads in the deserialized data and returns a new Distribution of the appropriate type. This relies on thetag
of the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time. This overload allows specifying aBase
, which must match the Base used to serialize the data (the Base defaults toBase.BASE16
).- Parameters:
data
- serialized String data probably produced byDistribution.stringSerialize(Base)
base
- which Base to use, from the "digital" library, such asBase.BASE10
- Returns:
- a new Distribution with the appropriate type internally, using the state from data
-
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
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
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
Returns an unordered List of copies of the Distribution "prototype" objects this uses during deserialization. Each Distribution copy's generator is seeded with1L
before it is put in the List.- Returns:
- a List of copies of the Distribution instances this knows
-