Package Torello.CSS
Class Dimension
- java.lang.Object
-
- Torello.CSS.CSSToken
-
- Torello.CSS.Num
-
- Torello.CSS.Dimension
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,java.lang.Comparable<java.lang.CharSequence>
public class Dimension extends Num implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<java.lang.CharSequence>
This is a Token Data-Class. It is a descendant of the root CSSToken-Class:CSSToken. Instances of the class are usually are produced by theCSSTokenizerclass. Many (but not all) of these subclasses maintain astatic-method for building instances of this class named'build'. AnyCSSToken-subclass that is neither a singleton-instance, nor an "Error-Subtype" should have such a builder. Singeton instances do not need builders, and the two Error-Subtype Classes can only be generated by the tokenizer.
AllCSSTokensubclasses have aCSSToken.strfield which contains the exact character data that was extracted and used to construct instances of this class. All sub-casses also have several "Loop Optimization" methods. These are methods that may or may not be useful in light of some of the newer additions to JDK 17 & 21 including the'instanceof varName'conditional-expression variable-naming features.
The algorithms used to write this tokenizer were generated based solely on the CSS Working-Group's Syntax-Documentation. This document may be viewed here:CSS Working-Group CSS-Syntax. There is an external site that maintain all thing CSS located atdrafts.csswg.org- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/CSS/Dimension.java
- Open New Browser-Tab: Torello/CSS/Dimension.java
File Size: 7,071 Bytes Line Count: 165 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static longserialVersionUIDThis Data-Class' Instance-Fields Modifier and Type Field Stringdimension-
Fields inherited from class Torello.CSS.Num
integerOrNumber, number, signChar
-
-
Method Summary
Static Builders: Build an Instance of this class Modifier and Type Method static Dimensionbuild(String dimensionStr)Tokenize CSS: CSS Working-Group Implementation Modifier and Type Method protected static voidconsume(int[] css, ByRef<Integer> POS, Consumer<CSSToken> returnParsedToken, int identifierStartPos, Num num)Loop-Optimization Methods: 'is' & 'if' Modifier and Type Method DimensionifDimension()booleanisDimension()-
Methods inherited from class Torello.CSS.CSSToken
asAtKeyword, asBadStr, asBadURL, asCDC, asCDO, asComment, asDelimiter, asDimension, asEOF, asFunc, asHash, asIdentifier, asNum, asPercentage, asPunct, asStr, asUnicodeRange, asURL, asWhitespace, charAt, compareTo, equals, ifAtKeyword, ifBadStr, ifBadURL, ifCDC, ifCDO, ifComment, ifDelimiter, ifDelimiter, ifEOF, ifFunc, ifHash, ifIdentifier, ifPercentage, ifPunct, ifPunct, ifStr, ifUnicodeRange, ifURL, ifWhitespace, isAtKeyword, isBadStr, isBadURL, isCDC, isCDO, isComment, isDelimiter, isDelimiter, isEOF, isFunc, isHash, isIdentifier, isPercentage, isPunct, isPunct, isStr, isUnicodeRange, isURL, isWhitespace, length, subSequence, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
dimension
public final java.lang.String dimension
The text /Stringthat was appended to the end of the number that begin thisDimension-Token- Code:
- Exact Field Declaration Expression:
public final String dimension;
-
-
Method Detail
-
isDimension
public final boolean isDimension()
Description copied from class:CSSTokenLoop Optimization: This method only returnsTRUEif this is an actual instance ofDimension.- Overrides:
isDimensionin classCSSToken- Returns:
- This method returns
FALSEfor all instances ofCSSToken, except when'this'instance is actually theDimensionSubclass.
That class has overridden this method, and returnsTRUE. - See Also:
isDimension()
-
ifDimension
public final Dimension ifDimension()
Description copied from class:CSSTokenLoop Optimization: When this method is invoked on an instance of sub-classDimensionthis method produces'this'instance.- Overrides:
ifDimensionin classCSSToken- Returns:
- This method shall return
null, always, except when'this'is an actual instance ofDimension. When so, this method simply returns'this'. All other sub-classes of (abstract) classCSSTokeninherit this method, and therefore return null. - See Also:
ifDimension()
-
build
public static Dimension build(java.lang.String dimensionStr)
Static-Builder Method for creating an instance of this class. This Static-Method is a substitute for an actual Constructor. Because many of the'consume(...)'methods in the Token Classe forTorello.CSSactually generate / spit-out more thanCSSTokeninstance, writing publicly available constructors is largely impossible.
The upside to this approach is that thebuildmethods and theconsumemethods share identical code. Furthermore this code is (nearly) perfectly based on the Pseudo-Code on the CSS Working-Group Website.- Parameters:
dimensionStr- Any Java-Stringthat can be parsed into an instance ofDimension- Returns:
- An instance of
Dimension.
If the contents of the Input-Stringparameter'dimensionStr'cannot be consumed, exactly, by this class''consume'method, then an exception shall throw. - Throws:
TokenizeException- This exception may be thrown for any number of reasons involving the inability to parse input parameter'dimensionStr'.
-
consume
protected static void consume (int[] css, ByRef<java.lang.Integer> POS, java.util.function.Consumer<CSSToken> returnParsedToken, int identifierStartPos, Num num)
This is a tokenizer method which "consumes" the next Dimension-Token from the input Code-Point Array.Tokenizer: Dimension Consume Method, Pseudo-Code
Making use of the CSS Parser DOES NOT require any knowledge of how the underlying Pass 1 Tokenizer actually works. Below is the CSS Working Group's Dimension Rail-Road Diagram. It is here for informational purposes.
These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied, verbatim, from the CSS-Working-Group Web-Site:
https://drafts.csswg.org/css-syntax/#dimension-token-diagram
-
-