Package Torello.HTML
Class SubSection
- java.lang.Object
-
- Torello.HTML.SubSection
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.CharSequence
,java.lang.Cloneable
,java.lang.Comparable<SubSection>
public final class SubSection extends java.lang.Object implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<SubSection>, java.lang.Cloneable
SubSection - Documentation.
This class is is a simple data-structure-class which is used to represent vectorized-html web-page "sub-sections." It is used almost identically with the classpublic class 'DotPair'
but this class also keeps a copy of the actualHTMLNode
content of the vector sub-section that is identified by the fields in this class. Whileclass 'DotPair'
only keeps a pointer to the starting and ending index-positions of the html-vector, this class - in addition to keeping an instance ofclass 'DotPair'
as a public member field - also keeps a clone/copy of the sub-list itself as a public field of this class.
NOTE: If the above sounds like technical-jargon, please reviewpublic class DotPair
, and notice that thepublic final int 'start'
and'end'
fields are merely pointers into a vectorized-html web-page. They 'point' to the starting and ending places on the main html web-page where this "sub-section" or "sub-list" being and end. Thisclass 'SubSection'
is intended to have the same meaning as classclass 'DotPair'
- except that actual HTML, itself, not just start and end pointers is stored as public fields in this data-structure.
STALE-DATA NOTE: The burden of ensuring that stale-data is not contained inside an instance ofclass 'SubSection'
is left as an exercise for the programmer using this class. If the original page vector is modified, even the portion of the original page being modified does not overlap this sub-section the values insidepublic DotPair location
and the values insidepublic final Vector<HTMLNode> html
could become stale. If any nodes are removed or added, the index pointers contained in this class would no longer point to indexes inside the html-page-vector that represent the original sub-section intended by the original instantiation of this class.
POINT: Make sure that when modifying a vectorized-html web-page that you update, renew, re-look-for, or discard stale vector-index data, and / or stale vectorHTMLNode's
. If nodes are shifted in the vector due to an insertion or removal, then every instance of "SubSection" created for the vector will be "stale" or "invalid." Keep in mind, and instance of "SubSection" could easily be "shifted" left or right by as many nodes as were inserted or deleted, however, these simple Data Structures in Java-HTML are all immutable. "Shifting" the start and end index positions of a subsection by so many nodes would require building a newpublic class 'DotPair'
, and newpublic class 'SubSection'
instance. Luckily, these 'ultra-light' Data-Structures are very easily instantiated.- See Also:
HTMLNode
,DotPair
,NodeIndex
,TagNodePeekInclusive
,InnerTagPeekInclusive
, Serialized Form
Hi-Lited Source-Code:
- View Here: Torello/HTML/SubSection.java
- Open New Browser-Tab: Torello/HTML/SubSection.java
-
-
Field Summary
Fields Modifier and Type Field static Comparator<SubSection>
comp2
Vector<HTMLNode>
html
DotPair
location
static long
serialVersionUID
-
Constructor Summary
Constructors Constructor SubSection(DotPair location, Vector<HTMLNode> html)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method char
charAt(int index)
SubSection
clone()
int
compareTo(SubSection other)
int
length()
CharSequence
subSequence(int start, int end)
String
toString()
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable
. Using theSerializable
Implementation 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:
1
public static final long serialVersionUID = 1;
-
location
public DotPair location
This public field identifies the sub-section location of a particular sub-section from a vectorized-html webpage. The location of the sub-page is specified by theclass DotPair
public-fields:public final int 'start'
andpublic final int 'end'
- See Also:
DotPair
- Code:
- Exact Field Declaration Expression:
1
public DotPair location;
-
html
public final java.util.Vector<HTMLNode> html
This public field identifies the actual nodes - the vectorized-html sub-list - that are included in this sub-section of an html web-page.- See Also:
HTMLNode
- Code:
- Exact Field Declaration Expression:
1
public final Vector<HTMLNode> html;
-
comp2
public static java.util.Comparator<SubSection> comp2
This is an "alternative Comparitor" that can be used for sorting instances of this class. It should work with theCollections.sort(List, Comparator)
method in the standard JDK packagejava.util.*;
NOTE: This simply compares the fieldspublic DotPair location
to each-other using the secondary instance ofComparator
that is available as a lambda inclass DotPair
.- See Also:
DotPair.comp2
- Code:
- Exact Field Declaration Expression:
1 2
public static Comparator<SubSection> comp2 = (SubSection ss1, SubSection ss2) -> DotPair.comp2.compare(ss1.location, ss2.location);
-
-
Constructor Detail
-
SubSection
public SubSection(DotPair location, java.util.Vector<HTMLNode> html)
This just builds a new instance of this class. It represents a 'sub-section' of the html-page that needs to encapsulated into an object-instance. The contents of this data-structure are merely these two parameters that are passed to this constructor.- Parameters:
location
- This parameter value will be assigned immediately to the internal-fieldpublic DotPair location.
It is a two-integerVector
-index class that points to the starting index-position, inside the main html-Vector
, of the htmlclass 'SubSection'
being constructed here.html
- This parameter may be any vectorized-html web-page, but the intention is that thisVector
is an exact range-clone ... or "cloned range" of a web-page whose starting and ending integer indexVector
-positions are the contents of the parameter'location'
- Throws:
java.lang.IllegalArgumentException
- This exception will throw if either of these two scenarios occur:- If the input
Vector<HTMLNode> 'html'
hashtml.size() == 0
. - If
html.size() != location.size()
- If the input
- See Also:
location
,html
,DotPair
,NodeIndex
,HTMLNode
- Code:
- Exact Constructor Body:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if (location == null) throw new NullPointerException ("Parameter 'DotPair location' to SubSection constructor was null."); if (html == null) throw new NullPointerException ("Parameter 'Vector<HTMLNode> html' to SubSection constructor was null."); if (html.size() == 0) throw new IllegalArgumentException( "Parameter 'Vector<HTMLNode> html' to SubSection constructor has size zero, but " + "this is not allowed here." ); if (location.size() != html.size()) throw new IllegalArgumentException( "Field 'public final int end' [value=" + location.end + "] of passed-parameter " + "'DotPair location' to SubSection constructor is different than the length of the " + "html-vector [" + html.size() + "]." ); this.location = location; this.html = html;
-
-
Method Detail
-
clone
public SubSection clone()
Java'sinterface Cloneable
requirements. This instantiates a newSubSection
with identicalVector<HTMLNode> html
andDotPair location
fields.- Overrides:
clone
in classjava.lang.Object
- Returns:
- A new
SubSection
whose internal fields are identical to this one. - Code:
- Exact Method Body:
1
return new SubSection(location, html);
-
compareTo
public final int compareTo(SubSection other)
Java'sinterface Comparable<T>
requirements. This does a very simple comparison using the fieldpublic DotPair location.
FINAL METHOD: This method is declaredfinal
, and cannot be modified by sub-classes.- Specified by:
compareTo
in interfacejava.lang.Comparable<SubSection>
- Parameters:
other
- Any otherSubSection
to be compared to'this' NodeISubSectionndex
- Returns:
- An integer that fulfils Java's
interface Comparable<T> public boolean compareTo(T t)
method requirements. - See Also:
DotPair.compareTo(DotPair)
- Code:
- Exact Method Body:
1
return this.location.compareTo(other.location);
-
toString
public final java.lang.String toString()
Java'stoString()
requirement.
FINAL METHOD: This method isfinal
, and cannot be modified by sub-classes.- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
- Returns:
- A
String
-representation of thisHTMLNode.
- See Also:
toString()
- Code:
- Exact Method Body:
1
return Util.pageToString(html);
-
charAt
public final char charAt(int index)
Returns the char value at the specified index of the String defined-by an invokation of the method:Util.pageToString(html)
. An index ranges from'0'
(zero) tolength() - 1.
The firstchar
value of the sequence is at index , the next at index one, and so on, as for array indexing.
NOTE: If the char value specified by the index is a surrogate, the surrogate value is returned.
FINAL METHOD: This method isfinal
, and cannot be modified by sub-classes.- Specified by:
charAt
in interfacejava.lang.CharSequence
- Parameters:
index
- The index of the char value to be returned- Returns:
- The specified char value
- See Also:
toString()
- Code:
- Exact Method Body:
1
return toString().charAt(index);
-
length
public final int length()
Returns the length of theString
defined-by an invokation of the method:Util.pageToString(html)
. The length is the number of 16-bitchar's
in the sequence.
FINAL METHOD: This method isfinal
, and cannot be modified by sub-classes.- Specified by:
length
in interfacejava.lang.CharSequence
- Returns:
- the number of
chars
inthis.n.str
- See Also:
toString()
- Code:
- Exact Method Body:
1
return toString().length();
-
subSequence
public final java.lang.CharSequence subSequence(int start, int end)
Returns ajava.lang.CharSequence
that is a subsequence of theString
defined-by an invokation of the method:Util.pageToString(html)
. The subsequence starts with thechar
value at the specified index and ends with thechar
value at indexend - 1.
The length (inchar's
) of the returned sequence isend - start
, so ifstart == end
then an empty sequence is returned.
FINAL METHOD: This method isfinal
, and cannot be modified by sub-classes.- Specified by:
subSequence
in interfacejava.lang.CharSequence
- Parameters:
start
- The start index, inclusiveend
- The end index, exclusive- Returns:
- The specified subsequence
- See Also:
toString()
- Code:
- Exact Method Body:
1
return toString().substring(start, end);
-
-