MCPcopy Index your code
hub / github.com/JakeWharton/flip-tables

github.com/JakeWharton/flip-tables @1.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.1.1 ↗ · + Follow
177 symbols 249 edges 9 files 6 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Flip Tables

Because pretty-printing text tables in Java should be easy.

(╯°□°)╯︵ ┻━┻

Development on this project has basically stopped. You can find a more comprehensive and actively-developed text table library at https://github.com/JakeWharton/picnic.

Usage

A FlipTable requires headers and data in string form:

String[] headers = { "Test", "Header" };
String[][] data = {
    { "Foo", "Bar" },
    { "Kit", "Kat" },
};
System.out.println(FlipTable.of(headers, data));
╔══════╤════════╗
║ Test │ Header ║
╠══════╪════════╣
║ Foo  │ Bar    ║
╟──────┼────────╢
║ Kit  │ Kat    ║
╚══════╧════════╝

They can be empty:

String[] headers = { "Test", "Header" };
String[][] data = {};
System.out.println(FlipTable.of(headers, data));
╔══════╤════════╗
║ Test │ Header ║
╠══════╧════════╣
║ (empty)       ║
╚═══════════════╝

Newlines are supported:

String[] headers = { "One Two\nThree", "Four" };
String[][] data = { { "Five", "Six\nSeven Eight" } };
System.out.println(FlipTable.of(headers, data));
╔═════════╤═════════════╗
║ One Two │ Four        ║
║ Three   │             ║
╠═════════╪═════════════╣
║ Five    │ Six         ║
║         │ Seven Eight ║
╚═════════╧═════════════╝

Which means tables can be nested:

String[] innerHeaders = { "One", "Two" };
String[][] innerData = { { "1", "2" } };
String inner = FlipTable.of(innerHeaders, innerData);
String[] headers = { "Left", "Right" };
String[][] data = { { inner, inner } };
System.out.println(FlipTable.of(headers, data));
╔═══════════════╤═══════════════╗
║ Left          │ Right         ║
╠═══════════════╪═══════════════╣
║ ╔═════╤═════╗ │ ╔═════╤═════╗ ║
║ ║ One │ Two ║ │ ║ One │ Two ║ ║
║ ╠═════╪═════╣ │ ╠═════╪═════╣ ║
║ ║ 1   │ 2   ║ │ ║ 1   │ 2   ║ ║
║ ╚═════╧═════╝ │ ╚═════╧═════╝ ║
╚═══════════════╧═══════════════╝

Helper methods convert from types like lists:

List<Person> people = Arrays.asList(new Person("Foo", "Bar"), new Person("Kit", "Kat"));
System.out.println(FlipTableConverters.fromIterable(people, Person.class));
╔═══════════╤══════════╗
║ FirstName │ LastName ║
╠═══════════╪══════════╣
║ Foo       │ Bar      ║
╟───────────┼──────────╢
║ Kit       │ Kat      ║
╚═══════════╧══════════╝

Or a database result:

ResultSet resultSet = statement.executeQuery("SELECT first_name, last_name FROM users");
System.out.println(FlipTableConverters.fromResultSet(resultSet));
╔════════════╤═══════════╗
║ first_name │ last_name ║
╠════════════╪═══════════╣
║ Jake       │ Wharton   ║
╟────────────┼───────────╢
║ Edward     │ Snowden   ║
╚════════════╧═══════════╝

Arbitrary objects are also supported:

String[] headers = { "First Name", "Last Name", "Age", "Type" };
Object[][] data = {
    { "Big", "Bird", 16, PersonType.COSTUME },
    { "Joe", "Smith", 42, PersonType.HUMAN },
    { "Oscar", "Grouchant", 8, PersonType.PUPPET }
};
System.out.println(FlipTableConverters.fromObjects(headers, data));
╔════════════╤═══════════╤═════╤═════════╗
║ First Name │ Last Name │ Age │ Type    ║
╠════════════╪═══════════╪═════╪═════════╣
║ Big        │ Bird      │ 16  │ COSTUME ║
╟────────────┼───────────┼─────┼─────────╢
║ Joe        │ Smith     │ 42  │ HUMAN   ║
╟────────────┼───────────┼─────┼─────────╢
║ Oscar      │ Grouchant │ 8   │ PUPPET  ║
╚════════════╧═══════════╧═════╧═════════╝

Download

Download the latest jar or reference on Maven central as com.jakewharton.fliptables:fliptables:1.1.1.

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2014 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Core symbols most depended-on inside this repo

of
called by 23
src/main/java/com/jakewharton/fliptables/FlipTable.java
printDivider
called by 5
src/main/java/com/jakewharton/fliptables/FlipTable.java
pad
called by 3
src/main/java/com/jakewharton/fliptables/FlipTable.java
printData
called by 2
src/main/java/com/jakewharton/fliptables/FlipTable.java
fromObjects
called by 2
src/main/java/com/jakewharton/fliptables/FlipTableConverters.java
fromIterable
called by 2
src/main/java/com/jakewharton/fliptables/FlipTableConverters.java
fromResultSet
called by 2
src/main/java/com/jakewharton/fliptables/FlipTableConverters.java
toString
called by 1
src/main/java/com/jakewharton/fliptables/FlipTable.java

Shape

Method 167
Class 9
Enum 1

Languages

Java100%

Modules by API surface

src/test/java/com/jakewharton/fliptables/util/AbstractResultSet.java97 symbols
src/test/java/com/jakewharton/fliptables/util/AbstractResultSetMetaData.java24 symbols
src/test/java/com/jakewharton/fliptables/FlipTableTest.java20 symbols
src/test/java/com/jakewharton/fliptables/util/FakeResultSet.java9 symbols
src/test/java/com/jakewharton/fliptables/FlipTableConvertersTest.java7 symbols
src/main/java/com/jakewharton/fliptables/FlipTable.java7 symbols
src/test/java/com/jakewharton/fliptables/util/Person.java6 symbols
src/main/java/com/jakewharton/fliptables/FlipTableConverters.java6 symbols
src/test/java/com/jakewharton/fliptables/util/PersonType.java1 symbols

For agents

$ claude mcp add flip-tables \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact