Package Torello.JavaDoc.SyntaxHiLite
Class AbstractHashCodeHLC<NUMBER extends java.lang.Number>
- java.lang.Object
-
- Torello.JavaDoc.SyntaxHiLite.AbstractHashCodeHLC<NUMBER>
-
- All Implemented Interfaces:
HiLiteCache
public abstract class AbstractHashCodeHLC<NUMBER extends java.lang.Number> extends java.lang.Object implements HiLiteCache
A caching-system class that allows this tool to efficiently bypass calls to the server when an exact-copy of the hilited source-code already exists inside the cache.
Hi-Lited Source-Code:- View Here: Torello/JavaDoc/SyntaxHiLite/AbstractHashCodeHLC.java
- Open New Browser-Tab: Torello/JavaDoc/SyntaxHiLite/AbstractHashCodeHLC.java
File Size: 10,694 Bytes Line Count: 259 '\n' Characters Found
-
-
Field Summary
Fields Modifier and Type Field String
cacheSaveDirectory
Class<NUMBER>
NUMBER_CLASS
-
Constructor Summary
Constructors Constructor AbstractHashCodeHLC(String cacheSaveDirectory, Class<NUMBER> NUMBER_CLASS)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method void
checkIn(String sourceCodeAsString, String hilitedCodeAsString, String codeTypeParam, boolean includeLineNumbers, byte styleNum)
abstract NUMBER
computeCacheKey(String codeTypeParam, boolean includeLineNumbers, byte styleNum, String sourceCodeAsString)
String
get(String sourceCodeAsString, String codeTypeParam, boolean includeLineNumbers, byte styleNum)
static String
initializeOrClear(String cacheSaveDirectory, StorageWriter sw)
static void
main(String[] argv)
void
persistMasterHashToDisk()
int
totalNumber()
long
totalSize()
-
-
-
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
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 byString
-Parameter'cacheSaveDirectory'
. An exception shall be thrown if this file is not found.- Parameters:
cacheSaveDirectory
- This constructor presumes that this cache has been used and visited before. This directory name should point to your local-cache of theHiLite.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 thisError
shall also throw. The chain-causeThrowable
should be visible, and is included as theThrowable.getCause()
.
-
-
Method Detail
-
initializeOrClear
public static java.lang.String initializeOrClear (java.lang.String cacheSaveDirectory, StorageWriter sw)
This will initialize a cache-file in the file-system directory identified by parameterString cacheSaveDirectory
. If the directory specified does not exist, aCacheError
is thrown. Any old cache files will be removed. To attempt to preserve old cache-files, call methodinitializeOrRepair(String, StorageWriter)
OrClear: If the directory structure provided to this initialize method is not empty, the its entire contents shall be erased by a call to (Below)
Java Line of Code:
FileTransfer.deleteFilesRecursive (FileNode.createRoot(cacheSaveDirectory).loadTree(), sw);
- Parameters:
cacheSaveDirectory
- This constructor presumes that this cache has been used and visited before. This directory name should point to your local-cache ofHiLite.ME
Server Code hilite past-operations.sw
- This receives log-writes from the call toFileTransfer.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-causeThrowable
should be visible, and is included as theThrowable.getCause()
.- Code:
- Exact Method Body:
return TreeSetMethods.initializeOrClear(cacheSaveDirectory, sw);
-
totalSize
public long totalSize()
Description copied from interface:HiLiteCache
Inform the user how much space (in bytes) is used by thisCache
.- Specified by:
totalSize
in interfaceHiLiteCache
- 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 thisCache
.- Specified by:
totalNumber
in interfaceHiLiteCache
- 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
public void persistMasterHashToDisk() throws CacheError
Description copied from interface:HiLiteCache
This will save the hash-codeTreeSet<Integer>
to disk. The Master Hash-Code List just keeps a record of the hashcodes of everyString
that was hilited by the Hiliter (and therefore saved inside the Cache). This method will save that JavaTreeSet
of Hash-Codes to disk.- Specified by:
persistMasterHashToDisk
in interfaceHiLiteCache
- Throws:
CacheError
- ThisError
will throw if there is a problem writing the master cache-hash to disk. The chain-causeThrowable
should be visible, and is included as theThrowable.getCause()
- Code:
- Exact Method Body:
TreeSetMethods.persistMasterHashToDisk(this.hashCodes, this.cacheSaveDirectory);
-
get
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 codeString
from the cache if it exists. If a Cache-Miss has occurred, then this method shall return null.- Specified by:
get
in interfaceHiLiteCache
- 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
, ornull
if not cached. - Code:
- Exact Method Body:
return CheckInOut.get( sourceCodeAsString, this.computeCacheKey (codeTypeParam, includeLineNumbers, styleNum, sourceCodeAsString), this );
-
checkIn
public void checkIn(java.lang.String sourceCodeAsString, java.lang.String hilitedCodeAsString, java.lang.String codeTypeParam, boolean includeLineNumbers, byte styleNum)
Description copied from interface:HiLiteCache
Stores a newly highlighted source codeString
into the cache for future retrieval.- Specified by:
checkIn
in interfaceHiLiteCache
- 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- 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)
- 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); } java.io.File f = new java.io.File(argv[0]); if ((! f.exists()) || (! f.isDirectory())) { System.out.println( "argv[0] must contain the Cache-Directory Name.\n" + "Unfortunately: ((! f.exists()) || (! f.isDirectory()))\n" ); System.exit(1); } initializeOrClear(argv[0], new StorageWriter());
-
-