1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.pattern.parser;
15
16 public class Node {
17 static final int LITERAL = 0;
18 static final int SIMPLE_KEYWORD = 1;
19 static final int COMPOSITE_KEYWORD = 2;
20
21 final int type;
22 final Object value;
23 Node next;
24
25 Node(int type) {
26 this(type, null);
27 }
28
29 Node(int type, Object value) {
30 this.type = type;
31 this.value = value;
32 }
33
34
35
36
37 public int getType() {
38 return type;
39 }
40
41
42
43
44 public Object getValue() {
45 return value;
46 }
47
48 public Node getNext() {
49 return next;
50 }
51
52 public void setNext(Node next) {
53 this.next = next;
54 }
55
56 public boolean equals(Object o) {
57 if (this == o) {
58 return true;
59 }
60 if (!(o instanceof Node)) {
61 return false;
62 }
63 Node r = (Node) o;
64
65 return (type == r.type) && (value != null ? value.equals(r.value) : r.value == null)
66 && (next != null ? next.equals(r.next) : r.next == null);
67 }
68
69 @Override
70 public int hashCode() {
71 int result = type;
72 result = 31 * result + (value != null ? value.hashCode() : 0);
73 return result;
74 }
75
76 String printNext() {
77 if (next != null) {
78 return " -> " + next;
79 } else {
80 return "";
81 }
82 }
83
84 public String toString() {
85 StringBuilder buf = new StringBuilder();
86 switch (type) {
87 case LITERAL:
88 buf.append("LITERAL(" + value + ")");
89 break;
90 default:
91 buf.append(super.toString());
92 }
93
94 buf.append(printNext());
95
96 return buf.toString();
97 }
98 }