Class INoise.Serializer
java.lang.Object
com.github.yellowstonegames.grid.INoise.Serializer
- Enclosing interface:
INoise
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.github.tommyettinger.ds.ObjectList<INoise> Returns a List (in no particular order) of copies of the INoise "prototype" objects this uses during deserialization.static com.github.tommyettinger.ds.ObjectSet<String> copyTags()Creates an unordered Set of all String tags for INoise types Serializer knows, and returns it.static INoisedeserialize(String data) Given a String produced by callingserialize(INoise)on any registered implementation (as withregister(INoise)), this reads in the deserialized data and returns a new INoise of the appropriate type.static INoiseGets a copy of the INoise registered with the given tag, or null if this has nothing registered for the given tag.static voidGiven a (typically freshly-constructed and never-reused) INoise, this registers that instance by itsINoise.getTag()in a Map, so that this type of INoise can be deserialized correctly bydeserialize(String).static StringGiven an INoise that implementsINoise.stringSerialize()andINoise.getTag(), this produces a serialized String that stores the exact state of the INoise.
-
Method Details
-
register
Given a (typically freshly-constructed and never-reused) INoise, this registers that instance by itsINoise.getTag()in a Map, so that this type of INoise can be deserialized correctly bydeserialize(String). The INoise type must implementINoise.getTag(),INoise.stringSerialize(),INoise.stringDeserialize(String), andINoise.copy().- Parameters:
noise- a (typically freshly-constructed) INoise that should never be reused elsewhere
-
get
Gets a copy of the INoise 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 INoise registered with this class- Returns:
- a new copy of the corresponding INoise, or null if none was found
-
serialize
Given an INoise that implementsINoise.stringSerialize()andINoise.getTag(), this produces a serialized String that stores the exact state of the INoise. This serialized String can be read back in bydeserialize(String).
This is preferred over callingINoise.stringSerialize()on its own, because it prepends theINoise.getTag()to allowdeserialize(String)to load it back regardless of implementation. If you know only one INoise class will be used, you can use itsINoise.stringSerialize()and itsINoise.stringDeserialize(String)methods to save and restore that single class.- Parameters:
noise- an INoise that implementsINoise.stringSerialize()andINoise.getTag()- Returns:
- a String that can be read back in by
deserialize(String)
-
deserialize
Given a String produced by callingserialize(INoise)on any registered implementation (as withregister(INoise)), this reads in the deserialized data and returns a new INoise of the appropriate type. This relies on thetagof the type being registered at deserialization time, though it doesn't actually need to be registered at serialization time. This cannot read back the direct output ofINoise.stringSerialize(); it needs the tag prepended byserialize(INoise)to work.
This is preferred over callingINoise.stringDeserialize(String)if the implementation of the serialized INoise is not known. This will return an INoise with the correct implementation, though the compile-time type will still be INoise and not anything more specific.- Parameters:
data- serialized String data probably produced byserialize(INoise)- Returns:
- a new INoise with the appropriate type internally, using the state from data
-
copyTags
Creates an unordered Set of all String tags for INoise types Serializer knows, and returns it. A tag can be used withget(String)to retrieve the corresponding INoise.- Returns:
- an ObjectSet of all String tags for INoise types this knows
-
copyNoises
Returns a List (in no particular order) of copies of the INoise "prototype" objects this uses during deserialization. Each INoise copy is seeded with-1Lbefore it is put in the List. This includes wrapper types such asNoiseWrapper, using their default INoise and other settings when retrieved.- Returns:
- an ObjectList of copies of the INoise instances this knows
-