Package edu.cmu.tetrad.util
Class TetradSerializableUtils
java.lang.Object
edu.cmu.tetrad.util.TetradSerializableUtils
Contains methods used by TestSerialization to ensure that previous "stable" versions of Tetrad will by loadable by
later "stable" versions of Tetrad.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTetradSerializableUtils
(String serializableScope, String currentDirectory, String archiveDirectory) Blank constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates a zip archive of the currently serialized files in getCurrentDirectory(), placing the archive in getArchiveDirectory().void
Checks all of the classes in the serialization scope that implement TetradSerializable to make sure all of their fields are either themselves (a) primitive, (b) TetradSerializable, or (c) assignable from types designated as safely serializable by virtue of being included in the safelySerializableTypes array (see), or are arrays whose lowest order component types satisfy either (a), (b), or (c).void
Clears the archive directory.void
Deserializes examplars stored in archives in getArchiveDirectory().void
Deserializes all files in the given directory, as a test to make sure they can all be deserialized.void
Finds all classes inside the stated scope that implement TetradSerializable and serializes them out to the getCurrentDirectory() directory.
-
Constructor Details
-
TetradSerializableUtils
-
-
Method Details
-
checkNestingOfFields
public void checkNestingOfFields()Checks all of the classes in the serialization scope that implement TetradSerializable to make sure all of their fields are either themselves (a) primitive, (b) TetradSerializable, or (c) assignable from types designated as safely serializable by virtue of being included in the safelySerializableTypes array (see), or are arrays whose lowest order component types satisfy either (a), (b), or (c). Safely serializable classes in the Java API currently include collections classes, plus String and Class. Collections classes are included, since their types will be syntactically checkable in JDK 1.5. String and Class are members of a broader type of Class whose safely can by checked by making sure there is no way to pass into them via constructor or method argument any object that is not TetradSerializable or safely serializable. But it's easy enough now to just make a list.- See Also:
-
serializeCurrentDirectory
Finds all classes inside the stated scope that implement TetradSerializable and serializes them out to the getCurrentDirectory() directory. Abstract methods and interfaces are skipped over. For all other classes C, it is assumed that C has a static constructor of the following form:public static C serializableInstance() { // Returns an instance of C. May be a mind-numbingly simple // instance, no need to get fancy. }
The instance returned may be mind-numbingly simple; there is no need to get fancy. It may change over time. The point is to make sure that instances serialized out with earlier versions load with the currentDirectory version.- Throws:
RuntimeException
- if clazz cannot be serialized. This exception has an informative message and wraps the originally thrown exception as root cause.
-
clearArchiveDirectory
public void clearArchiveDirectory()Clears the archive directory. -
deserializeCurrentDirectory
Deserializes all files in the given directory, as a test to make sure they can all be deserialized.- Throws:
RuntimeException
- if clazz cannot be serialized. This exception has an informative message and wraps the originally thrown exception as root cause.
-
archiveCurrentDirectory
Creates a zip archive of the currently serialized files in getCurrentDirectory(), placing the archive in getArchiveDirectory().- Throws:
RuntimeException
- if clazz cannot be serialized. This exception has an informative message and wraps the originally thrown exception as root cause.- See Also:
-
deserializeArchivedVersions
Deserializes examplars stored in archives in getArchiveDirectory().- Throws:
RuntimeException
- if clazz cannot be serialized. This exception has an informative message and wraps the originally thrown exception as root cause.- See Also:
-