View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.pattern.parser;
15  
16  public class Node {
17  	static final int LITERAL = 0;
18  	static final int KEYWORD = 1;
19  	static final int COMPOSITE = 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  	 * @return Returns the type.
36  	 */
37  	public int getType() {
38  		return type;
39  	}
40  
41  	/**
42  	 * @return Returns the value.
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)
66  				&& (value != null ? value.equals(r.value) : r.value == null)
67  				&& (next != null ? next.equals(r.next) : r.next == null);
68  	}
69  
70  	String printNext() {
71  		if (next != null) {
72  			return " -> " + next;
73  		} else {
74  			return "";
75  		}
76  	}
77  
78  	public String toString() {
79  		StringBuffer buf = new StringBuffer();
80  		switch (type) {
81  		case LITERAL:
82  			buf.append("LITERAL(" + value + ")");
83  			break;
84  		default:
85  			buf.append(super.toString());
86  		}
87  
88  		buf.append(printNext());
89  		
90  		return buf.toString();
91  	}
92  }