2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import java
.util
.HashSet
;
33 import java
.util
.ResourceBundle
;
36 * A Link is a section of text with a reference to a Topic.
40 // ------------------------------------------------------------------------
41 // Variables --------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * The topic id that this link points to.
50 * The text inside the link tag.
55 * The number of words in this link.
57 private int wordCount
;
60 * The word number (from the beginning of topic text) that corresponds to
61 * the first word of this link.
65 // ------------------------------------------------------------------------
66 // Constructors -----------------------------------------------------------
67 // ------------------------------------------------------------------------
72 * @param topic the topic to point to
73 * @param text the text inside the link tag
74 * @param index the word count index
76 public Link(final String topic
, final String text
, final int index
) {
80 this.wordCount
= text
.split("\\s+").length
;
83 // ------------------------------------------------------------------------
84 // Link -------------------------------------------------------------------
85 // ------------------------------------------------------------------------
92 public String
getTopic() {
99 * @return the text inside the link tag
101 public String
getText() {
106 * Get the word index for this link.
108 * @return the word number (from the beginning of topic text) that
109 * corresponds to the first word of this link
111 public int getIndex() {
116 * Get the number of words in this link.
118 * @return the number of words in this link
120 public int getWordCount() {
125 * Generate a human-readable string for this widget.
127 * @return a human-readable string
130 public String
toString() {
131 return String
.format("%s(%8x) topic %s link text %s word # %d count %d",
132 getClass().getName(), hashCode(), topic
, text
, index
, wordCount
);