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 /** 020 * The simplest possible implementation of Message. It just returns the String given as the constructor argument. 021 */ 022 public 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 public String getFormattedMessage() { 047 return message; 048 } 049 050 /** 051 * Returns the message. 052 * @return the message. 053 */ 054 public String getFormat() { 055 return message; 056 } 057 058 /** 059 * Returns null since there are no parameters. 060 * @return null. 061 */ 062 public Object[] getParameters() { 063 return null; 064 } 065 066 @Override 067 public boolean equals(final Object o) { 068 if (this == o) { 069 return true; 070 } 071 if (o == null || getClass() != o.getClass()) { 072 return false; 073 } 074 075 final SimpleMessage that = (SimpleMessage) o; 076 077 return !(message != null ? !message.equals(that.message) : that.message != null); 078 } 079 080 @Override 081 public int hashCode() { 082 return message != null ? message.hashCode() : 0; 083 } 084 085 @Override 086 public String toString() { 087 return "SimpleMessage[message=" + message + "]"; 088 } 089 090 /** 091 * Always returns null. 092 * 093 * @return null 094 */ 095 public Throwable getThrowable() { 096 return null; 097 } 098 }