Class Transformer

java.lang.Object
io.fi0x.javaconsolegraph.Transformer

public class Transformer extends Object
This class contains methods, to transform arrays and lists into a single String, that is formatted to display a nice looking graph or table.
  • Method Details

    • getInstance

      public static Transformer getInstance()
      Get the Transformer-singleton and create it if it does not exist yet.
      Returns:
      The instance of the Transformer-singleton.
    • getTable

      public String getTable(String[] columnHeaders, String[][] columns)
      Get a correctly formatted String that will print out a table.
      Parameters:
      columnHeaders - The headers of each column that the table should have.
      columns - The individual entries of each column.
      Returns:
      A correctly formatted String that will create a table with the provided headers and entries.
    • getTable

      public String getTable(String[][] columns)
      Get a correctly formatted String that will print out a table.
      Parameters:
      columns - The individual columns of the table, including their headers.
      Returns:
      A correctly formatted string that will create a table with the provided headers and entries.
    • getTable

      public String getTable(ArrayList<String[]> rows)
      Get a correctly formatted String that will print out a table.
      Parameters:
      rows - The individual rows of the table, including their headers.
      Returns:
      A correctly formatted string that will create a table with the provided headers and entries.
    • setTableSettings

      public void setTableSettings(boolean centeredEntries, boolean useSeparators, int entryPadding)
      Change the behaviour of the table formatting.
      Parameters:
      centeredEntries - Weather or not entries should be centered in their column.
      useSeparators - Weather or not separators should be added between columns and rows.
      entryPadding - Weather or not entries should get extra spaces before and after the normal padding.
    • getGraphString

      public String[][] getGraphString(double[] values)
      Get a correctly formatted String that will print out a graph.
      Parameters:
      values - The individual values that get mapped on the xAxis.
      Returns:
      A correctly formatted String-Array that represents a graph. Can be used to create a table.
    • setGraphSettings

      public void setGraphSettings(String xAxis, String yAxis, double xMin, double yMin, double scaleX, double scaleY, int xValues, int yValues)
      Change the behaviour of the graph formatting.
      Parameters:
      xAxis - How the xAxis should be named.
      yAxis - How the yAxis should be named.
      xMin - What the lowest value on the xAxis is.
      yMin - What the lowestValue on the yAxis is.
      scaleX - How large the steps between individual xValues should be.
      scaleY - How large the steps between individual yValues should be.
      xValues - How many individual values should be displayed in x-direction.
      yValues - How many individual values should be displayed in y-direction.