aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/html/ElementNode.java
blob: 3faf4ae28f9aff0f1729b82f11eff82283e0ce29 (plain) (blame)
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
package model.html;

import org.javatuples.Pair;

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;

    private final ArrayList<Node> children;

    public ElementNode(String tag, ArrayList<Pair<String, String>> attributes, ArrayList<Node> children) {
        this.tag = tag;
        this.attributes = attributes;
        this.children = children;
    }

    /**
     * Overloads the constructor for ease of use. We often don't provide children, at first.
     */
    public ElementNode(String tag, ArrayList<Pair<String, String>> attributes) {
        this(tag, attributes, new ArrayList<>());
    }

    /**
     * Overloads the constructor for ease of use. Should probably only be used for tests.
     */
    public ElementNode(String tag) {
        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();
    }
}