Class INoise.Serializer

java.lang.Object
com.github.yellowstonegames.grid.INoise.Serializer
Enclosing interface:
INoise

public static class INoise.Serializer extends Object
  • Method Details

    • register

      public static void register(INoise noise)
      Given a (typically freshly-constructed and never-reused) INoise, this registers that instance by its INoise.getTag() in a Map, so that this type of INoise can be deserialized correctly by deserialize(String). The INoise type must implement INoise.getTag(), INoise.stringSerialize(), INoise.stringDeserialize(String), and INoise.copy().
      Parameters:
      noise - a (typically freshly-constructed) INoise that should never be reused elsewhere
    • get

      public static INoise get(String tag)
      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

      public static String serialize(INoise noise)
      Given an INoise that implements INoise.stringSerialize() and INoise.getTag(), this produces a serialized String that stores the exact state of the INoise. This serialized String can be read back in by deserialize(String).
      This is preferred over calling INoise.stringSerialize() on its own, because it prepends the INoise.getTag() to allow deserialize(String) to load it back regardless of implementation. If you know only one INoise class will be used, you can use its INoise.stringSerialize() and its INoise.stringDeserialize(String) methods to save and restore that single class.
      Parameters:
      noise - an INoise that implements INoise.stringSerialize() and INoise.getTag()
      Returns:
      a String that can be read back in by deserialize(String)
    • deserialize

      public static INoise deserialize(String data)
      Given a String produced by calling serialize(INoise) on any registered implementation (as with register(INoise)), this reads in the deserialized data and returns a new INoise 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 cannot read back the direct output of INoise.stringSerialize(); it needs the tag prepended by serialize(INoise) to work.
      This is preferred over calling INoise.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 by serialize(INoise)
      Returns:
      a new INoise with the appropriate type internally, using the state from data
    • copyTags

      public static com.github.tommyettinger.ds.ObjectSet<String> copyTags()
      Creates an unordered Set of all String tags for INoise types Serializer knows, and returns it. A tag can be used with get(String) to retrieve the corresponding INoise.
      Returns:
      an ObjectSet of all String tags for INoise types this knows
    • copyNoises

      public static com.github.tommyettinger.ds.ObjectList<INoise> 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 -1L before it is put in the List. This includes wrapper types such as NoiseWrapper, using their default INoise and other settings when retrieved.
      Returns:
      an ObjectList of copies of the INoise instances this knows