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

org.infinispan.cli.printers.PrettyPrinter Maven / Gradle / Ivy

package org.infinispan.cli.printers;

import java.io.Closeable;
import java.util.Iterator;
import java.util.Map;

import org.aesh.command.shell.Shell;

/**
 * @since 14.0
 **/
public interface PrettyPrinter extends Closeable {

   enum PrettyPrintMode {
      TABLE,
      JSON,
      CSV
   }

   static PrettyPrinter forMode(PrettyPrintMode mode, Shell shell, PrettyRowPrinter rowPrinter) {
      switch (mode) {
         case TABLE:
            return new TablePrettyPrinter(shell, rowPrinter);
         case JSON:
            return new JsonPrettyPrinter(shell);
         case CSV:
            return new CsvPrettyPrinter(shell, rowPrinter);
         default:
            throw new IllegalArgumentException(mode.name());
      }
   }

   void printItem(Map item);

   default void print(Iterator it) {
      it.forEachRemaining(i -> printItem(Map.of("", i)));
   }

   default void print(Iterable> it) {
      it.forEach(this::printItem);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy