Class TetradSerializableUtils

java.lang.Object
edu.cmu.tetrad.util.TetradSerializableUtils

public class TetradSerializableUtils extends Object
Contains methods used by TestSerialization to ensure that previous "stable" versions of Tetrad will by loadable by later "stable" versions of Tetrad.
Author:
josephramsey
See Also:
  • safelySerializableTypes
  • Constructor Summary

    Constructors
    Constructor
    Description
    TetradSerializableUtils(String serializableScope, String currentDirectory, String archiveDirectory)
    Blank constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TetradSerializableUtils

      public TetradSerializableUtils(String serializableScope, String currentDirectory, String archiveDirectory)
      Blank constructor. Please set the directory undirectedPaths that you will need using the relevant set methods before calling test methods.
  • 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:
      • safelySerializableTypes
    • serializeCurrentDirectory

      public void serializeCurrentDirectory() throws RuntimeException
      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

      public void deserializeCurrentDirectory() throws RuntimeException
      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

      public void archiveCurrentDirectory() throws RuntimeException
      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:
      • getCurrentDirectory()
      • getArchiveDirectory()
    • deserializeArchivedVersions

      public void deserializeArchivedVersions() throws RuntimeException
      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:
      • getArchiveDirectory()