aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/html
diff options
context:
space:
mode:
authorJJ2022-12-28 06:26:54 +0000
committerJJ2022-12-28 23:31:27 +0000
commit4d55ecb842fab83e25adfd2cac76bc6b1ba8d0da (patch)
treef42dc8d25856b1ea0a7decc95c9734842976b235 /src/main/model/html
parenta1b9e8c5259472ab13b2fd4161d3df8825f52b86 (diff)
encapsulation is evil
Diffstat (limited to 'src/main/model/html')
-rw-r--r--src/main/model/html/ElementNode.java26
-rw-r--r--src/main/model/html/HtmlParser.java6
-rw-r--r--src/main/model/html/Node.java2
-rw-r--r--src/main/model/html/TextNode.java2
4 files changed, 10 insertions, 26 deletions
diff --git a/src/main/model/html/ElementNode.java b/src/main/model/html/ElementNode.java
index 3faf4ae..358d97c 100644
--- a/src/main/model/html/ElementNode.java
+++ b/src/main/model/html/ElementNode.java
@@ -8,10 +8,10 @@ import java.util.ArrayList;
* This ElementNode class represents an HTML tag and nested tags.
*/
public class ElementNode implements Node {
- private final String tag;
- private final ArrayList<Pair<String,String>> attributes;
+ public final String tag;
+ public final ArrayList<Pair<String,String>> attributes;
- private final ArrayList<Node> children;
+ public final ArrayList<Node> children;
public ElementNode(String tag, ArrayList<Pair<String, String>> attributes, ArrayList<Node> children) {
this.tag = tag;
@@ -33,24 +33,8 @@ public class ElementNode implements Node {
this(tag, new ArrayList<>(), new ArrayList<>());
}
- public void addChild(Node child) {
- this.children.add(child);
- }
-
- public String getTag() {
- return this.tag;
- }
-
- public ArrayList<Pair<String, String>> getAttributes() {
- return this.attributes;
- }
-
- public ArrayList<Node> getChildren() {
- return this.children;
- }
-
// We implement this method for easy debugging.
- public String getData() {
- return getTag() + " " + getAttributes().toString();
+ public String data() {
+ return this.tag + " " + this.attributes.toString();
}
}
diff --git a/src/main/model/html/HtmlParser.java b/src/main/model/html/HtmlParser.java
index 5e5e7ce..a3abe0f 100644
--- a/src/main/model/html/HtmlParser.java
+++ b/src/main/model/html/HtmlParser.java
@@ -219,9 +219,9 @@ public class HtmlParser {
// Helper function to remove code duplication.
private void addNewElementNode() {
state = ParserState.HTML;
- ElementNode node = new ElementNode(currentTag, currentAttributes);
+ var node = new ElementNode(currentTag, currentAttributes);
if (unfinished.size() != 0) {
- unfinished.getLast().addChild(node);
+ unfinished.getLast().children.add(node);
if (!isSelfClosingTag(currentTag)) {
unfinished.add(node);
}
@@ -238,7 +238,7 @@ public class HtmlParser {
// Helper function to check method length boxes.
private void addNewTextNode() {
if (unfinished.size() != 0) {
- unfinished.getLast().addChild(new TextNode(currentText));
+ unfinished.getLast().children.add(new TextNode(currentText));
} else {
result.add(new TextNode(currentText));
}
diff --git a/src/main/model/html/Node.java b/src/main/model/html/Node.java
index 9a846ee..be217f6 100644
--- a/src/main/model/html/Node.java
+++ b/src/main/model/html/Node.java
@@ -6,5 +6,5 @@ package model.html;
*/
public interface Node {
// Return a representation of the Node. Useful for debugging.
- public String getData();
+ public String data();
}
diff --git a/src/main/model/html/TextNode.java b/src/main/model/html/TextNode.java
index c50ce0f..29f2791 100644
--- a/src/main/model/html/TextNode.java
+++ b/src/main/model/html/TextNode.java
@@ -5,7 +5,7 @@ package model.html;
*/
public record TextNode(String text) implements Node {
// We implement this method for easy debugging.
- public String getData() {
+ public String data() {
return text();
}
}