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

kz.greetgo.kafka.model.Box Maven / Gradle / Ivy

There is a newer version: 2.5.5
Show newest version
package kz.greetgo.kafka.model;

import java.util.Collection;
import java.util.stream.Stream;

import static java.util.stream.Collectors.joining;

public class Box {

  /**
   * Author of record
   */
  public String a;

  /**
   * Kafka id
   */
  public String id;

  /**
   * Body of message
   */
  public Object body;

  @Override
  public String toString() {
    return Stream.of(
                   new Object[]{"id", id},
                   new Object[]{"a", a},
                   new Object[]{"body", body}
                 )
                 .filter(e -> e[1] != null)
                 .map(e -> e[0] + "=" + e[1])
                 .collect(joining(", ", getClass().getSimpleName() + "{", "}"));
  }

  public static void validateBody(Object body) throws Throwable {

    if (body == null) {
      throw new NullPointerException(Box.class.getName() + ".body == null");
    }

    if (body instanceof KafkaValidator) {
      ((KafkaValidator) body).validateKafka();
      return;
    }

    if (body instanceof Collection) {
      //noinspection rawtypes
      for (Object object : ((Collection) body)) {
        validateIt(object);
      }
      return;
    }
  }

  public void validate() throws Throwable {
    validateBody(body);
  }

  private static void validateIt(Object object) throws Throwable {
    if (object instanceof KafkaValidator) {
      ((KafkaValidator) object).validateKafka();
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy