Class AbstractHashCodeHLC<NUMBER extends java.lang.Number>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      String cacheSaveDirectory
      This is, as the name clearly says, the Cache's Storae-Directory
      Class<NUMBER> NUMBER_CLASS
      This is nothing more than a "reified" Generic Type Parameter.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractHashCodeHLC​(String cacheSaveDirectory, Class<NUMBER> NUMBER_CLASS)
      This will load the hashCodes table to memory from the file-system directory identified by String-Parameter 'cacheSaveDirectory'.
    • Method Summary

       
      Retrieving Files from the Cache & Inserting new Files into the Cache
      Modifier and Type Method Description
      void checkIn​(String sourceCodeAsString, String hilitedCodeAsString, String codeTypeParam, boolean includeLineNumbers, byte styleNum)
      Store a newly highlighted source code String into the cache for future retrieval.
      String get​(String sourceCodeAsString, String codeTypeParam, boolean includeLineNumbers, byte styleNum)
      Retrieves a previously highlighted source code String from the cache if it exists.
       
      Check the Cache Size
      Modifier and Type Method Description
      int totalNumber()
      Count how many files and directories are contained in this Cache.
      long totalSize()
      Inform the user how much space (in bytes) is used by this Cache.
       
      Write Cache-State to Disk
      Modifier and Type Method Description
      void persistMasterHashToDisk()
      This will save the hash-code TreeSet<Integer> to disk.
       
      Initialize a Directory for use as a Syntax HiLiting Cache
      Modifier and Type Method Description
      static String initializeDirectory​(String cacheSaveDirectory, StorageWriter sw)
      This will initialize a cache-file in the file-system directory identified by parameter String cacheSaveDirectory.
      static void main​(String[] argv)
      A Main-Method which invokes initializeDirectory(String, StorageWriter)
       
      Abstract Method for Calculating the Hash-Key used in Caching Files
      Modifier and Type Method Description
      abstract NUMBER computeCacheKey​(String codeTypeParam, boolean includeLineNumbers, byte styleNum, String sourceCodeAsString)
      Compute a Hash-Code for a given Source-File, and it's HiLiting Parameters
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NUMBER_CLASS

        🡇     🗕  🗗  🗖
        public final java.lang.Class<NUMBER extends java.lang.Number> NUMBER_CLASS
        This is nothing more than a "reified" Generic Type Parameter. No more, no less.
        Code:
        Exact Field Declaration Expression:
         public final Class<NUMBER> NUMBER_CLASS;
        
      • cacheSaveDirectory

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String cacheSaveDirectory
        This is, as the name clearly says, the Cache's Storae-Directory
        Code:
        Exact Field Declaration Expression:
         public final String cacheSaveDirectory;
        
    • Constructor Detail

      • AbstractHashCodeHLC

        🡅  🡇         External-Java:      🗕  🗗  🗖
        public AbstractHashCodeHLC​(java.lang.String cacheSaveDirectory,
                                   java.lang.Class<NUMBER> NUMBER_CLASS)
        This will load the hashCodes table to memory from the file-system directory identified by String-Parameter 'cacheSaveDirectory'. An exception shall be thrown if this file is not found, or the specified directory doesn't exist.
        Parameters:
        cacheSaveDirectory - This constructor presumes that this cache has been used and visited before. This directory name should point to your local-cache of the HiLite.ME Server Code hilite past-operations.
        Throws:
        CacheError - This error will throw if the cache has not been instantiated, or is corrupted. If the specified directory does not exist, then this Error shall also throw. The chain-cause Throwable should be visible, and is included as the Throwable.getCause().
    • Method Detail

      • initializeDirectory

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public static java.lang.String initializeDirectory​
                    (java.lang.String cacheSaveDirectory,
                     StorageWriter sw)
        
        This will initialize a cache-file in the file-system directory identified by parameter String cacheSaveDirectory. If the directory specified does not exist, File.mkdirs() will be invoked, thereby creating that directory. If the specified directory already exists - it's contents shall be fully wiped, meaning all files deleted.

        Erasing Contents: If the directory structure provided to this method is non-empty, the its entire contents shall be erased by a call to FileTransfer#deleteFilesRecursive., as per the statement below


         FileTransfer.deleteFilesRecursive
             (FileNode.createRoot(cacheSaveDirectory).loadTree(), sw);
        

        This method saves a brand-new (empty) Hash-Code List (a java.util.TreeSet) to disk, using Java Object Serialization. It is not actually important to know whether this Cache is going to be a 32-Bit or a 64-Bit Cache. The TreeSet which is written to disk is empty. Therefore, in all actuality, what is written to disk is a "Raw-Types" TreeSet (precisely because of Java's Generic Erasure). Thus it is perfectly irrelevant what is written to disk.
        Parameters:
        cacheSaveDirectory - This constructor presumes that this cache has been used and visited before. This directory name should point to your local-cache of HiLite.ME Server Code hilite past-operations.
        sw - This receives log-writes from the call to FileTransfer.deleteFilesRecursive(Torello.Java.FileNode, Torello.Java.FileNodeFilter, Torello.Java.FileNodeFilter, java.lang.Appendable) which clears the files currently in the cache. This parameter may be null, and if it is, output-text will be shunted.
        Throws:
        CacheError - This exception will be throw if there are errors deleting any old-cache files currently in the directory; or if there is any error creating the new master hash-cache file. The chain-cause Throwable should be visible, and is included as the Throwable.getCause().
        Code:
        Exact Method Body:
         return TreeSetMethods.initializeDirectory(cacheSaveDirectory, sw);
        
      • totalSize

        🡅  🡇     🗕  🗗  🗖
        public long totalSize()
        Description copied from interface: HiLiteCache
        Inform the user how much space (in bytes) is used by this Cache.
        Specified by:
        totalSize in interface HiLiteCache
        Returns:
        The number of bytes being used on the file-system by this Cache.
        Code:
        Exact Method Body:
         return FileNode
             .createRoot(this.cacheSaveDirectory)
             .loadTree()
             .getDirTotalContentsSize();
        
      • totalNumber

        🡅  🡇     🗕  🗗  🗖
        public int totalNumber()
        Description copied from interface: HiLiteCache
        Count how many files and directories are contained in this Cache.
        Specified by:
        totalNumber in interface HiLiteCache
        Returns:
        The total number of files and sub-directories in the Cache directory.
        Code:
        Exact Method Body:
         return FileNode
             .createRoot(this.cacheSaveDirectory)
             .loadTree()
             .count();
        
      • persistMasterHashToDisk

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public void persistMasterHashToDisk()
                                     throws CacheError
        Description copied from interface: HiLiteCache
        This will save the hash-code TreeSet<Integer> to disk. The Master Hash-Code List just keeps a record of the hashcodes of every String that was hilited by the Hiliter (and therefore saved inside the Cache). This method will save that Java TreeSet of Hash-Codes to disk.
        Specified by:
        persistMasterHashToDisk in interface HiLiteCache
        Throws:
        CacheError - This Error will throw if there is a problem writing the master cache-hash to disk. The chain-cause Throwable should be visible, and is included as the Throwable.getCause()
        Code:
        Exact Method Body:
         TreeSetMethods.persistMasterHashToDisk(this.hashCodes, this.cacheSaveDirectory);
        
      • get

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public java.lang.String get​(java.lang.String sourceCodeAsString,
                                    java.lang.String codeTypeParam,
                                    boolean includeLineNumbers,
                                    byte styleNum)
        Description copied from interface: HiLiteCache
        Retrieves a previously highlighted source code String from the cache if it exists. If a Cache-Miss has occurred, then this method shall return null.
        Specified by:
        get in interface HiLiteCache
        Parameters:
        sourceCodeAsString - The unhighlighted source code text which is used for generating a "Hash Key" into the cache.
        codeTypeParam - The code type identifier (e.g., 'java', 'html', 'css') used to distinguish syntax rules.
        includeLineNumbers - A flag indicating whether line numbers are to be included in the highlighted HTML output.
        styleNum - A numeric style identifier used to determine which syntax color scheme should be applied.
        Returns:
        The highlighted version of the source code as a String, or null if not cached.
        Code:
        Exact Method Body:
         return CheckInOut.get(
             sourceCodeAsString,
             this.computeCacheKey
                 (codeTypeParam, includeLineNumbers, styleNum, sourceCodeAsString),
             this
         );
        
      • checkIn

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public void checkIn​(java.lang.String sourceCodeAsString,
                            java.lang.String hilitedCodeAsString,
                            java.lang.String codeTypeParam,
                            boolean includeLineNumbers,
                            byte styleNum)
        Description copied from interface: HiLiteCache
        Store a newly highlighted source code String into the cache for future retrieval.
        Specified by:
        checkIn in interface HiLiteCache
        Parameters:
        sourceCodeAsString - The unhighlighted source code text which is used for generating a "Hash Key" into the cache.
        codeTypeParam - The code type identifier (e.g., 'java', 'html', 'css') used to distinguish syntax rules.
        includeLineNumbers - A flag indicating whether line numbers are to be included in the highlighted HTML output.
        styleNum - A numeric style identifier used to determine which syntax color scheme should be applied.
        Code:
        Exact Method Body:
         CheckInOut.checkIn(
             sourceCodeAsString,
             hilitedCodeAsString,
             this.computeCacheKey
                 (codeTypeParam, includeLineNumbers, styleNum, sourceCodeAsString),
             this 
         );
        
      • computeCacheKey

        🡅  🡇     🗕  🗗  🗖
        public abstract NUMBER computeCacheKey​(java.lang.String codeTypeParam,
                                               boolean includeLineNumbers,
                                               byte styleNum,
                                               java.lang.String sourceCodeAsString)
        Compute a Hash-Code for a given Source-File, and it's HiLiting Parameters
        Parameters:
        codeTypeParam - The code type identifier (e.g., 'java', 'html', 'css') used to distinguish syntax rules.
        includeLineNumbers - A flag indicating whether line numbers are to be included in the highlighted HTML output.
        styleNum - A numeric style identifier used to determine which syntax color scheme should be applied.
        sourceCodeAsString - The unhighlighted source code text which is used for generating a "Hash Key" into the cache.
        Returns:
        A key which may be used for saving a file to disk.
      • main

        🡅     🗕  🗗  🗖
        public static void main​(java.lang.String[] argv)
        A Main-Method which invokes initializeDirectory(String, StorageWriter)
        Code:
        Exact Method Body:
         if (argv.length != 1)
         {
             System.out.println(
                 "argv.length != 1\n" +
                 "argv[0] must contain the Cache-Directory Name.\n"
             );
        
             System.exit(1);
         }
        
         initializeDirectory(argv[0], new StorageWriter());