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

im.aop.loggers.messageinterpolation.SliceToStringStrategy 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)

There is a newer version: 1.1.3
Show newest version
package im.aop.loggers.messageinterpolation;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Slice;

/**
 * {@link ToStringStrategy} implementation for {@link Slice}, using {@link IterableToStringStrategy}
 * to return a String representation of the list of element.
 *
 * @author Andy Lian
 */
public class SliceToStringStrategy implements ToStringStrategy {

  @Autowired private IterableToStringStrategy iterableToStringStrategy;

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

  @Override
  public String toString(Object object) {
    final Slice slice = (Slice) object;
    final ToStringBuilder toStringBuilder =
        new ToStringBuilder(slice, ToStringStyle.NO_CLASS_NAME_STYLE);

    if (slice.getPageable().isPaged()) {
      toStringBuilder
          .append("page", slice.getNumber())
          .append("size", slice.getSize())
          .append("sort", slice.getSort());
    }

    toStringBuilder
        .append("numberOfElements", slice.getNumberOfElements())
        .append("content", iterableToStringStrategy.toString(slice.getContent()));

    return toStringBuilder.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy