Package Torello.HTML.NodeSearch
Class AbstractHNLI<E extends HTMLNode,F>
- java.lang.Object
-
- Torello.HTML.NodeSearch.AbstractHNLI<E,F>
-
- Type Parameters:
E- This must be eitherTagNode,TextNodeorCommentNode. This is type of the query-specifierPredicatebeing used.F- This is the actual-type that will be iterated. For instances ofHNLI, both type-parameters'E'and'F'are identical. ThePredicate'swill be querrying for a certain type ofHTMLNode, and theIteratorwill be iterating that type ofHTMLNodetoo.
However, for instances ofHNLIInclusive, the query-specifier is (automatically-required) to be set toTagNode, and theIteratorshall be returning instances ofVector<HTMLNode>. Generic Type-Parameter'F'is automatically set toVector<HTMLNode>for instances ofHNLIInclusive.
- All Implemented Interfaces:
java.util.Iterator<F>,java.util.ListIterator<F>
- Direct Known Subclasses:
HNLI,HNLIInclusive
public abstract class AbstractHNLI<E extends HTMLNode,F> extends java.lang.Object implements java.util.ListIterator<F>
Abstract HTMLNode-ListIterator:
This class is the parent of the following two classes:
Methods that are common to both of these classes have been placed in this abstract super-class.Abstract parent-class for both of the types of HTML-Iterator's
This is anabstract super-classfor theHTML Node List Iteratorclasses. Having anabstractparent-class allows to collect some of the common features of both sub-classes into a single parent.
Hi-Lited Source-Code:- View Here: Torello/HTML/NodeSearch/AbstractHNLI.java
- Open New Browser-Tab: Torello/HTML/NodeSearch/AbstractHNLI.java
File Size: 34,572 Bytes Line Count: 870 '\n' Characters Found
-
-
Field Summary
Primary Iterator Fields Modifier and Type Field protected Class<E>cprotected Predicate<E>pprotected VectorvCursor Fields Modifier and Type Field protected intcursorprotected intmaxCursorprotected intminCursorException Monitoring Fields Modifier and Type Field protected intexpectedSizeprotected booleanmodifiedSince
-
Constructor Summary
Constructors Modifier Constructor protectedAbstractHNLI(Vector<?> html, Predicate<E> p, Class<E> c)
-
Method Summary
Replacing HTML Modifier and Type Method voidreplaceRange(int sPos, int ePos, Vector<HTMLNode> newNodes)voidreplaceRange(DotPair range, Vector<HTMLNode> newNodes)voidset(E e)voidset(String html)voidset(Vector<HTMLNode> html)voidsetHTMLNode(HTMLNode n)Inserting HTML Modifier and Type Method voidadd(E e)voidadd(String html)voidadd(Vector<HTMLNode> html)voidaddHTMLNode(HTMLNode n)voidinsertAt(String html, int pos)voidinsertAt(Vector<? extends HTMLNode> html, int pos)voidinsertAt(HTMLNode n, int pos)Removing HTML Modifier and Type Method voidremove()voidremoveElementAt(int pos)voidremoveElements(int... posArr)voidremoveRange(int sPos, int ePos)voidremoveRange(DotPair range)Cursor Methods Modifier and Type Method voidclearCursorBounds()intcursorLocation()voidmoveCursor(int location)voidmoveCursorToEnd()voidmoveCursorToStart()voidrestrictCursor(int minCursorBounds, int maxCursorBounds)voidrestrictCursor(DotPair cursorBounds)voidrestrictCursor(LV loopVariable)Internal: Exception-Checks Modifier and Type Method protected voidCHECK_CME()protected voidCHECK_EXCEPTIONS()protected voidCHECK_EXCEPTIONS(int pos)protected voidCHECK_EXCEPTIONS(int[] posArr)protected voidCHECK_EXCEPTIONS(DotPair range)protected voidMODIFIED()
-
-
-
Field Detail
-
v
protected java.util.Vector v
The internal, underlying instance ofVectorthat thisIteratoris using.- Code:
- Exact Field Declaration Expression:
@SuppressWarnings("rawtypes") protected Vector v;
-
p
-
c
-
cursor
protected int cursor
Internal'cursor'field.
It is initialized to -1, which allows the iterator to identify whether it has been used yet.- Code:
- Exact Field Declaration Expression:
protected int cursor = -1;
-
modifiedSince
protected boolean modifiedSince
This identifies whether one of theIterator'shtml modification methods (set, remove, add) have been invoked. Multiple invocations of these methods after a single iteration causes aSecondModificationException
Initializing this toTRUEprevents the programmer from calling any of the modification methods without first finding a match.- Code:
- Exact Field Declaration Expression:
protected boolean modifiedSince = true;
-
maxCursor
protected int maxCursor
The maximum boundary for theCursor Boundary Window.
Initialized to'-1'means the default setting is for theIteratoris not to use aCursor Boundaries. One may be assigned using therestrictCursor(...)methods.- See Also:
restrictCursor(DotPair),restrictCursor(int, int),clearCursorBounds()- Code:
- Exact Field Declaration Expression:
protected int maxCursor = -1;
-
minCursor
protected int minCursor
The minimum boundary for theCursor Boundary Window.
Initialized to'-1'means the default setting is for theIteratoris not to use aCursor Boundaries. One may be assigned using therestrictCursor(...)methods.- See Also:
restrictCursor(DotPair),restrictCursor(int, int),clearCursorBounds()- Code:
- Exact Field Declaration Expression:
protected int minCursor = -1;
-
expectedSize
protected int expectedSize
This is an attempt to monitor outside modifications to an HTMLVector- Code:
- Exact Field Declaration Expression:
protected int expectedSize;
-
-
Constructor Detail
-
AbstractHNLI
protected AbstractHNLI(java.util.Vector<?> html, java.util.function.Predicate<E> p, java.lang.Class<E> c)
Constructs an instance of this class using an HTMLVector, and aPredicatefor testing the nodes in thatVectorfor matches. The third parameter'c'is only necessary because of Java's type-erasure problem.- Parameters:
html- Any vectorized HTML page or sub-page.p- Ajava.util.function.Predicatefor testing the nodes in the htmlVectorfor matches.c- The sub-class ofHTMLNodethat thisHNLIshall be searching. The values for parameter'c'include:TagNode.class, TextNode, andCommentNode.class
-
-
Method Detail
-
MODIFIED
protected final void MODIFIED()
- Code:
- Exact Method Body:
modifiedSince = true; expectedSize = v.size(); RESET_MATCHES();
-
remove
public void remove()
This removes the last match that was returned by theIteratorout of the underlyingVector.- Specified by:
removein interfacejava.util.Iterator<E extends HTMLNode>- Specified by:
removein interfacejava.util.ListIterator<E extends HTMLNode>- Throws:
SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(); int numRemoved = REMOVE(); if (maxCursor != -1) maxCursor -= numRemoved; MODIFIED();
-
moveCursorToStart
public void moveCursorToStart()
Convenience Method
Invokes:moveCursor(int)
Uses minimum cursor-bound for parameter'location', which would be zero, unless a cursor-window has been set.- Code:
- Exact Method Body:
moveCursor((minCursor == -1) ? 0 : minCursor);
-
moveCursorToEnd
public void moveCursorToEnd()
Convenience Method
Invokes:moveCursor(int)
Uses minimum cursor-bound for parameter'location', which would bev.size() - 1, unless a cursor-window has been set.- Code:
- Exact Method Body:
moveCursor((maxCursor == -1) ? (v.size() - 1) : maxCursor);
-
moveCursor
public void moveCursor(int location)
Sets the internal state of thisIterator'scursor location. The next invocation ofnext, previous, etc... will return the nearest match to thisVector-index.
Cursor Reset Method:
This method is (somewhat / sort-of) of a Reset-Method - because the internal-cursoris moved to the beginning of the underlying-Vector. Whenever the cursor is moved (or restricted), this class' code will check for the possibility of aConcurrentModificationException.
In normal situations, when statements or method's from outside the update methods in this class, modify the underlying html-VectoraConcurrentModificationExceptionshall throw. However, whenever anHTML Node List Iteratormethod moves the cursor, the logic for checking Concurrent-Modification will reset (by setting the internal'expectedSize'field tov.size()).
This 'resetting' of the internal'expectedSize'field is precisely how to prevent an exception throw due to outside modification of the underlyingVector.- Parameters:
location- Any index into the underlying HTMLVector- Throws:
java.lang.IndexOutOfBoundsException- This shall throw if the value passed to parameter'location'is negative, or past the end of the underlying htmlVector.CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.- Code:
- Exact Method Body:
if (location < 0) throw new IndexOutOfBoundsException ("You have passed a negative value to the cursor location: [" + location + "]."); if (location > v.size()) throw new IndexOutOfBoundsException( "You have passed a cursor location value [" + location + "] that is larger than the " + "size of the underlying Vector [" + v.size() + "]" ); CursorException.check(minCursor, maxCursor, location); cursor = location; modifiedSince = true; expectedSize = v.size(); RESET_MATCHES();
-
restrictCursor
public void restrictCursor(DotPair cursorBounds)
- Code:
- Exact Method Body:
restrictCursor(cursorBounds.start, cursorBounds.end);
-
restrictCursor
public void restrictCursor(LV loopVariable)
- Code:
- Exact Method Body:
restrictCursor(loopVariable.start, loopVariable.end - 1);
-
restrictCursor
public void restrictCursor(int minCursorBounds, int maxCursorBounds)
Restrict the internalcursorboundaries to a window defined by the parameters'maxCursorBounds', and'minCursorBounds'. When thecursorbounds are restricted, any matches that would be returned by thisIteratorwhich lay outside the boundaries of this window shall be skipped or avoided.
If thecursoris currently located outside the boundaries of the given window, it shall be moved to within it.
Cursor Reset Method:
This method is (somewhat / sort-of) of a Reset-Method - because the internal-cursoris moved to the beginning of the underlying-Vector. Whenever the cursor is moved (or restricted), this class' code will check for the possibility of aConcurrentModificationException.
In normal situations, when statements or method's from outside the update methods in this class, modify the underlying html-VectoraConcurrentModificationExceptionshall throw. However, whenever anHTML Node List Iteratormethod moves the cursor, the logic for checking Concurrent-Modification will reset (by setting the internal'expectedSize'field tov.size()).
This 'resetting' of the internal'expectedSize'field is precisely how to prevent an exception throw due to outside modification of the underlyingVector.- Parameters:
minCursorBounds- This shall set a minimumcursor-index value that restricts the returned matches generated by thisHTML Node List Iteratorto indices less thanminCursorBounds. This is an inclusive bound. Matches falling directly on this index may be included in a result set.maxCursorBounds- This shall set a maximumcursor-index value that restricts the returned matches generated by thisHTML Node List Iteratorto indices greater thanmaxCursorBounds. This is *also* an inclusive bound. Matches falling directly on this index may be included in a result set.- Throws:
java.lang.IndexOutOfBoundsException- If the bounds provided by the'cursorBounds'input parameter extend past the end of the current underlyingVector, then this exception shall throw.- Code:
- Exact Method Body:
if (minCursorBounds < 0) throw new IndexOutOfBoundsException ("The value for parameter 'minPos' [" + minCursorBounds + "] cannot be negative"); if (maxCursorBounds >= v.size()) throw new IndexOutOfBoundsException( "The value for parameter 'maxPos' [" + maxCursorBounds + "] is larger than " + "(or equal to) the size of the underlying Vector [" + v.size() + "]." ); this.minCursor = minCursorBounds; this.maxCursor = maxCursorBounds; if (this.cursor < this.minCursor) { RESET_MATCHES(); this.cursor = this.minCursor; } else if (this.cursor > this.maxCursor) { RESET_MATCHES(); this.cursor = this.maxCursor; }
-
clearCursorBounds
public void clearCursorBounds()
Eliminates the Cursor Boundary Window, if one had been set.- Code:
- Exact Method Body:
this.maxCursor = this.minCursor = -1;
-
cursorLocation
public int cursorLocation()
Retrieves the current location of the cursor.- Returns:
- The current location of
'this' Iterator'scursor. IfhasNext()orhasPrevious()has just been called, for example, the cursor will be pointing to the next (or previous) node-match in the HTMLVector. - Code:
- Exact Method Body:
return cursor;
-
addHTMLNode
public void addHTMLNode(HTMLNode n)
This provides a way to insert an HTML node into the HTML-Vector. The node is at the currentcursor-index. The cursor should be pointing to the location of the last returned match.- Parameters:
n- This may be any descendant of theclass HTMLNode. There is an issue to think about when working with Java's Generics and Compile-Time versus Run-Time types in java: vis-a-vis Type-Erasure. It is important to bear in mind that when creating an instance ofclass HNLI or HNLIInclusive(which are extendinterface Iterator<E>- a generic-type), the underlyingVectorover which theIteratoris 'iterating' could be aVectorof a sub-class (inherited class) of the top-levelclass HTMLNode. Specifically this could be anIteratorthat is traversing:Vector<HTMLNode>, Vector<TagNode>, Vector<CommentNode>, etc...
If anIteratoris created for aVector<TagNode>(which are returned by many of the search operations), and an one inserts an instance ofclass CommentNode, Java Will Allow You To Do This ! (Specifically,'ClassCastException'will not be thrown). This is the consequence of Run-TimeType Erasure. There is not necessarily a problem with this, and all it means is that at Run-Time - allVector'sare effectively instances ofVector<Object>. Be aware when inserting nodes intoVector'sabout the pitfalls.- Throws:
SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(); v.add(cursor, n); if (maxCursor != -1) maxCursor++; cursor++; MODIFIED();
-
add
public void add(java.lang.String html)
This provides a way to insertString-represented HTML. The HTML will placed in the underlying HTML-Vectordirectly before the currentcursor-index. Thecursoris situated at the location of the last match returned by theIterator.
This method will perform a parse of HTML that has been represented as aString, and convert it to a Vectorized-HTML partial-page. This partial page is then inserted into the underlyingVectorusing a method of the same name.
Immutability:
TheHTMLNode"Data-Classes" in Java-HTML are all 100% immutable - meaning that if one wants to change a node, a new instance must be instantiated, instead. This concept is rooted in how classclass java.lang.Stringis designed -String'sare also always immutable.
One feature of this design choice, is that "reusing" instances ofHTMLNode, (and its sub-classesTagNode,TextNode&CommentNode) turns out to be easy. If multiple web-pages have a copy of an HTML divider ('DIV') element, there is no chance at all that one of the node-copies will be changed in one sublist, and that - that change - will accidentally modify the content of another web-page (or the content in another location on the same page).
How does all of this affect this method? Well, primarily, this method - if reused over and over in a loop - would be an extremely inefficient way of doing things. All of the nodes being inserted here are un-chaning, by virtue of the fact they are always derived from the exact sameString!
For this reason, it would actually be smarter to insert a pre-parsed HTML-Vector, and reinsert those nodes, over and over again inside of your loop. Because classHTMLNodeis immutable, it is guaranteed that any page or location that's receiving these inserted nodes simply WOULD NOT HAVE TO WORRY ABOUT the contents of any of the nodes in thatVectorfrom being changed in one location, and (unintentionally) reverbrating that change everywhere that theVectorhad been inserted.
Thanks to the "Immutability ofHTMLNode's" - the same copy of an HTML-Vectorcan be re-inserted, over and over again into different pages (or different locations on the same page). In such a scenario, there are no worries that HTML changes in one sub-section will disastrously affect another page, or another part of the page.
If multiple insertions of the same HTML are being performed, it is highly recommended to first parse & instantiate a Vectorized-HTML sub-section first, instead of using this method repeatedly (inside of a loop). This method performs an instantiation & parse of new HTML-Nodes each and every time it is invoked.
In any case where the same HTML is going to be inserted many times, avoiding this method, and rather, relying on the other-version of this method that inserts sublists of 'already-parsed' and 'already-instantiated' vectorized HTML sub-sections would be smarter, as a lot less memory allocations would be made.- Parameters:
html- This is any valid, parse-able HTML section represented as ajava.lang.String. TheStringwill be converted to vectorized-html before insertion.- Throws:
SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
HTMLPage.getPageTokens(CharSequence, boolean)- Code:
- Exact Method Body:
add(HTMLPage.getPageTokens(html, false));
-
add
public void add(java.util.Vector<HTMLNode> html)
Adds vectorized-HTML at the currentcursorposition.- Parameters:
html- This may be any vectorized HTML page or sub-page. It will be inserted at the the location of the last returned match.- Throws:
SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(); v.addAll(cursor, html); cursor += html.size(); if (maxCursor != -1) maxCursor += html.size(); MODIFIED();
-
setHTMLNode
public void setHTMLNode(HTMLNode n)
This provides a way to replace the previous match with an instance ofHTMLNode.The match that is replaced is the one that was last returned from a call to any of:next(), previous(), nextIndex(), previousIndex(),etc...- Parameters:
n- This may be any descendant of theclass HTMLNode. There is an issue to think about when working with Java's Generics and Compile-Time versus Run-Time types in java: vis-a-vis Type-Erasure. It is important to bear in mind that when creating an instance ofclass HNLI or HNLIInclusive(which are extendinterface Iterator<E>- a generic-type), the underlyingVectorover which theIteratoris 'iterating' could be aVectorof a sub-class (inherited class) of the top-levelclass HTMLNode. Specifically this could be anIteratorthat is traversing:Vector<HTMLNode>, Vector<TagNode>, Vector<CommentNode>, etc...
If anIteratoris created for aVector<TagNode>(which are returned by many of the search operations), and an one inserts an instance ofclass CommentNode, Java Will Allow You To Do This ! (Specifically,'ClassCastException'will not be thrown). This is the consequence of Run-TimeType Erasure. There is not necessarily a problem with this, and all it means is that at Run-Time - allVector'sare effectively instances ofVector<Object>. Be aware when inserting nodes intoVector'sabout the pitfalls.- Throws:
SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
remove(),cursor,expectedSize,maxCursor- Code:
- Exact Method Body:
remove(); v.add(cursor, n); cursor++; expectedSize++; if (maxCursor != -1) maxCursor++;
-
set
public void set(java.lang.String html)
Convenience Method
Invokes: (Parses HTML)HTMLPage.getPageTokens(CharSequence, boolean)
And-Then:set(Vector)
Efficiency Warning:
This method will will parse (and re-parse) the HTML inside parameter'html'everytime this method is invoked!- Code:
- Exact Method Body:
set(HTMLPage.getPageTokens(html, false));
-
set
public void set(java.util.Vector<HTMLNode> html)
Replaces the last returned match with the contents of parameter'html'.- Parameters:
html- This may be any-sized html page, or sub-page.- Throws:
SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.- See Also:
Util.Remove.range(Vector, DotPair),remove(),cursor,expectedSize,maxCursor- Code:
- Exact Method Body:
remove(); v.addAll(cursor, html); cursor += html.size(); expectedSize += html.size(); if (maxCursor != -1) maxCursor += + html.size();
-
insertAt
public void insertAt(HTMLNode n, int pos)
Inserts parameterHTMLNode ninto the underlying vectorized-html atVector-index'pos'.- Parameters:
n- This may be any descendant of theclass HTMLNode. There is an issue to think about when working with Java's Generics and Compile-Time versus Run-Time types in java: vis-a-vis Type-Erasure. It is important to bear in mind that when creating an instance ofclass HNLI or HNLIInclusive(which are extendinterface Iterator<E>- a generic-type), the underlyingVectorover which theIteratoris 'iterating' could be aVectorof a sub-class (inherited class) of the top-levelclass HTMLNode. Specifically this could be anIteratorthat is traversing:Vector<HTMLNode>, Vector<TagNode>, Vector<CommentNode>, etc...
If anIteratoris created for aVector<TagNode>(which are returned by many of the search operations), and an one inserts an instance ofclass CommentNode, Java Will Allow You To Do This ! (Specifically,'ClassCastException'will not be thrown). This is the consequence of Run-TimeType Erasure. There is not necessarily a problem with this, and all it means is that at Run-Time - allVector'sare effectively instances ofVector<Object>. Be aware when inserting nodes intoVector'sabout the pitfalls.pos- This is the location in the underlyingVectorbeing iterated where the passed parameter'n'shall be inserted.- Throws:
CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(int),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(pos); v.add(pos, n); if (pos < cursor) cursor++; if (maxCursor != -1) maxCursor++; MODIFIED();
-
insertAt
public void insertAt(java.lang.String html, int pos)
Convenience Method
Invokes: (Parses HTML)HTMLPage.getPageTokens(CharSequence, boolean)
And-Then:insertAt(Vector, int).
Efficiency Warning:
This method will will parse (and re-parse) the HTML inside parameter'html'everytime this method is invoked!- Code:
- Exact Method Body:
insertAt(HTMLPage.getPageTokens(html, false), pos);
-
insertAt
public void insertAt(java.util.Vector<? extends HTMLNode> html, int pos)
Insert the contents of vectorized-html parameter'html'into the underlying htmlVector, beginning at position'pos'.- Parameters:
html- This may be any HTML page or sub-page.pos- This is the location in the underlyingVectorbeing iterated where the passed parameter'html'shall be inserted.- Throws:
CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(int),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(pos); v.addAll(pos, html); if (pos < cursor) cursor += html.size(); if (maxCursor != -1) maxCursor += html.size(); MODIFIED();
-
replaceRange
public void replaceRange(int sPos, int ePos, java.util.Vector<HTMLNode> newNodes)
Convenience Method
Invokes:replaceRange(DotPair, Vector)
Off-By-One Mistake:ePosis decremented by 1, sinceDotPair.endis always an inclusive value, whileePosis always exclusive.- Code:
- Exact Method Body:
replaceRange(new DotPair(sPos, ePos - 1), newNodes);
-
replaceRange
public void replaceRange(DotPair range, java.util.Vector<HTMLNode> newNodes)
This replaces a specified sub-range of nodes in the underlying vectorized-html with the nodes in'newNodes'.- Parameters:
range- This is the sub-range or "sub-section" of the underlying vectorized-html page that is going to be replaced by the'newNodes'.newNodes- These are the nodes to be inserted into the location where the old range is.- Throws:
CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
Util.Remove.range(Vector, DotPair),DotPair.isInside(int),DotPair.size(),CHECK_EXCEPTIONS(DotPair),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(range); Util.replaceRange(v, range, newNodes); int sizeChange = newNodes.size() - range.size(); if (range.isInside(cursor)) cursor = range.start; else if(cursor > range.end) cursor += sizeChange; if (maxCursor != -1) maxCursor += sizeChange; MODIFIED();
-
removeElementAt
public void removeElementAt(int pos)
This removes the node at a specified index in the underlying vectorized-html.- Parameters:
pos- This is the index into the underlying vectorized-html page to be removed.- Throws:
CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(int),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(pos); v.removeElementAt(pos); if (pos < cursor) cursor--; if (maxCursor != -1) maxCursor--; MODIFIED();
-
removeRange
public void removeRange(int sPos, int ePos)
Convenience Method
Invokes:removeRange(int, int)
Off-By-One Mistake:ePosis decremented by 1, sinceDotPair.endis always an inclusive value, whileePosis always exclusive.- Code:
- Exact Method Body:
removeRange(new DotPair(sPos, ePos-1));
-
removeRange
public void removeRange(DotPair range)
This removes a specified sub-range of nodes in the underlying vectorized-html.- Parameters:
range- This is the sub-range or "sub-section" of the underlying vectorized-html page;- Throws:
CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
DotPair.isInside(int),DotPair.size(),CHECK_EXCEPTIONS(DotPair),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(range); Util.Remove.range(v, range); if (range.isInside(cursor)) cursor = range.start; else if(cursor > range.end) cursor -= range.size(); if (maxCursor != -1) maxCursor -= range.size(); MODIFIED();
-
removeElements
public void removeElements(int... posArr)
This will remove everyVector-element that is identified by the'posArr'Vector-positionint[]array.- Parameters:
posArr- This is a list of nodes that shall be removed from the underlying html-Vector.- Throws:
CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_EXCEPTIONS(int[]),MODIFIED()- Code:
- Exact Method Body:
CHECK_EXCEPTIONS(posArr); Util.Remove.nodes(false, v, posArr); // false --> sorts the input int[] array int ORIGINAL_CURSOR = cursor; for (int pos : posArr) if (pos < ORIGINAL_CURSOR) cursor--; else break; if (maxCursor != -1) maxCursor -= posArr.length; MODIFIED();
-
CHECK_EXCEPTIONS
protected void CHECK_EXCEPTIONS(int pos)
Checks the input position'pos'parameter to verify it is not out of the bounds of the underlying HTML-Vector, nor out of the bounds of theCursor Boundary Window- if one has been set.
This shall throw exceptions if the passed'range'is out of either of these bounds.
Upon completion of this test, the rest of the standard Exception check-throws are performed.- Throws:
IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.- See Also:
CHECK_EXCEPTIONS()- Code:
- Exact Method Body:
IteratorOutOfBoundsException.check(v, pos); CursorException.check(minCursor, maxCursor, pos); CHECK_EXCEPTIONS();
-
CHECK_EXCEPTIONS
protected void CHECK_EXCEPTIONS(DotPair range)
Checks the input position'range'parameter to verify the providedrangevalues are not out of the bounds of the underlying HTML-Vector, nor out of the bounds of theCursor Boundary Window- if one has been set.
This shall throw exceptions if the passed'range'is out of either of these bounds.
Upon completion of this test, the rest of the standard Exception check-throws are performed.- Throws:
IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.- See Also:
CHECK_EXCEPTIONS()- Code:
- Exact Method Body:
IteratorOutOfBoundsException.check(v, range); CursorException.check(minCursor, maxCursor, range); CHECK_EXCEPTIONS();
-
CHECK_EXCEPTIONS
protected void CHECK_EXCEPTIONS(int[] posArr)
Checks the input position-array'posArr'parameter to verify that none of the indices listed in this position-array are out of the bounds of the underlying HTML-Vector, nor out of the bounds of theCursor Boundary Window- if one has been set.
This shall throw exceptions if the indices in this input array extend past either of these boundaries.
Upon completion of this test, the rest of the standard Exception check-throws are performed.- Throws:
IteratorOutOfBoundsException- This exception will be thrown if any of theinsertorremovemethods are invoked with any value for theint posparameter (or values in theint[] posArrparameter) that are negative, or past the end of the underlying vectorized-html.CursorException- Whenever a method attempts to modify the underlying HTMLVector, the location where the modification is occurring shall be checked against theCursor Boundary Window. It is not mandatory that anHTML Node List Iteratorhave aBoundary Windowset for thecursor, and by default, no such window is created. If, however, one was created, the modificationVectorindex or indices shall be checked against the values set forminCursorandmaxCursor- and if the location does not fall within the window's bounds, (if the window exists) aCursorExceptionshall throw.- See Also:
CHECK_EXCEPTIONS()- Code:
- Exact Method Body:
IteratorOutOfBoundsException.check(v, posArr); CursorException.check(minCursor, maxCursor, posArr); CHECK_EXCEPTIONS();
-
CHECK_EXCEPTIONS
protected void CHECK_EXCEPTIONS()
Does a check regarding whether any exceptions should throw.- Throws:
java.lang.IllegalStateException- This exception will also throw if theIteratorhas just been constructed, and no calls tonext, previous, firstorlasthave been made (or any of their variants). This is necessary because until a value has been returned by theIterator, the internalcursorhas not been set to a valid match-value, and thusly modifying a value near thecursor-index would have non-deterministic results.SecondModificationException- This exception will throw if successive, multiple invocations are made to any of theIteratormethod variants foradd(...), set(...),orremove(...)without an inter-leaved, or intervening call being made to the standard getter methodsnext(), nextDotPair(), previous(), previousDotPair, first()orlast(),etc...BothHNLI Iteratorsshall not permit successive calls to theadd, set,orremoveoperations after a call tonext, previous, firstorlast. Operations that modify the underlyingVectormay only be invoked once per retrieval operation. That means after any retrieval operation such as:next(), previous(), first(), etc... The iteration-match can be changed, appended, etc. - but this may only occur once per match. After the first change, the user is expected to move on to the next iteration-match before making a second attempt to modify the underlying vectorized-html.java.util.ConcurrentModificationException- Internal to thisIterator'sstate is a privateint-field named'expectedSize'that is consistently maintained to know the current size of the underlying HTML-Vector. Whenever modifications are made to that HTML with this class' Add, Set & Remove methods - this class code will also, simultaenously, update the'expectedSize'field.
If changes to the HTML-Vectorare made outside of this class' Add, Set, Remove or Update interface-methods, then the value of this internal integer-field ('expectedSize') will stop being consistent with the actual size of the HTML-Vector.
When the size of the internal HTML-Vectordoes not equal the value stored inside field'expectedSize', this class' code will throw aConcurrentModificationException.Changes to the underlyingVectorthat do not modify theVector'ssize simply won't be detected. This is (somewhat) due to 'a bug' in the JDK implementation ofAbstractListwhere the integer-field named'modCount'is assigned'protected'visibility, rendering it somewhat useless.RESET NOTE: Any call made to a variant of the providedfirst(...)orlast(...)methods will force a reset of this the internal integer-field'expected-size'(to the <Vector'sactual size). When this field is reset, it will actually prevent theConcurrentModificationExceptionfrom throwing - even if code from outside this class has changed the size of the HTML-Vector- because it becomes impossible to detect that change.- See Also:
CHECK_CME()- Code:
- Exact Method Body:
CHECK_CME(); if (cursor == -1) throw new IllegalStateException( "Neither next, nor previous have been called since initializing the iterator with a " + "constructor." ); if (modifiedSince) throw new SecondModificationException( "One of the remove, add, or set methods - which are this Iterator's Update (Modifier) " + "Operations - has already been called since the prior call to a next, previous, first, " + "or last (Inspection) method. The Modifier and Inspection methods / API of this " + "Iterator may only be used ONCE PER CALL (or, rather, on A ONE-TO-ONE BASIS) with " + "each-other. In other words, after an invocation of an 'Inspection Method' (such as " + "'next'), only one invocation of a 'Modifier Method' (such as 'set') will be allowed " + "until another inspection is invoked." );
-
CHECK_CME
protected void CHECK_CME()
Does a check regarding whether an exception should throw.- Throws:
java.util.ConcurrentModificationException- Checks for, and throws if necessary, Java'sConcurrentModificationException.- Code:
- Exact Method Body:
if (expectedSize != v.size()) throw new ConcurrentModificationException( "The expected size of the underlying vector was: [" + expectedSize + "], but the " + "encountered size was: [" + v.size() + "]. This implies that the Vector was modified " + "outside of this HNLI Iterator's provided update & modify API. This is not allowed, " + "unless followed by a call to: first, last, firstIndex, or lastIndex - all of which " + "'reset' the outside-modification monitor-logic (as do the cursor-movement and cursor " + "bounds methods)." );
-
-