Tables
- Create an object which represents a row:
@HeaderOrder({"First Name", "Age"}) // specifies the sorting of the headers
// this is optional, but if you don't include this,
// the order of the columns is "random"
public static class Person {
@Column("First Name") // must be same as in HeaderOrder
public final String first;
@Column("Age") // must be same as in HeaderOrder
public final int age;
}
- Create table
final Person[] people = new Person[5];
RandomFactory.fill(people); // generate random person objects
// create table and fill with array
final Table table = TableBuilder.from(people, Person.class)
.color(true)
.style(TableStyle.ROUND);
System.out.println(table);
Output (note: may be broken on some browsers)
╭────────────┬─────╮
│ First Name │ Age │
├────────────┼─────┤
│ Margaret │ 42 │
│ Michael │ 79 │
│ Anna │ 43 │
│ Cynthia │ 50 │
│ Margaret │ 82 │
╰────────────┴─────╯
Without Annotations
final Person[] people = new Person[5];
RandomFactory.fill(people);
final Table x = TableBuilder.builder("Name", "Age")
.loads(Arrays.asList(people), person -> TableBuilder.array(
person.first,
String.valueOf(person.age))
)
.build();
Example
Output (note: may be broken on some browsers)
╭─────────────┬────────┬─────────┬───────┬───────┬───────╮
│ Name │ Symbol │ Ordinal │ Shell │ Phase │ Group │
├─────────────┼────────┼─────────┼───────┼───────┼───────┤
│ Wasserstoff │ H │ 1 │ K │ 3 │ true │
│ Helium │ He │ 2 │ K │ 3 │ true │
│ Natrium │ Na │ 11 │ M │ 1 │ true │
│ Eisen │ Fe │ 26 │ N │ 1 │ false │
│ Germanium │ Ge │ 32 │ N │ 1 │ false │
│ Brom │ Br │ 35 │ N │ 2 │ true │
│ Tellur │ Te │ 52 │ O │ 1 │ true │
│ Gold │ Au │ 79 │ P │ 1 │ false │
╰─────────────┴────────┴─────────┴───────┴───────┴───────╯
Last update:
2022-03-15