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 import java.io.Serializable; 20 21 /** 22 * The simplest possible implementation of Message. It just returns the String given as the constructor argument. 23 */ 24 public class SimpleMessage implements Message, Serializable { 25 private static final long serialVersionUID = -8398002534962715992L; 26 27 private final String message; 28 29 /** 30 * Basic constructor. 31 */ 32 public SimpleMessage() { 33 this(null); 34 } 35 36 /** 37 * Constructor that includes the message. 38 * @param message The String message. 39 */ 40 public SimpleMessage(String message) { 41 this.message = message; 42 } 43 44 /** 45 * Returns the message. 46 * @return the message. 47 */ 48 public String getFormattedMessage() { 49 return message; 50 } 51 52 /** 53 * Returns the message. 54 * @return the message. 55 */ 56 public String getFormat() { 57 return message; 58 } 59 60 /** 61 * Returns null since there are no parameters. 62 * @return null. 63 */ 64 public Object[] getParameters() { 65 return null; 66 } 67 68 @Override 69 public boolean equals(Object o) { 70 if (this == o) { 71 return true; 72 } 73 if (o == null || getClass() != o.getClass()) { 74 return false; 75 } 76 77 SimpleMessage that = (SimpleMessage) o; 78 79 return !(message != null ? !message.equals(that.message) : that.message != null); 80 } 81 82 @Override 83 public int hashCode() { 84 return message != null ? message.hashCode() : 0; 85 } 86 87 @Override 88 public String toString() { 89 return "SimpleMessage[message=" + message + "]"; 90 } 91 }