View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 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       * @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) && (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  }