├── .vs
└── slnx.sqlite
├── .gradle
├── buildOutputCleanup
│ ├── built.bin
│ ├── cache.properties.lock
│ └── cache.properties
├── 3.5
│ ├── file-changes
│ │ └── last-build.bin
│ └── taskHistory
│ │ ├── fileHashes.bin
│ │ ├── taskHistory.bin
│ │ ├── taskHistory.lock
│ │ └── fileSnapshots.bin
└── 4.0.2
│ ├── fileChanges
│ └── last-build.bin
│ ├── fileHashes
│ ├── fileHashes.bin
│ └── fileHashes.lock
│ └── taskHistory
│ ├── taskHistory.bin
│ ├── taskHistory.lock
│ └── fileSnapshots.bin
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── bin
└── io
│ └── github
│ └── woodenbell
│ └── pprint
│ ├── Util.class
│ ├── ObjectPrint.class
│ ├── SimplePrint.class
│ ├── CollectionPrint.class
│ ├── PrettyPrintable.class
│ ├── Util$TableFormat.class
│ └── test
│ ├── ObjectTest$1.class
│ ├── ObjectTest$2.class
│ ├── ObjectTest$3.class
│ ├── ObjectTest.class
│ ├── PPTestSuite.class
│ ├── SimpleTest.class
│ ├── CollectionTest.class
│ ├── ObjectTest$Person.class
│ ├── ObjectTest$DataStruct.class
│ └── ObjectTest$DataStructType.class
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.buildship.core.prefs
├── src
├── test
│ └── java
│ │ └── io
│ │ └── github
│ │ └── woodenbell
│ │ └── pprint
│ │ └── test
│ │ ├── PPTestSuite.java
│ │ ├── SimpleTest.java
│ │ ├── CollectionTest.java
│ │ └── ObjectTest.java
└── main
│ └── java
│ └── io
│ └── github
│ └── woodenbell
│ └── pprint
│ ├── PrettyPrintable.java
│ ├── SimplePrint.java
│ ├── Util.java
│ ├── ObjectPrint.java
│ └── CollectionPrint.java
├── .gitattributes
├── .classpath
├── settings.gradle
├── .project
├── .gitignore
├── gradlew.bat
├── gradlew
├── LICENSE
└── README.md
/.vs/slnx.sqlite:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/built.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/3.5/file-changes/last-build.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/4.0.2/fileChanges/last-build.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/cache.properties.lock:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/cache.properties:
--------------------------------------------------------------------------------
1 | #Fri Sep 22 19:11:17 BRT 2017
2 | gradle.version=3.5
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gradle/3.5/taskHistory/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/3.5/taskHistory/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/3.5/taskHistory/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/3.5/taskHistory/taskHistory.bin
--------------------------------------------------------------------------------
/.gradle/3.5/taskHistory/taskHistory.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/3.5/taskHistory/taskHistory.lock
--------------------------------------------------------------------------------
/.gradle/4.0.2/fileHashes/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/4.0.2/fileHashes/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/4.0.2/fileHashes/fileHashes.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/4.0.2/fileHashes/fileHashes.lock
--------------------------------------------------------------------------------
/.gradle/3.5/taskHistory/fileSnapshots.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/3.5/taskHistory/fileSnapshots.bin
--------------------------------------------------------------------------------
/.gradle/4.0.2/taskHistory/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/4.0.2/taskHistory/taskHistory.bin
--------------------------------------------------------------------------------
/.gradle/4.0.2/taskHistory/taskHistory.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/4.0.2/taskHistory/taskHistory.lock
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/Util.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/Util.class
--------------------------------------------------------------------------------
/.gradle/4.0.2/taskHistory/fileSnapshots.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/.gradle/4.0.2/taskHistory/fileSnapshots.bin
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java/io/github/woodenbell/pprint/Util.java=UTF-8
3 |
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/ObjectPrint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/ObjectPrint.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/SimplePrint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/SimplePrint.class
--------------------------------------------------------------------------------
/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
2 | connection.project.dir=
3 | eclipse.preferences.version=1
4 |
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/CollectionPrint.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/CollectionPrint.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/PrettyPrintable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/PrettyPrintable.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/Util$TableFormat.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/Util$TableFormat.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest$1.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest$2.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest$3.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/PPTestSuite.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/PPTestSuite.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/SimpleTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/SimpleTest.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/CollectionTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/CollectionTest.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest$Person.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest$Person.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest$DataStruct.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest$DataStruct.class
--------------------------------------------------------------------------------
/bin/io/github/woodenbell/pprint/test/ObjectTest$DataStructType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/woodenbell/PrettyPrint/HEAD/bin/io/github/woodenbell/pprint/test/ObjectTest$DataStructType.class
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 11 15:15:32 BRT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
7 |
--------------------------------------------------------------------------------
/src/test/java/io/github/woodenbell/pprint/test/PPTestSuite.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint.test;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 |
6 | @RunWith(Suite.class)
7 |
8 | @Suite.SuiteClasses({ ObjectTest.class, CollectionTest.class, SimpleTest.class})
9 |
10 | public class PPTestSuite {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This settings file was generated by the Gradle 'init' task.
3 | *
4 | * The settings file is used to specify which projects to include in your build.
5 | * In a single project build this file can be empty or even removed.
6 | *
7 | * Detailed information about configuring a multi-project build in Gradle can be found
8 | * in the user guide at https://docs.gradle.org/3.5/userguide/multi_project_builds.html
9 | */
10 |
11 | /*
12 | // To declare projects as part of a multi-project build use the 'include' method
13 | include 'shared'
14 | include 'api'
15 | include 'services:webservice'
16 | */
17 |
18 | rootProject.name = 'PrettyPrint'
19 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | PrettyPrint
4 | Project PrettyPrint created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 |
--------------------------------------------------------------------------------
/src/main/java/io/github/woodenbell/pprint/PrettyPrintable.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint;
2 |
3 | /**
4 | * Interface to be implemented by objects that support pprint.
5 | *
6 | * @author Gabriel C.
7 | *
8 | * @see io.github.woodenbell.pprint.ObjectPrint
9 | */
10 |
11 | public interface PrettyPrintable {
12 |
13 | /**
14 | * Used to tell if the object supports recursive printing.
15 | *
16 | * @return If the object supports recursive printing.
17 | * @see io.github.woodenbell.pprint.ObjectPrint#pprintRecursive(PrettyPrintable)
18 | */
19 |
20 | public boolean ppIsRecursive();
21 |
22 | /**
23 | * Used to tell if the object uses keys or number indexes when enumerated is
24 | * used.
25 | *
26 | * @return If the object uses keys when pretty printing.
27 | */
28 |
29 | public boolean ppHasKeys();
30 |
31 | /**
32 | * Method to return the object printing keys.
33 | *
34 | * @return The keys of object's elements.
35 | */
36 |
37 | public Object[] ppGetKeys();
38 |
39 | /**
40 | * Method to return the object printing values.
41 | *
42 | * @return The keys of object's values.
43 | */
44 |
45 | public Object[] ppGetValues();
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/io/github/woodenbell/pprint/SimplePrint.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 | import java.util.Queue;
6 | import java.util.Set;
7 |
8 | /**
9 | * Contains pprint methods that print in a simple format, similar to Python
10 | * representation of data structures.
11 | *
12 | * @author Gabriel C.
13 | * @since 1.1
14 | */
15 |
16 | public class SimplePrint {
17 |
18 | /**
19 | * Prints an object array in a simple format.
20 | *
21 | * @param p
22 | * The object array.
23 | */
24 |
25 | public static void pprint(Object[] p) {
26 |
27 | if (p == null)
28 | return;
29 |
30 | System.out.println("[" + Util.toListWithCommas(p) + "]");
31 | }
32 |
33 | /**
34 | * Prints a List collection in a simple format.
35 | *
36 | * @param p
37 | * The List object.
38 | *
39 | * @see java.util.List
40 | */
41 |
42 | public static void pprint(List> p) {
43 |
44 | if (p == null)
45 | return;
46 |
47 | System.out.println("[" + Util.toListWithCommas(p.toArray()) + "]");
48 |
49 | }
50 |
51 | /**
52 | * Prints a Set collection in a simple format.
53 | *
54 | * @param p
55 | * The Set object.
56 | * @see java.util.Set
57 | */
58 |
59 | public static void pprint(Set> p) {
60 |
61 | if (p == null)
62 | return;
63 |
64 | System.out.println("{" + Util.toListWithCommas(p.toArray()) + "}");
65 | }
66 |
67 | /**
68 | * Prints a Queue collection in a simple format.
69 | *
70 | * @param p
71 | * The Queue object.
72 | * @see java.util.Queue
73 | */
74 |
75 | public static void pprint(Queue> p) {
76 |
77 | if (p == null)
78 | return;
79 |
80 | System.out.println("[" + Util.toListWithCommas(p.toArray()) + "]");
81 | }
82 |
83 | /**
84 | * Prints a Map collection in a simple format.
85 | *
86 | * @param p
87 | * The map object.
88 | * @see java.util.Map
89 | */
90 |
91 | public static void pprint(Map, ?> p) {
92 |
93 | if (p == null)
94 | return;
95 |
96 | System.out.println("{\n" + Util.toKeyValListWithCommas(p.keySet().toArray(), p.values().toArray()) + "\n}");
97 |
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/src/test/java/io/github/woodenbell/pprint/test/SimpleTest.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint.test;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.HashSet;
6 |
7 | import org.junit.Test;
8 |
9 | import io.github.woodenbell.pprint.SimplePrint;
10 |
11 |
12 | public class SimpleTest {
13 |
14 | @Test
15 | public void arrayTest() {
16 |
17 | System.out.println("- Testing object array simple pprint");
18 | System.out.println();
19 |
20 | Object[] numbers = new Integer[] {2, 5, 6, 9};
21 | SimplePrint.pprint(numbers);
22 |
23 | System.out.println();
24 | System.out.println();
25 |
26 | Object[] names = new String[] {"wow", "much", null, "array"};
27 | SimplePrint.pprint(names);
28 |
29 | System.out.println();
30 | System.out.println();
31 | }
32 |
33 | @Test
34 | public void listTest() {
35 |
36 | System.out.println("- Testing List simple pprint");
37 | System.out.println();
38 |
39 | ArrayList words = new ArrayList<>();
40 | words.add("world");
41 | words.add("cup");
42 | words.add("head");
43 |
44 | SimplePrint.pprint(words);
45 |
46 | System.out.println();
47 | System.out.println();
48 |
49 | ArrayList money = new ArrayList<>();
50 | money.add(37.8);
51 | money.add(9.43);
52 | money.add(null);
53 | money.add(6.0);
54 |
55 | SimplePrint.pprint(money);
56 |
57 | System.out.println();
58 | System.out.println();
59 | }
60 |
61 |
62 | @Test
63 | public void setTest() {
64 |
65 | System.out.println("- Testing Set simple pprint");
66 | System.out.println();
67 |
68 | HashSet words = new HashSet<>();
69 | words.add("really");
70 | words.add("more");
71 | words.add("words");
72 |
73 | SimplePrint.pprint(words);
74 |
75 | System.out.println();
76 | System.out.println();
77 |
78 | HashSet money = new HashSet<>();
79 | money.add(2.8);
80 | money.add(0.0);
81 | money.add(null);
82 | money.add(3.0);
83 |
84 | SimplePrint.pprint(money);
85 |
86 | System.out.println();
87 | System.out.println();
88 |
89 | }
90 |
91 | @Test
92 | public void mapTest() {
93 |
94 | System.out.println("- Testing Map simple pprint");
95 | System.out.println();
96 |
97 | HashMap ages = new HashMap<>();
98 | ages.put("John", 31);
99 | ages.put(null, 0);
100 | ages.put("James", 22);
101 | ages.put("Unknown", null);
102 | ages.put(null, null);
103 | ages.put("Pyro", 20);
104 |
105 | SimplePrint.pprint(ages);
106 |
107 | System.out.println();
108 | System.out.println();
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/io/github/woodenbell/pprint/Util.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint;
2 |
3 | /**
4 | * Utility class for the package.
5 | *
6 | * @author Gabriel C.
7 | */
8 |
9 | public class Util {
10 |
11 | /**
12 | * Enumeration representing table printing formats.
13 | *
14 | * @author WoodenBell
15 | */
16 |
17 | public static enum TableFormat {
18 |
19 | /**
20 | * UNDERSCORE TableFormat Top/Bottom border character: _ Right/Left border and
21 | * division character: |
22 | */
23 |
24 | UNDERSCORE('_', '|'),
25 |
26 | /**
27 | * HYPHEN TableFormat Top/Bottom border character: - Right/Left border and
28 | * division character: |
29 | */
30 |
31 | HYPHEN('-', '|'),
32 |
33 | /**
34 | * EQUALS TableFormat Top/Bottom border character: = Right/Left border and
35 | * division character: |
36 | */
37 |
38 | EQUALS('=', '|');
39 |
40 | char border, division;
41 |
42 | /**
43 | * Creates a table format with given border and division.
44 | *
45 | * @param border
46 | * The character to be used as top and bottom border.
47 | * @param division
48 | * The character to be used as division to the elements.
49 | */
50 |
51 | TableFormat(char border, char division) {
52 | this.border = border;
53 | this.division = division;
54 | }
55 | }
56 |
57 | /**
58 | * Generates padding for table printing.
59 | *
60 | * @param c
61 | * The character used in padding.
62 | * @param times
63 | * The padding size, or the number of times the character will be
64 | * multiplied.
65 | * @return A string containing the padding made with the character.
66 | */
67 |
68 | protected static String makePadding(char c, int times) {
69 | StringBuilder sb = new StringBuilder();
70 | for (int i = 1; i <= times; i++)
71 | sb.append(c);
72 | return sb.toString();
73 | }
74 |
75 | /**
76 | * Creates a comma separated list.
77 | * @param l The array that will be used to create the list string.
78 | * @return The list string.
79 | * @since 1.1
80 | */
81 |
82 | protected static String toListWithCommas(Object[] l) {
83 |
84 | StringBuilder sb = new StringBuilder();
85 |
86 | for (Object o : l) {
87 |
88 | if (o == null) {
89 | sb.append("null, ");
90 | } else if(o instanceof String) {
91 | sb.append("\"" + o.toString() + "\", ");
92 | } else {
93 | sb.append(o.toString() + ", ");
94 | }
95 |
96 | }
97 |
98 | return sb.substring(0, sb.length() - 2);
99 |
100 | }
101 |
102 | /**
103 | * Creates a key-value pair list represented in string.
104 | *
105 | * @param ks
106 | * The key array that will be used to create the key-value list.
107 | * @param vs
108 | * The value array that will be used to create the key-value list.
109 | * @return The string key-value pair list, separated by newline characters.
110 | * @since 1.1
111 | */
112 |
113 | protected static String toKeyValListWithCommas(Object[] ks, Object[] vs) {
114 |
115 | StringBuilder sb = new StringBuilder();
116 |
117 | for (int i = 0; i < ks.length; i++) {
118 |
119 | if (ks[i] == null) {
120 | sb.append("null: ");
121 | } else if (ks[i] instanceof String) {
122 | sb.append("\"" + ks[i].toString() + "\": ");
123 | } else {
124 | sb.append(ks[i].toString() + ": ");
125 | }
126 |
127 | if (vs[i] == null) {
128 | sb.append("null,\n");
129 | } else if (vs[i] instanceof String) {
130 | sb.append("\"" + vs[i].toString() + "\",\n");
131 | } else {
132 | sb.append(vs[i].toString() + ",\n");
133 | }
134 |
135 | }
136 |
137 | return sb.substring(0, sb.length() - 2);
138 |
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/test/java/io/github/woodenbell/pprint/test/CollectionTest.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint.test;
2 |
3 | import org.junit.Test;
4 |
5 | import io.github.woodenbell.pprint.CollectionPrint;
6 | import io.github.woodenbell.pprint.Util;
7 |
8 | import java.util.ArrayDeque;
9 | import java.util.ArrayList;
10 | import java.util.HashMap;
11 | import java.util.HashSet;
12 |
13 | public class CollectionTest {
14 |
15 | @Test
16 | public void ListTest() {
17 |
18 | System.out.println("- Testing List pprint");
19 | System.out.println();
20 |
21 | ArrayList people = new ArrayList<>();
22 | people.add("Sherlock Holmes, 37 years old, lives at 221B baker Street");
23 | people.add("Me, 16 years old, lives in the middle of nothing");
24 | people.add("Someone else, ? years old");
25 | people.add("How many people are left?");
26 | people.add("People filler #1");
27 | people.add("People filler #2");
28 | people.add("John Smith");
29 | people.add("John Smith II");
30 | people.add("John Smith III");
31 | people.add("And, again, John Smith IV");
32 |
33 | CollectionPrint.pprint(people);
34 |
35 | System.out.println();
36 | System.out.println();
37 |
38 | CollectionPrint.pprint(people, true);
39 |
40 | System.out.println();
41 | System.out.println();
42 |
43 | CollectionPrint.pprint(people, true, true, Util.TableFormat.EQUALS);
44 | System.out.println();
45 | System.out.println();
46 |
47 | }
48 |
49 | @Test
50 | public void MapTest() {
51 |
52 | System.out.println("- Testing Map pprint");
53 | System.out.println();
54 |
55 | HashMap balance = new HashMap<>();
56 |
57 | balance.put("John Smith", 345.66);
58 | balance.put("Aaron Daniels", 120.40);
59 | balance.put("Paul Klein", 12.0);
60 | balance.put("Karl Smith", -35.90);
61 | balance.put("Catherine Durant", 200.00);
62 | balance.put("Klein Smith", 145.66);
63 |
64 | CollectionPrint.pprint(balance);
65 |
66 | System.out.println();
67 | System.out.println();
68 |
69 | CollectionPrint.pprint(balance, true);
70 |
71 | System.out.println();
72 | System.out.println();
73 |
74 | CollectionPrint.pprint(balance, true, true, Util.TableFormat.UNDERSCORE);
75 |
76 | System.out.println();
77 | System.out.println();
78 | }
79 |
80 | @Test
81 | public void SetTest() {
82 |
83 | System.out.println("- Testing Set pprint");
84 | System.out.println();
85 |
86 | HashSet firstPrimes = new HashSet<>();
87 |
88 | firstPrimes.add(1);
89 | firstPrimes.add(2);
90 | firstPrimes.add(3);
91 | firstPrimes.add(5);
92 | firstPrimes.add(7);
93 | firstPrimes.add(11);
94 | firstPrimes.add(13);
95 | firstPrimes.add(17);
96 | firstPrimes.add(19);
97 | firstPrimes.add(23);
98 |
99 | CollectionPrint.pprint(firstPrimes);
100 |
101 | System.out.println();
102 | System.out.println();
103 |
104 | CollectionPrint.pprint(firstPrimes, true);
105 |
106 | System.out.println();
107 | System.out.println();
108 |
109 | CollectionPrint.pprint(firstPrimes, true, true, Util.TableFormat.HYPHEN);
110 |
111 | System.out.println();
112 | System.out.println();
113 | }
114 |
115 | @Test
116 | public void QueueTest() {
117 |
118 | System.out.println("- Testing Queue pprint");
119 | System.out.println();
120 |
121 | ArrayDeque firstNums = new ArrayDeque<>();
122 |
123 | firstNums.add(2);
124 | firstNums.add(3);
125 | firstNums.add(4);
126 | firstNums.add(5);
127 | firstNums.add(6);
128 | firstNums.add(7);
129 | firstNums.add(8);
130 | firstNums.add(9);
131 |
132 | firstNums.addFirst(1);
133 | firstNums.addLast(10);
134 |
135 | CollectionPrint.pprint(firstNums);
136 |
137 | System.out.println();
138 | System.out.println();
139 |
140 | CollectionPrint.pprint(firstNums, true);
141 |
142 | System.out.println();
143 | System.out.println();
144 |
145 | CollectionPrint.pprint(firstNums, true, true);
146 |
147 | System.out.println();
148 | System.out.println();
149 | }
150 |
151 | @Test
152 | public void errorTest() {
153 |
154 | System.out.println("- Testing pprint on collections with null elements or values");
155 | System.out.println();
156 |
157 | HashMap hm1 = new HashMap<>();
158 | HashMap hm2 = new HashMap<>();
159 | ArrayList al = new ArrayList<>();
160 |
161 | HashSet hs = new HashSet<>();
162 |
163 | hm1.put("wow", null);
164 | hm1.put("much null", null);
165 | hm1.put("not null", "3");
166 |
167 | hm2.put(null, "much null");
168 | hm2.put("not null", "3");
169 |
170 | al.add(null);
171 | al.add("wow");
172 |
173 | hs.add("hey");
174 | hs.add(null);
175 |
176 | CollectionPrint.pprint(hm1, true);
177 | CollectionPrint.pprint(hm2, true);
178 | CollectionPrint.pprint(hm2);
179 |
180 | CollectionPrint.pprint(al);
181 |
182 | CollectionPrint.pprint(hs);
183 |
184 | }
185 |
186 | }
187 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/src/test/java/io/github/woodenbell/pprint/test/ObjectTest.java:
--------------------------------------------------------------------------------
1 | package io.github.woodenbell.pprint.test;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.junit.Test;
7 |
8 | import io.github.woodenbell.pprint.ObjectPrint;
9 | import io.github.woodenbell.pprint.PrettyPrintable;
10 | import io.github.woodenbell.pprint.Util;
11 |
12 | public class ObjectTest {
13 |
14 | private static class Person implements PrettyPrintable {
15 |
16 | String name;
17 | int age;
18 | String address;
19 |
20 | Person(String name, int age, String address) {
21 |
22 | this.name = name;
23 | this.age = age;
24 | this.address = address;
25 | }
26 |
27 | public boolean ppIsRecursive() {
28 | return false;
29 | }
30 |
31 | public boolean ppHasKeys() {
32 | return true;
33 | }
34 |
35 | public Object[] ppGetKeys() {
36 | return new String[] { "Name", "Age", "Address" };
37 | }
38 |
39 | public Object[] ppGetValues() {
40 | return new Object[] { name, age, address };
41 | }
42 |
43 | }
44 |
45 | @Test
46 | public void PPObjectTest() {
47 |
48 | System.out.println("- Testing custom object pprint");
49 | System.out.println();
50 |
51 | Person sherlock = new Person("Sherlock Holmes", 37, "Baker Street 221B");
52 |
53 | ObjectPrint.pprint(sherlock);
54 |
55 | System.out.println();
56 | System.out.println();
57 |
58 | ObjectPrint.pprint(sherlock, true);
59 |
60 | System.out.println();
61 | System.out.println();
62 |
63 | ObjectPrint.pprint(sherlock, true, true);
64 |
65 | System.out.println();
66 | System.out.println();
67 |
68 | }
69 |
70 | @Test
71 | public void ObjectArrayTest() {
72 |
73 | System.out.println("- Testing object array pprint");
74 | System.out.println();
75 |
76 | Object[] invited = new String[] { "Me", "You", "Everyone else" };
77 |
78 | ObjectPrint.pprint(invited);
79 |
80 | System.out.println();
81 | System.out.println();
82 |
83 | ObjectPrint.pprint(invited, true);
84 |
85 | System.out.println();
86 | System.out.println();
87 |
88 | ObjectPrint.pprint(invited, true, true, Util.TableFormat.EQUALS);
89 |
90 | System.out.println();
91 | System.out.println();
92 | }
93 |
94 | private static enum DataStructType {
95 |
96 | INTEGER, STRING, DATASTRUCT;
97 |
98 | }
99 |
100 | private static class DataStruct implements PrettyPrintable {
101 |
102 | List