View Javadoc

    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      @Override
    47      public String getFormattedMessage() {
    48          return message;
    49      }
    50
    51      /**
    52       * Returns the message.
    53       * @return the message.
    54       */
    55      @Override
    56      public String getFormat() {
    57          return message;
    58      }
    59
    60      /**
    61       * Returns null since there are no parameters.
    62       * @return null.
    63       */
    64      @Override
    65      public Object[] getParameters() {
    66          return null;
    67      }
    68
    69      @Override
    70      public boolean equals(final Object o) {
    71          if (this == o) {
    72              return true;
    73          }
    74          if (o == null || getClass() != o.getClass()) {
    75              return false;
    76          }
    77
    78          final SimpleMessage that = (SimpleMessage) o;
    79
    80          return !(message != null ? !message.equals(that.message) : that.message != null);
    81      }
    82
    83      @Override
    84      public int hashCode() {
    85          return message != null ? message.hashCode() : 0;
    86      }
    87
    88      @Override
    89      public String toString() {
    90          return "SimpleMessage[message=" + message + ']';
    91      }
    92
    93      /**
    94       * Always returns null.
    95       *
    96       * @return null
    97       */
    98      @Override
    99      public Throwable getThrowable() {
    100         return null;
    101     }
    102 }