View Javadoc

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