diff --git a/src/main/java/me/araopj/cscreen/components/CTable.java b/src/main/java/me/araopj/cscreen/components/CTable.java index 848c6de..e9dee21 100644 --- a/src/main/java/me/araopj/cscreen/components/CTable.java +++ b/src/main/java/me/araopj/cscreen/components/CTable.java @@ -2,12 +2,9 @@ import me.araopj.cscreen.classes.Position; import me.araopj.cscreen.classes.Utilities; - -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; import java.util.stream.IntStream; -import java.io.PrintStream; +import static java.lang.System.out; import java.util.*; /** @@ -118,16 +115,11 @@ void init() { * Displays the table on the screen. */ public void display() { - try { - generateScreen(); - PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8.name()); - Arrays.stream(screen).forEach(value -> { - IntStream.range(0, screen[0].length).forEachOrdered(j -> out.print(value[j])); - out.println(); - }); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + generateScreen(); + Arrays.stream(screen).forEach(value -> { + IntStream.range(0, screen[0].length).forEachOrdered(j -> out.print(value[j])); + out.println(); + }); } /** @@ -359,6 +351,16 @@ public void setColumnAlignment(int columnIndex, Position position) { alignments.put(columnIndex, position); } + /** + * Sets the alignment for all columns in the table. + * @param position The alignment position for all the columns. + */ + public void setColumnAlignment(Position position) { + for (int i = 0; i < this.columnHeader.length; i++) { + alignments.put(i, position); + } + } + /** * Calculates the total sum of numeric values in a specific column. * @@ -376,7 +378,7 @@ public int getTotal(int columnIndex) { * @param columnIndex The index of the column. * @return The total sum of floating-point values in the specified column. */ - public double getFloatTotal(int columnIndex) { + public double getDoubleTotal(int columnIndex) { return list2D.stream() .filter(i -> i.stream().filter(Utilities::isNumeric).isParallel()).mapToDouble(row -> columnIndex).sum(); }