Package Torello.HTML

Class Util.Count

  • Enclosing class:
    Util

    public static class Util.Count
    extends java.lang.Object



    Stateless Class:
    This class neither contains any program-state, nor can it be instantiated. The @StaticFunctional Annotation may also be called 'The Spaghetti Report'. Static-Functional classes are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's @Stateless Annotation.

    • 1 Constructor(s), 1 declared private, zero-argument constructor
    • 12 Method(s), 12 declared static
    • 0 Field(s)


    • Method Detail

      • textNodes

        🡅  🡇     🗕  🗗  🗖
        public static int textNodes​(java.util.Vector<HTMLNode> page,
                                    int sPos,
                                    int ePos)
        Counts the number of TextNode's in a Vector<HTMLNode> between the demarcated array / Vector positions, 'sPos' and 'ePos'
        Parameters:
        page - Any HTML page.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of TextNode's in the Vector between the demarcated indices.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         int counter = 0;
         LV  l       = new LV(page, sPos, ePos);
        
         // Iterates the entire page between sPos and ePos, incrementing the count for every
         // instance of text-node.
        
         for (int i=l.start; i < l.end; i++) if (page.elementAt(i).isTextNode()) counter++;
        
         return counter;
        
      • commentNodes

        🡅  🡇     🗕  🗗  🗖
        public static int commentNodes​(java.util.Vector<HTMLNode> page,
                                       int sPos,
                                       int ePos)
        Counts the number of CommentNode's in an Vector<HTMLNode> between the demarcated array / Vector positions.
        Parameters:
        page - Any HTML page.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of CommentNode's in the Vector between the demarcated indices.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         int counter = 0;
         LV  l       = new LV(page, sPos, ePos);
        
         // Iterates the entire page between sPos and ePos, incrementing the count for every
         // instance of comment-node.
        
         for (int i=l.start; i < l.end; i++)  if (page.elementAt(i).isCommentNode()) counter++;
        
         return counter;
        
      • tagNodes

        🡅  🡇     🗕  🗗  🗖
        public static int tagNodes​(java.util.Vector<HTMLNode> page,
                                   int sPos,
                                   int ePos)
        Counts the number of TagNode's in a Vector<HTMLNode> between the demarcated array / Vector positions.
        Parameters:
        page - Any HTML page.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of TagNode's in the Vector.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         int counter = 0;
         LV  l       = new LV(page, sPos, ePos);
        
         // Iterates the entire page between sPos and ePos, incrementing the count for every
         // instance of TagNode.
        
         for (int i=l.start; i < l.end; i++) if (page.elementAt(i).isTagNode()) counter++;
        
         return counter;
        
      • newLines

        🡅     🗕  🗗  🗖
        public static int newLines​(java.util.Vector<? extends HTMLNode> html,
                                   int sPos,
                                   int ePos)
        This will count the number of new-line symbols present - on the partial HTML page. The count will include a sum of every HTMLNode.str that contains the standard new-line symbols: \r\n, \r, \n, meaning that UNIX, MSFT, Apple, etc. forms of text-line rendering should all be treated equally.
        Parameters:
        html - This may be any Vectorized-HTML Web-Page (or sub-page).

        The Variable-Type Wild-Card Expression '? extends HTMLNode' means that a Vector<TagNode>, Vector<TextNode> or Vector<CommentNode> will all be accepted by this paramter without causing an exception throw.

        These 'sub-type' Vectors are often returned as search results from the classes in the 'NodeSearch'vpackage.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of new-line characters in all of the HTMLNode's that occur between vectorized-page positions 'sPos' and 'ePos.'

        NOTE: The regular-expression used here 'NEWLINEP' is as follows:
         private static final Pattern NEWLINEP = Pattern.compile("\\r\\n|\\r|\\n");
        
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        See Also:
        StringParse.NEWLINEP
        Code:
        Exact Method Body:
         int newLineCount    = 0;
         LV  l               = new LV(html, sPos, ePos);
        
         for (int i=l.start; i < l.end; i++)
        
             // Uses the Torello.Java.StringParse "New Line RegEx"
             for (   Matcher m = StringParse.NEWLINEP.matcher(html.elementAt(i).str);
                     m.find();
                     newLineCount++);
        
         return newLineCount;