# HG changeset patch
# User František Kučera
# Date 1707059437 -3600
# Node ID 099bb96f8d8d9dfb648b5f87e39feef739100893
# Parent c4b901ff07038c151326c75e8e8d97b52aacdc5c
tabular formatter: new option 'separateBy' to print horizontal separator on each change of given column
diff -r c4b901ff0703 -r 099bb96f8d8d java/sql-dk/src/main/java/info/globalcode/sql/dk/configuration/Properties.java
--- a/java/sql-dk/src/main/java/info/globalcode/sql/dk/configuration/Properties.java Fri Sep 23 18:05:50 2022 +0200
+++ b/java/sql-dk/src/main/java/info/globalcode/sql/dk/configuration/Properties.java Sun Feb 04 16:10:37 2024 +0100
@@ -20,15 +20,16 @@
import javax.xml.bind.annotation.XmlTransient;
import static info.globalcode.sql.dk.Functions.findByName;
import java.util.Collections;
+import java.util.regex.Pattern;
/**
*
* List of configurables.
*
*
- * Can be backed by defaults – if value for given name is nof found in this instance, we will
- * look into defaults. Methods also accept defaultValue parameter – is used if property is nof found
- * even in default properties.
+ * Can be backed by defaults – if value for given name is nof found in this
+ * instance, we will look into defaults. Methods also accept defaultValue
+ * parameter – is used if property is nof found even in default properties.
@@ -49,6 +52,7 @@
@PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, defaultValue = "false", type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones")
@PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, defaultValue = "false", type = Boolean.class, description = "whether to trim the values to fit the column width")
@PropertyDeclaration(name = TabularFormatter.PROPERTY_HEADER_TYPE, defaultValue = "true", type = Boolean.class, description = "whether to print data types in column headers")
+@PropertyDeclaration(name = TabularFormatter.PROPERTY_SEPARATE_BY, defaultValue = "", type = String.class, description = "colum(s) whose change triggers separator printing")
public class TabularFormatter extends AbstractFormatter {
private static final Logger log = Logger.getLogger(TabularFormatter.class.getName());
@@ -58,6 +62,7 @@
public static final String PROPERTY_ASCII = "ascii";
public static final String PROPERTY_TRIM = "trim";
public static final String PROPERTY_HEADER_TYPE = "headerTypes";
+ public static final String PROPERTY_SEPARATE_BY = "separateBy";
protected ColorfulPrintWriter out;
private boolean firstResult = true;
private int[] columnWidth;
@@ -73,6 +78,27 @@
* Print data type of each column in the header
*/
private final boolean printHeaderTypes;
+ /**
+ * When values of columns (names specified by this pattern) changes
+ * between two consecutive rows, horizontal separator is printed.
+ */
+ private final Pattern separateBy;
+ /**
+ * Indexes of columns that matches {@linkplain #separateBy}
+ */
+ private final List separators = new ArrayList<>();
+ /**
+ * Internal counter for buffered data.
+ */
+ private int currentColumnsCount = 0;
+ /**
+ * Buffered data to be compared and printed later.
+ */
+ private final List