Last active
June 10, 2016 11:15
-
-
Save JoolsF/1780546fc16fa921aa69e859c017959a to your computer and use it in GitHub Desktop.
Pretty printer with fields and delimiter param
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Iterates through fields and prints each one with its name and value | |
* | |
* Delimiter parameter seperates fields. Defaults to line seperator | |
*/ | |
def toStringPrettyPrint(delimiter: String = "\n"): String = { | |
val fields = this.getClass.getDeclaredFields.foldLeft(new TreeMap[String,Any]) { (acc,field) => | |
field.setAccessible(true) | |
acc + (field.getName -> field.get(this)) | |
} | |
s"${fields.mkString(delimiter)}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment