-
- All Implemented Interfaces:
public class StringUtils
Utilities for producing pretty-print indented strings that could nearly compile to Kotlin or Java (some abbreviations for brevity).
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringUtils
INSTANCE
-
Method Summary
Modifier and Type Method Description final static String
spaces(Integer len)
Efficiently returns a String with the given number of spaces. final static String
iterableToStr(Integer indent, String collName, Iterable<Object> ls, Boolean entriesAsSymbols, Boolean singleLine)
Pretty-prints any iterable with the given indent and class/field name final static String
iterableToStr(Integer indent, String collName, Iterable<Object> ls, Boolean entriesAsSymbols)
Pretty-prints any iterable with the given indent and class/field name final static String
iterableToStr(Integer indent, String collName, Iterable<Object> ls)
Pretty-prints any iterable with the given indent and class/field name final static String
listToStr(Integer indent, Iterable<Object> ls, Boolean singleLine)
Pretty-prints any Iterable with the given indent as a list/array. final static String
listToStr(Integer indent, Iterable<Object> ls)
Pretty-prints any Iterable with the given indent as a list/array. final static String
oneFieldPerLine(Integer indent, String collName, Iterable<Entry.Map<String, Object>> fields)
Use this to pretty-print a class with one field per line. final String
oneFieldPerLineK(Integer indent, String collName, Iterable<Pair<String, Object>> fields)
Kotlin wrapper because Pair does not implement Map.Entry and Pair is not accessible in Java. final static String
fieldsOnOneLine(Integer indent, String collName, Iterable<Entry.Map<String, Object>> fields)
Use this to pretty-print a class with all fields on one line. final String
fieldsOnOneLineK(Integer indent, String collName, Iterable<Pair<String, Object>> fields)
Kotlin wrapper because Pair does not implement Map.Entry and Pair is not accessible in Java. final static String
indent(Integer indent, Object item, Boolean entriesAsSymbols, Boolean singleLine)
Takes a shot at pretty-printing anything you throw at it. final static String
indent(Integer indent, Object item, Boolean entriesAsSymbols)
Takes a shot at pretty-printing anything you throw at it. final static String
indent(Integer indent, Object item)
Takes a shot at pretty-printing anything you throw at it. final static String
stringify(String s)
Surrounds strings with double quotes and escapes any internal double-quotes final static String
charToStr(Character c)
Surround chars with single quotes and escape any internal single- or double-quotes final static String
floatToStr(Float f)
Prints float so it looks like a Float and not a Double. final static String
bashSingleQuote(String s)
Single-quotes a string for Bash, escaping only single quotes. -
-
Method Detail
-
spaces
final static String spaces(Integer len)
Efficiently returns a String with the given number of spaces.
- Parameters:
len
- the number of spaces
-
iterableToStr
@JvmOverloads() final static String iterableToStr(Integer indent, String collName, Iterable<Object> ls, Boolean entriesAsSymbols, Boolean singleLine)
Pretty-prints any iterable with the given indent and class/field name
- Parameters:
entriesAsSymbols
- If true, treat Map.Entry keys of type String as symbols (don't quote them).singleLine
- If true, constrain all sub-collections to a single line.
-
iterableToStr
@JvmOverloads() final static String iterableToStr(Integer indent, String collName, Iterable<Object> ls, Boolean entriesAsSymbols)
Pretty-prints any iterable with the given indent and class/field name
- Parameters:
entriesAsSymbols
- If true, treat Map.Entry keys of type String as symbols (don't quote them).
-
iterableToStr
@JvmOverloads() final static String iterableToStr(Integer indent, String collName, Iterable<Object> ls)
Pretty-prints any iterable with the given indent and class/field name
-
listToStr
@JvmOverloads()@Deprecated(message = "This just seems like a one-off version of iterableToString with dubious merit.", replaceWith = @ReplaceWith(imports = {"org.organicdesign.indented.StringUtils.iterableToStr"}, expression = "iterableToStr(indent, "listOf", ls, singleLine)")) final static String listToStr(Integer indent, Iterable<Object> ls, Boolean singleLine)
Pretty-prints any Iterable with the given indent as a list/array.
- Parameters:
singleLine
- If true, constrain all sub-collections to a single line.
-
listToStr
@JvmOverloads()@Deprecated(message = "This just seems like a one-off version of iterableToString with dubious merit.", replaceWith = @ReplaceWith(imports = {"org.organicdesign.indented.StringUtils.iterableToStr"}, expression = "iterableToStr(indent, "listOf", ls, singleLine)")) final static String listToStr(Integer indent, Iterable<Object> ls)
Pretty-prints any Iterable with the given indent as a list/array.
-
oneFieldPerLine
final static String oneFieldPerLine(Integer indent, String collName, Iterable<Entry.Map<String, Object>> fields)
Use this to pretty-print a class with one field per line.
-
oneFieldPerLineK
final String oneFieldPerLineK(Integer indent, String collName, Iterable<Pair<String, Object>> fields)
Kotlin wrapper because Pair does not implement Map.Entry and Pair is not accessible in Java.
-
fieldsOnOneLine
final static String fieldsOnOneLine(Integer indent, String collName, Iterable<Entry.Map<String, Object>> fields)
Use this to pretty-print a class with all fields on one line.
-
fieldsOnOneLineK
final String fieldsOnOneLineK(Integer indent, String collName, Iterable<Pair<String, Object>> fields)
Kotlin wrapper because Pair does not implement Map.Entry and Pair is not accessible in Java.
-
indent
@JvmOverloads() final static String indent(Integer indent, Object item, Boolean entriesAsSymbols, Boolean singleLine)
Takes a shot at pretty-printing anything you throw at it. If it's already an IndentedStringable, it calls IndentedStringable.indentedStr. Otherwise takes its best shot at indenting whatever it finds.
- Parameters:
entriesAsSymbols
- If true, treat Map.Entry keys of type String as symbols (don't quote them).singleLine
- If true, constrain all sub-collections to a single line.
-
indent
@JvmOverloads() final static String indent(Integer indent, Object item, Boolean entriesAsSymbols)
Takes a shot at pretty-printing anything you throw at it. If it's already an IndentedStringable, it calls IndentedStringable.indentedStr. Otherwise takes its best shot at indenting whatever it finds.
- Parameters:
entriesAsSymbols
- If true, treat Map.Entry keys of type String as symbols (don't quote them).
-
indent
@JvmOverloads() final static String indent(Integer indent, Object item)
Takes a shot at pretty-printing anything you throw at it. If it's already an IndentedStringable, it calls IndentedStringable.indentedStr. Otherwise takes its best shot at indenting whatever it finds.
-
stringify
final static String stringify(String s)
Surrounds strings with double quotes and escapes any internal double-quotes
-
charToStr
final static String charToStr(Character c)
Surround chars with single quotes and escape any internal single- or double-quotes
-
floatToStr
final static String floatToStr(Float f)
Prints float so it looks like a Float and not a Double.
-
bashSingleQuote
final static String bashSingleQuote(String s)
Single-quotes a string for Bash, escaping only single quotes. Returns '' for both the empty string and null. Will not write out any back-spaces.
-
-
-
-