001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017 package org.apache.logging.log4j.message; 018 019 import java.io.Serializable; 020 021 /** 022 * The simplest possible implementation of Message. It just returns the String given as the constructor argument. 023 */ 024 public class SimpleMessage implements Message, Serializable { 025 private static final long serialVersionUID = -8398002534962715992L; 026 027 private final String message; 028 029 /** 030 * Basic constructor. 031 */ 032 public SimpleMessage() { 033 this(null); 034 } 035 036 /** 037 * Constructor that includes the message. 038 * @param message The String message. 039 */ 040 public SimpleMessage(String message) { 041 this.message = message; 042 } 043 044 /** 045 * Returns the message. 046 * @return the message. 047 */ 048 public String getFormattedMessage() { 049 return message; 050 } 051 052 /** 053 * Returns the message. 054 * @return the message. 055 */ 056 public String getFormat() { 057 return message; 058 } 059 060 /** 061 * Returns null since there are no parameters. 062 * @return null. 063 */ 064 public Object[] getParameters() { 065 return null; 066 } 067 068 @Override 069 public boolean equals(Object o) { 070 if (this == o) { 071 return true; 072 } 073 if (o == null || getClass() != o.getClass()) { 074 return false; 075 } 076 077 SimpleMessage that = (SimpleMessage) o; 078 079 return !(message != null ? !message.equals(that.message) : that.message != null); 080 } 081 082 @Override 083 public int hashCode() { 084 return message != null ? message.hashCode() : 0; 085 } 086 087 @Override 088 public String toString() { 089 return "SimpleMessage[message=" + message + "]"; 090 } 091 }