mirror of
https://github.com/danbulant/introductionToProgramming
synced 2026-05-19 12:28:44 +00:00
45 lines
1 KiB
Java
45 lines
1 KiB
Java
public class HtmlItem {
|
|
public enum HtmlItemType {
|
|
Text,
|
|
Tag
|
|
}
|
|
|
|
HtmlItemType type;
|
|
String textContent;
|
|
HtmlTag tagContent;
|
|
|
|
public static HtmlItem tag(HtmlTag tag) {
|
|
var item = new HtmlItem();
|
|
item.type = HtmlItemType.Tag;
|
|
item.tagContent = tag;
|
|
return item;
|
|
}
|
|
|
|
public static HtmlItem text(String content) {
|
|
var item = new HtmlItem();
|
|
item.type = HtmlItemType.Text;
|
|
item.textContent = content;
|
|
return item;
|
|
}
|
|
|
|
public HtmlTag getTag() {
|
|
assert this.type == HtmlItemType.Tag;
|
|
return this.tagContent;
|
|
}
|
|
|
|
public String getText() {
|
|
assert this.type == HtmlItemType.Text;
|
|
return this.textContent;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
switch (this.type) {
|
|
case HtmlItemType.Tag:
|
|
return this.tagContent.toString();
|
|
case HtmlItemType.Text:
|
|
return this.textContent;
|
|
}
|
|
return null;
|
|
}
|
|
}
|