All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.aop.loggers.messageinterpolation.OptionalToStringStrategy Maven / Gradle / Ivy

Go to download

A handy and configurable sets of annotation-based loggers for Spring Boot that can log every execution of a method when entering or exiting normally or abnormally, without you writing a single line of code using aspect-oriented programming (AOP)

The newest version!
package im.aop.loggers.messageinterpolation;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * {@link ToStringStrategy} implementation for {@link Optional}, using
 * {@link ObjectToStringStrategy} to return a String representation of the element.
 *
 * @author Andy Lian
 */
public class OptionalToStringStrategy implements ToStringStrategy {

  @Autowired private ObjectToStringStrategy objectToStringStrategy;

  @Override
  public boolean supports(Object object) {
    return object instanceof Optional;
  }

  @Override
  public String toString(Object object) {
    return toString((Optional) object);
  }

  private String toString(final Optional optional) {
    return optional.isEmpty() ? "null" : objectToStringStrategy.toString(optional.get());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy