edu.rice.cs.plt.debug
Class Indenter

java.lang.Object
  extended by edu.rice.cs.plt.debug.Indenter

public class Indenter
extends Object

Manages a string of varying size to be used for indenting. The "indent string" is some token string repeated a variable number of times. By default, the token string is " " (two spaces), but a different string may be provided if needed. Initially, the indentation level (the number of repeats) is set to 0; push() and pop() are used to adjust this value.

If thread safety is required, alternative atomicPop() and atomicPush() methods are provided as well. These use locking to prevent concurrent changes to the indentation level.


Constructor Summary
Indenter()
          Create an indenter with the default token string: " " (two spaces)
Indenter(int spaces)
          Create an indenter with the specified number of spaces as its token string
Indenter(String token)
          Create an indenter with the given string as its token string
 
Method Summary
 void atomicPop()
          Decrease the indentation level atomically.
 void atomicPush()
          Increase the indentation level atomically.
 String indentString()
          Produce a string based on the token string and current indentation level.
 void pop()
          Decrease the indentation level
 void push()
          Increase the indentation level
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Indenter

public Indenter()
Create an indenter with the default token string: " " (two spaces)


Indenter

public Indenter(int spaces)
Create an indenter with the specified number of spaces as its token string


Indenter

public Indenter(String token)
Create an indenter with the given string as its token string

Method Detail

push

public void push()
Increase the indentation level


pop

public void pop()
Decrease the indentation level


atomicPush

public void atomicPush()
Increase the indentation level atomically. Locking prevents other atomicPush() and atomicPop() invocations from adjusting the level simultaneously.


atomicPop

public void atomicPop()
Decrease the indentation level atomically. Locking prevents other atomicPush() and atomicPop() invocations from adjusting the level simultaneously.


indentString

public String indentString()
Produce a string based on the token string and current indentation level. If the level is <= 0, this is the empty string.