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) && (next != null ? next.equals(r.next) : r.next == null);
66      }
67  
68      @Override
69      public int hashCode() {
70          int result = type;
71          result = 31 * result + (value != null ? value.hashCode() : 0);
72          return result;
73      }
74  
75      String printNext() {
76          if (next != null) {
77              return " -> " + next;
78          } else {
79              return "";
80          }
81      }
82  
83      public String toString() {
84          StringBuilder buf = new StringBuilder();
85          switch (type) {
86          case LITERAL:
87              buf.append("LITERAL(" + value + ")");
88              break;
89          default:
90              buf.append(super.toString());
91          }
92  
93          buf.append(printNext());
94  
95          return buf.toString();
96      }
97  }