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 */ 017package org.apache.logging.log4j.message; 018 019/** 020 * The simplest possible implementation of Message. It just returns the String given as the constructor argument. 021 */ 022public class SimpleMessage implements Message { 023 private static final long serialVersionUID = -8398002534962715992L; 024 025 private final String message; 026 027 /** 028 * Basic constructor. 029 */ 030 public SimpleMessage() { 031 this(null); 032 } 033 034 /** 035 * Constructor that includes the message. 036 * @param message The String message. 037 */ 038 public SimpleMessage(final String message) { 039 this.message = message; 040 } 041 042 /** 043 * Returns the message. 044 * @return the message. 045 */ 046 @Override 047 public String getFormattedMessage() { 048 return message; 049 } 050 051 /** 052 * Returns the message. 053 * @return the message. 054 */ 055 @Override 056 public String getFormat() { 057 return message; 058 } 059 060 /** 061 * Returns null since there are no parameters. 062 * @return null. 063 */ 064 @Override 065 public Object[] getParameters() { 066 return null; 067 } 068 069 @Override 070 public boolean equals(final Object o) { 071 if (this == o) { 072 return true; 073 } 074 if (o == null || getClass() != o.getClass()) { 075 return false; 076 } 077 078 final SimpleMessage that = (SimpleMessage) o; 079 080 return !(message != null ? !message.equals(that.message) : that.message != null); 081 } 082 083 @Override 084 public int hashCode() { 085 return message != null ? message.hashCode() : 0; 086 } 087 088 @Override 089 public String toString() { 090 return "SimpleMessage[message=" + message + ']'; 091 } 092 093 /** 094 * Always returns null. 095 * 096 * @return null 097 */ 098 @Override 099 public Throwable getThrowable() { 100 return null; 101 } 102}