org.kopitubruk.util.json
Class IndentPadding

java.lang.Object
  extended by org.kopitubruk.util.json.IndentPadding
All Implemented Interfaces:
Cloneable

public class IndentPadding
extends Object
implements Cloneable

This class provides a way to do indented formatting of the output to make it easier to read for debugging. Each item is on its own line and indented to show nesting.

To use this, create the object and set any parameters you like and call JSONConfig.setIndentPadding(IndentPadding) to add it to your config object and use it when you convert to JSON.

This class is NOT thread safe. Do not reuse this object in different threads. If you reuse JSONConfig objects in the same thread, then you should probably call reset() before calling JSONUtil's toJSON() methods just to be safe (but not inside JSONAbles that have a JSONConfig object sent to them and use JSONUtil to generate their JSON).

Since:
1.7
Author:
Bill Davidson

Constructor Summary
IndentPadding()
          Create an indent padding object using four spaces and a standard newline.
IndentPadding(String indent, String newLine)
          Create an indent padding object with the given indent and newLine strings.
 
Method Summary
 IndentPadding clone()
           
 void decrementLevel()
          Decrement the level of indent.
 String getIndent()
          Get the spacing for one indent level.
 String getNewLine()
          Get the string to use for a new line (default \n)
 String getPadding()
          Get the padding for the current indent level.
 void incrementLevel()
          Increment the level of indent.
 void reset()
          Reset this object's operating data.
 void setIndent(String indent)
          Set the spacing for one indent level (default is 4 spaces).
 void setNewLine(String newLine)
           Set the string to use for a new line (default \n).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndentPadding

public IndentPadding()
Create an indent padding object using four spaces and a standard newline.


IndentPadding

public IndentPadding(String indent,
                     String newLine)
Create an indent padding object with the given indent and newLine strings.

Parameters:
indent - The indent string to use for one level.
newLine - The new line string.
Method Detail

clone

public IndentPadding clone()
Overrides:
clone in class Object

reset

public void reset()
Reset this object's operating data.


getIndent

public String getIndent()
Get the spacing for one indent level.

Returns:
the spacing for one indent level.

setIndent

public void setIndent(String indent)
Set the spacing for one indent level (default is 4 spaces).

Parameters:
indent - The spacing for one indent level.

incrementLevel

public void incrementLevel()
Increment the level of indent. The level is the number of indents currently being used.


decrementLevel

public void decrementLevel()
Decrement the level of indent.


getNewLine

public String getNewLine()
Get the string to use for a new line (default \n)

Returns:
the string to use for a new line (default \n)

setNewLine

public void setNewLine(String newLine)

Set the string to use for a new line (default \n). A string is used so that you can use \r\n or other new line sequences if you like.

For example, if you wanted a platform specific newLine, you could do this:


    setNewLine(String.format("%n"));
 

Parameters:
newLine - The string to use for a new line (default \n)

getPadding

public String getPadding()
Get the padding for the current indent level.

Returns:
The padding for the current indent level.


Copyright © 2016. All rights reserved.