001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.pattern.parser; 015 016public class Node { 017 static final int LITERAL = 0; 018 static final int SIMPLE_KEYWORD = 1; 019 static final int COMPOSITE_KEYWORD = 2; 020 021 final int type; 022 final Object value; 023 Node next; 024 025 Node(int type) { 026 this(type, null); 027 } 028 029 Node(int type, Object value) { 030 this.type = type; 031 this.value = value; 032 } 033 034 /** 035 * @return Returns the type. 036 */ 037 public int getType() { 038 return type; 039 } 040 041 /** 042 * @return Returns the value. 043 */ 044 public Object getValue() { 045 return value; 046 } 047 048 public Node getNext() { 049 return next; 050 } 051 052 public void setNext(Node next) { 053 this.next = next; 054 } 055 056 public boolean equals(Object o) { 057 if (this == o) { 058 return true; 059 } 060 if (!(o instanceof Node)) { 061 return false; 062 } 063 Node r = (Node) o; 064 065 return (type == r.type) && (value != null ? value.equals(r.value) : r.value == null) 066 && (next != null ? next.equals(r.next) : r.next == null); 067 } 068 069 @Override 070 public int hashCode() { 071 int result = type; 072 result = 31 * result + (value != null ? value.hashCode() : 0); 073 return result; 074 } 075 076 String printNext() { 077 if (next != null) { 078 return " -> " + next; 079 } else { 080 return ""; 081 } 082 } 083 084 public String toString() { 085 StringBuilder buf = new StringBuilder(); 086 switch (type) { 087 case LITERAL: 088 buf.append("LITERAL(" + value + ")"); 089 break; 090 default: 091 buf.append(super.toString()); 092 } 093 094 buf.append(printNext()); 095 096 return buf.toString(); 097 } 098}