Package Torello.JavaDoc
Enum Excuse
- java.lang.Object
-
- java.lang.Enum<Excuse>
-
- Torello.JavaDoc.Excuse
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Excuse>
public enum Excuse extends java.lang.Enum<Excuse>
An enumeration used by theStaticFunctional
annotation for explaining non-static
fields in a type.
These explanations are placed into the JavaDoc Documentation HTML Page whenever aclass
orinterface
is declared @StaticFunctional, and contains fields which are declaredstatic
, but are not declaraed final.
Hi-Lited Source-Code:- View Here: Torello/JavaDoc/Excuse.java
- Open New Browser-Tab: Torello/JavaDoc/Excuse.java
File Size: 2,259 Bytes Line Count: 67 '\n' Characters Found
-
-
Enum Constant Summary
Enum Constants Enum Constant CONFIGURATION
DEBUGGING
FLAG
GARBAGE_COLLECTION
LAZY_LOADING
LOGGING
SINGLETON
-
Method Summary
Convert String to Enum Constant Modifier and Type Method static Excuse
valueOf(String name)
List all Enum Constants Modifier and Type Method static Excuse[]
values()
-
-
-
Enum Constant Detail
-
FLAG
public static final Excuse FLAG
Indicates that a field inside of a class that has been decorated with theStaticFunctional
annotation is being used as a "Configuration Flag" for that class.
The reasons for excusing a non-final
field as aFLAG
are essentially the same as those for theCONFIGURATION
excuse. Mainly, this excuse gives an alternate name to a similar concept, and should be used for strictly 'on' or 'off' (boolean
)static
and non-final
fields.
-
CONFIGURATION
public static final Excuse CONFIGURATION
Indicates the field isn't marked with the'final'
modifier because it is used as a simple-configuration.
An example of a@StaticFunctional
class which designates a non-final field as aConfiguration
field may be found in classScrape
.
TheScrape
class 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 aGET
orPOST
command. In classScrape
, the fieldUSER_AGENT
allows the programmer to specify which browser is being mimicked.
Yes, in a real sense, this means thatScrape
is not perfectly 'stateless.' It even means that, technically, classScrape
is not really, fundamentally, thread-safe! This configuration-field is a non-final
andstatic
field 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 classScrape
in order to use it! A simple call toScrape.scrapePage
(for instance) is sufficient.
Remember, any pitfalls that might arise from usingScrape
within multiple-threads may be easily avoided with a simplesynchronized
-block and some common-object lock (for instance, using the objectScrape.class
as 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 aCONFIGURATION
a simple non-final
andstatic
field 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 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 fieldparser
declared 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 Excuse LOGGING
Indicates that a field is excused from the'final'
modifier because that field is solely used for logging purposes.
Both the classesShell
andGSUTIL
have a field that allows the output generated by the operating-system calls they make to be sent to an internalAppendable
instance for logging. Both of these classes are also declared 'stateless' using the@StaticFunctional
annotation.
As mentioned several times, rather than forcing a programmer to use constructors or factories to create instances of classShell
orGSUTIL
, 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 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 aDebugging
field - is the classStrCmpr
.
The classStrCmpr
is just a simple conglomerate ofString
-utilities, similar to the Apache-Commons classStringUtils
, but a little bit more comprehensive. The non-final
andstatic
fieldDEBUG
is 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 astatic
and non-final
field, 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 inMyClassOne
wants its debug steps to be printed, but code insideMyClassTwo
doesn'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
-fieldtrue
andfalse
is extremely low.
In a multi-threaded environment, synchronizing code on an object's monitor is extra effort, and even slightly more costly than setting thestatic
field over and over again; however, when the debugging-phase of a development-cycle is finished, there really shouldn't be any need to use theboolean
debug-flag at all, anyways.
-
LAZY_LOADING
public static final Excuse LAZY_LOADING
Indicates that a field inside of a class annotated byStaticFunctional
, is non-final
because 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_LOADING
excuse, 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 privatedescriptions
array is loaded from the JAR file, and assigned to that internal,private
and non-final
field. This really doesn't 'violate the expressed contract' of the@StaticFunctional
annotation, but rather simply provides a little leeway.
-
GARBAGE_COLLECTION
public static final 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-final
because 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's
and the externalJavaParser
library 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@StaticFunctional
is 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 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 (Excuse c : 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 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
-
-