1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | package Torello.HTML; import java.util.Comparator; /** * Represents document text, and is one of only three HTML Element Classes provided by the Java * HTML Library Tool, and also oneof the three classes that can be generated by the HTML Parser. * * <EMBED CLASS='external-html' DATA-FILE-ID=TEXT_NODE> * * <EMBED CLASS='external-html' DATA-FILE-ID=HTML_NODE_SUB_IMG> * * @see HTMLNode * @see TagNode * @see CommentNode */ @Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="HTML_NODE_SUBCLASS") public final class TextNode extends HTMLNode implements CharSequence, java.io.Serializable, Cloneable, Comparable<TextNode> { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ public static final long serialVersionUID = 1; /** * Constructs a new {@code TextNode} with internal field {@code String str} equal to parameter * {@code 's'} * * @param s Any valid Java {@code String} may be passed here. */ public TextNode(String s) { super(s); } /** * This method identifies that {@code 'this'} instance of (abstract parent-class) * {@link HTMLNode} is, indeed, an instance of sub-class {@code TextNode}. * * <BR /><BR /><B CLASS=JDDescLabel>Final Method:</B> * * <BR />This method is final, and cannot be modified by sub-classes. * * @return This method shall always return {@code TRUE} It overrides the parent-class * {@code HTMLNode} method {@link #isTextNode()}, which always returns {@code FALSE}. */ @Override public final boolean isTextNode() { return true; } /** * This method identifies that {@code 'this'} instance of (abstract parent-class) * {@link HTMLNode} is, indeed, an instance of sub-class {@code TextNode}. * * <BR /><BR /><B CLASS=JDDescLabel>Final Method:</B> * * <BR />This method is final, and cannot be modified by sub-classes. * * @return {@code 'this'} reference. This method can be used inside loops for improving * the readability of loop-condition expressions. See example below: * * <DIV CLASS=EXAMPLE>{@code * TextNode t; * * for (HTMLNode n : myHTMLVector) * if ((t = n.ifTextNode()) != null) * System.out.println("Text-Node Contains: " + t.str); * }</div> * * <BR /><BR />This method-version overrides the parent-class-version, which always returns * null. This method is <I>not overriden by other {@code HTMLNode} sub-classes.</I> */ @Override public final TextNode ifTextNode() { return this; } /** * Java's {@code interface Cloneable} requirements. This instantiates a new {@code TextNode} * with identical {@code String str} fields. * * @return A new {@code TextNode} whose internal fields are identical to this one. */ public TextNode clone() { return new TextNode(str); } /** * Java's {@code interface Comparable<T>} requirements. This does a very simple comparison * using the underlying field {@code final String str} that all Text's contain. * * @param tn Any other {@code TextNode} to be compared to {@code 'this' TextNode} * * @return An integer that fulfils Java's {@code interface Comparable<T> public boolean * compareTo(T t)} method requirements. */ public int compareTo(TextNode tn) { return this.str.compareTo(tn.str); } /** * This is an "alternative Comparitor" that can be used for sorting instances of this class. * It should work with the {@code Collections.sort(List, Comparator)} method in the standard * JDK package {@code java.util.*;} * * <BR /><BR /><B>NOTE:</B> This version utilizes the standard JDK * {@code String.compareToIgnoreCase(String)} method. * * @see HTMLNode#str */ public static final Comparator<TextNode> comp2 = (TextNode txn1, TextNode txn2) -> txn1.str.compareToIgnoreCase(txn2.str); } |