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.subst;
15
16 public class Token {
17
18     static public final Token START_TOKEN = new Token(Type.START, null);
19     static public final Token CURLY_LEFT_TOKEN = new Token(Type.CURLY_LEFT, null);
20     static public final Token CURLY_RIGHT_TOKEN = new Token(Type.CURLY_RIGHT, null);
21     static public final Token DEFAULT_SEP_TOKEN = new Token(Type.DEFAULT, null);
22
23     public enum Type {
24         LITERAL, START, CURLY_LEFT, CURLY_RIGHT, DEFAULT
25     }
26
27     Type type;
28     String payload;
29
30     public Token(Type type, String payload) {
31         this.type = type;
32         this.payload = payload;
33     }
34
35     @Override
36     public boolean equals(Object o) {
37         if (this == o)
38             return true;
39         if (o == null || getClass() != o.getClass())
40             return false;
41
42         Token token = (Token) o;
43
44         if (type != token.type)
45             return false;
46         if (payload != null ? !payload.equals(token.payload) : token.payload != null)
47             return false;
48
49         return true;
50     }
51
52     @Override
53     public int hashCode() {
54         int result = type != null ? type.hashCode() : 0;
55         result = 31 * result + (payload != null ? payload.hashCode() : 0);
56         return result;
57     }
58
59     @Override
60     public String toString() {
61         String result = "Token{" + "type=" + type;
62         if (payload != null)
63             result += ", payload='" + payload + '\'';
64
65         result += '}';
66         return result;
67     }
68 }
69