Package Torello.JavaDoc.Annotations
Enum StaticFunctional.Excuse
- java.lang.Object
-
- java.lang.Enum<StaticFunctional.Excuse>
-
- Torello.JavaDoc.Annotations.StaticFunctional.Excuse
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<StaticFunctional.Excuse>
- Enclosing class:
- StaticFunctional
public static enum StaticFunctional.Excuse extends java.lang.Enum<StaticFunctional.Excuse>
An enumeration used by theStaticFunctionalannotation for explaining non-staticfields in a type.
These explanations are placed into the JavaDoc Documentation HTML Page whenever aclassorinterfaceis declared @StaticFunctional, and contains fields which are declaredstatic, but are not declaraed final.
Hi-Lited Source-Code:- View Here: Torello/JavaDoc/Annotations/StaticFunctional.java
- Open New Browser-Tab: Torello/JavaDoc/Annotations/StaticFunctional.java
File Size: 2,469 Bytes Line Count: 66 '\n' Characters Found
-
-
Enum Constant Summary
Enum Constants Enum Constant CONFIGURATIONDEBUGGINGFLAGGARBAGE_COLLECTIONLAZY_LOADINGLOGGINGSINGLETON
-
Method Summary
Convert String to Enum Constant Modifier and Type Method static StaticFunctional.ExcusevalueOf(String name)List all Enum Constants Modifier and Type Method static StaticFunctional.Excuse[]values()
-
-
-
Enum Constant Detail
-
FLAG
public static final StaticFunctional.Excuse FLAG
Indicates that a field inside of a class that has been decorated with theStaticFunctionalannotation is being used as a "Configuration Flag" for that class.
The reasons for excusing a non-finalfield as aFLAGare essentially the same as those for theCONFIGURATIONexcuse. Mainly, this excuse gives an alternate name to a similar concept, and should be used for strictly 'on' or 'off' (boolean)staticand non-finalfields.
-
CONFIGURATION
public static final StaticFunctional.Excuse CONFIGURATION
Indicates the field isn't marked with the'final'modifier because it is used as a simple-configuration.
An example of a@StaticFunctionalclass which designates a non-final field as aConfigurationfield may be found in classScrape.
TheScrapeclass is primarily a wrapper for the JDK classes inside the packagesjava.net&java.io.Scrape(hopefully) reduces some of the tedium required to retrieve HTML from Web-Servers. Some web-servers like to know the exact name of a browser when returning HTML to a browser after aGETorPOSTcommand. In classScrape, the fieldUSER_AGENTallows the programmer to specify which browser is being mimicked.
Yes, in a real sense, this means thatScrapeis not perfectly 'stateless.' It even means that, technically, classScrapeis not really, fundamentally, thread-safe! This configuration-field is a non-finalandstaticfield because it allows the class to avoid one major pitfall: using the class doesn't requiring invoking any constructors or factory methods to create instances of classScrapein order to use it! A simple call toScrape.scrapePage(for instance) is sufficient.
Remember, any pitfalls that might arise from usingScrapewithin multiple-threads may be easily avoided with a simplesynchronized-block and some common-object lock (for instance, using the objectScrape.classas a lock). In such a scenario, if and when two different threads which are vying for use of the scraper, each of which would like to masquerade itself as different "web browser" (USER_AGENT), those threads may employ any one of a number of differentsynchronized-techniques to do so.
The benefits of making aCONFIGURATIONa simple non-finalandstaticfield far outweigh the costs. Forcing users to call constructor's and/or factory-methods (and then work with those instances, instead!) would make using the class feel a lot more complicated than it really needs to be.
-
SINGLETON
public static final StaticFunctional.Excuse SINGLETON
Indicates that an excused, non-final, field contains a singleton instance of aclass, and could conceivably be changed or swapped after the class-loading phase.
An example of aSINGLETON-field may be found in the classHTMLPage, as seen by the fieldparserdeclared in that class.
It would be extremely unlikely that a programmer would need to 'swap parsers' for parsing HTML, but if such a need were to arise (which it never has), assigning a new parser to that field would allow a user to possibly optimize or manipulate HTML parsing.
-
LOGGING
public static final StaticFunctional.Excuse LOGGING
Indicates that a field is excused from the'final'modifier because that field is solely used for logging purposes.
Both the classesShellandGSUTILhave a field that allows the output generated by the operating-system calls they make to be sent to an internalAppendableinstance for logging. Both of these classes are also declared 'stateless' using the@StaticFunctionalannotation.
As mentioned several times, rather than forcing a programmer to use constructors or factories to create instances of classShellorGSUTIL, the methods in these classes are all declared'static', and simply calling those methods using (for instance)Shell.CP(...)orGSUTIL.CP(...)saves a tremendous amount of time, work & complexity.
-
DEBUGGING
public static final StaticFunctional.Excuse DEBUGGING
Indicates that an excused field is not marked with the'final'modifier because it is intended to be used solely for debugging purposes (only!).
An example of a 'stateless' class annotated with@StaticFunctional- and has designated a non-final field as aDebuggingfield - is the classStrCmpr.
The classStrCmpris just a simple conglomerate ofString-utilities, similar to the Apache-Commons classStringUtils, but a little bit more comprehensive. The non-finalandstaticfieldDEBUGis merely just a setting that a programmer may make use of (when necessary) to print up debug-information while that class' search loops are checking forString-matches.
Obviously, because this field is astaticand non-finalfield, its setting applies to any code (and even any thread!) that wants to utilize the search and test routines inStrCmpr. If one block of code inMyClassOnewants its debug steps to be printed, but code insideMyClassTwodoesn't need to do so, it really only requires a modicum of effort to turn the field 'off' (by setting it tofalse) immediately after the requsite debugging information has been printed.
As mentioned elsewhere, requiring a user to call constructors or a factory-builder method for something this straight-forward makes this small amount of extra work well worth it. Furthermore, the overhead time-cost that is incurred when toggling aboolean-fieldtrueandfalseis extremely low.
In a multi-threaded environment, synchronizing code on an object's monitor is extra effort, and even slightly more costly than setting thestaticfield over and over again; however, when the debugging-phase of a development-cycle is finished, there really shouldn't be any need to use thebooleandebug-flag at all, anyways.
-
LAZY_LOADING
public static final StaticFunctional.Excuse LAZY_LOADING
Indicates that a field inside of a class annotated byStaticFunctional, is non-finalbecause the field's value isn't actually loaded at class-initialization time by theClassLoader.
Some classes maintain tables or lists that are stored inside data-files with the Java HTML JAR Distribution. Some of those tables contain information that is seldom (or even never) used. A class which can perform nearly all of its duties without loading a particular table, array or list from disk can save a good amount of time and memory by waiting to load ('lazily-loading') such data from disk until it is actually necessary.
When a field is declared as excused from the'final'modifier using theLAZY_LOADINGexcuse, it means that the field simply cannot be initialized by the class'static-initializers (or theClassLoader) because, under normal operation, that field's value will likely never be used.
An example of a field that is excused in this way may be found in class-fieldHTTPCodes.descriptions. Most of the 'data' that is actually needed by the methods there is already present inside the class' declaration. The data itself is only a few brief arrays. However, there is also aString[]-Array of "descriptions" - that is of little use to most programs, and normal operation. Unless a programmer has decided to start printing text-descriptions of HTTP Error-Codes that can occur when connecting to web-servers, thisString[]-Array field is would never actually be needed, though neither would its value ever actually populated from disk!
If the need does arise, the privatedescriptionsarray is loaded from the JAR file, and assigned to that internal,privateand non-finalfield. This really doesn't 'violate the expressed contract' of the@StaticFunctionalannotation, but rather simply provides a little leeway.
-
GARBAGE_COLLECTION
public static final StaticFunctional.Excuse GARBAGE_COLLECTION
Since ensuring that the Garbage-Collector runs does not constitute program state, this excuse is provided for any field that doesn't declare the'final'modifier because it is involved in calls toSystem.gc().
Any field in a class which is excused as non-finalbecause it is part of an effort to invoke the Java Garbage Collector directly is generally of little relevance among independent code-blocks, or even among independent threads.
Processing HTML can occasionally create many thousands of instances ofHTMLNode'sand the externalJavaParserlibrary creates an even greater number of AST (Abstract Syntax Tree) nodes.
Forcing the JRE to run its garbage-collection routines more often than it normally would does require a very minor amount of "Program State." The purpose of the@StaticFunctionalis to assert that a class is stateless, which is almost nearly true - with the exception of requests for keeping up with calls toSystem.gc()
-
-
Method Detail
-
values
public static StaticFunctional.Excuse[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (StaticFunctional.Excuse c : StaticFunctional.Excuse.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static StaticFunctional.Excuse valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException- if this enum type has no constant with the specified namejava.lang.NullPointerException- if the argument is null
-
-