1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.message; 18 19 /** 20 * The simplest possible implementation of Message. It just returns the String given as the constructor argument. 21 */ 22 public class SimpleMessage implements Message { 23 private static final long serialVersionUID = -8398002534962715992L; 24 25 private final String message; 26 27 /** 28 * Basic constructor. 29 */ 30 public SimpleMessage() { 31 this(null); 32 } 33 34 /** 35 * Constructor that includes the message. 36 * @param message The String message. 37 */ 38 public SimpleMessage(final String message) { 39 this.message = message; 40 } 41 42 /** 43 * Returns the message. 44 * @return the message. 45 */ 46 public String getFormattedMessage() { 47 return message; 48 } 49 50 /** 51 * Returns the message. 52 * @return the message. 53 */ 54 public String getFormat() { 55 return message; 56 } 57 58 /** 59 * Returns null since there are no parameters. 60 * @return null. 61 */ 62 public Object[] getParameters() { 63 return null; 64 } 65 66 @Override 67 public boolean equals(final Object o) { 68 if (this == o) { 69 return true; 70 } 71 if (o == null || getClass() != o.getClass()) { 72 return false; 73 } 74 75 final SimpleMessage that = (SimpleMessage) o; 76 77 return !(message != null ? !message.equals(that.message) : that.message != null); 78 } 79 80 @Override 81 public int hashCode() { 82 return message != null ? message.hashCode() : 0; 83 } 84 85 @Override 86 public String toString() { 87 return "SimpleMessage[message=" + message + "]"; 88 } 89 90 /** 91 * Always returns null. 92 * 93 * @return null 94 */ 95 public Throwable getThrowable() { 96 return null; 97 } 98 }