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.subst; 015 016public class Token { 017 018 static public final Token START_TOKEN = new Token(Type.START, null); 019 static public final Token CURLY_LEFT_TOKEN = new Token(Type.CURLY_LEFT, null); 020 static public final Token CURLY_RIGHT_TOKEN = new Token(Type.CURLY_RIGHT, null); 021 static public final Token DEFAULT_SEP_TOKEN = new Token(Type.DEFAULT, null); 022 023 public enum Type { 024 LITERAL, START, CURLY_LEFT, CURLY_RIGHT, DEFAULT 025 } 026 027 Type type; 028 String payload; 029 030 public Token(Type type, String payload) { 031 this.type = type; 032 this.payload = payload; 033 } 034 035 @Override 036 public boolean equals(Object o) { 037 if (this == o) 038 return true; 039 if (o == null || getClass() != o.getClass()) 040 return false; 041 042 Token token = (Token) o; 043 044 if (type != token.type) 045 return false; 046 if (payload != null ? !payload.equals(token.payload) : token.payload != null) 047 return false; 048 049 return true; 050 } 051 052 @Override 053 public int hashCode() { 054 int result = type != null ? type.hashCode() : 0; 055 result = 31 * result + (payload != null ? payload.hashCode() : 0); 056 return result; 057 } 058 059 @Override 060 public String toString() { 061 String result = "Token{" + "type=" + type; 062 if (payload != null) 063 result += ", payload='" + payload + '\''; 064 065 result += '}'; 066 return result; 067 } 068}