MCPcopy Create free account
hub / github.com/careercup/ctci / Element

Class Element

java/Chapter 17/Question17_10/Element.java:5–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import java.util.ArrayList;
4
5public class Element {
6 public ArrayList<Attribute> attributes;
7 public ArrayList<Element> children;
8 public String name;
9 public String value;
10
11 public Element(String n) {
12 name = n;
13 attributes = new ArrayList<Attribute>();
14 children = new ArrayList<Element>();
15 }
16
17 public Element(String n, String v) {
18 name = n;
19 value = v;
20 attributes = new ArrayList<Attribute>();
21 children = new ArrayList<Element>();
22 }
23
24 public String getNameCode() {
25 if (name == "family") {
26 return "1";
27 } else if (name == "person") {
28 return "2";
29 } else if (name == "firstName") {
30 return "3";
31 } else if (name == "lastName") {
32 return "4";
33 } else if (name == "state") {
34 return "5";
35 }
36 return "--";
37 }
38
39 public void insert(Attribute attribute) {
40 attributes.add(attribute);
41 }
42
43 public void insert(Element child) {
44 children.add(child);
45 }
46}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected