net.kolls.railworld.io
Interface SaveLoad

All Known Subinterfaces:
Car, Script, SignalProgram
All Known Implementing Classes:
AbstractCar, AutoControl, Autorack, Boxcar, Caboose, CachedCar, Coveredhopper, Engine, Flatcar, Green, Intermodal, MixControl, Openhopper, Passenger, Red, Stockcar, Tankcar, TrainControl, UserControl, Yellow

public interface SaveLoad

Allows a class to specify data to save and restore data on load. This is essentially serialization; the reason for using a custom class rather than serializable is so that scripts instances can be saved as well using the same technique as regular classes. Script classes are can't use newInstance, so we have an alternative here.

Author:
Steve Kollmansberger

Method Summary
 void load(java.util.Map<java.lang.String,java.lang.String> data)
          Load from saved.
 java.lang.Object newInstance()
          like getClass().newInstance().
 java.util.Map<java.lang.String,java.lang.String> save()
          Store all persistent data into a map and return for saving.
 java.lang.String toString()
           
 

Method Detail

save

java.util.Map<java.lang.String,java.lang.String> save()
Store all persistent data into a map and return for saving. May return null if there is no data to save. This will be treated the same as the empty map.

Returns:
A list of key-value pairs to be saved.

load

void load(java.util.Map<java.lang.String,java.lang.String> data)
Load from saved.

Parameters:
data - Key value pairs saved by an instance of this class

newInstance

java.lang.Object newInstance()
like getClass().newInstance(). Allows script objects to also be copied.

Returns:
A new instance of this class

toString

java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Give the name of this type so it can be reconstructed by the factory.