Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## lp.struct.util
Class LpBuffer

    java.lang.Object
      lp.struct.util.LpBuffer

All Implemented Interfaces:
  Appendable, CharSequence

    public class LpBuffer

extends Object
implements Appendable, CharSequence

A convenience class that makes it possible to work with classes inheriting from a `LpPrinter` for writing into a string buffer instead of a writer. The contents of the buffer are available through the methods of this character sequence.

Version:
  1.0.0
Author:
  Martin Slota
See Also:
  `LpPrinter`, `LpPrettyPrinter.getBuffer()`, `EvolpPrettyPrinter.getBuffer()`, `LpHtmlPrinter.getBuffer()`, `LpEncoder.getBuffer()`

Field Summary
`private StringBuffer` | `buffer` The delegate for manipulating a mutable string.
`private LpPrinter<StringWriter>` | `printer` The `LpPrinter` used to append `LpStructureUnit`s to `buffer`.

Constructor Summary
`LpBuffer(LpPrinter<StringWriter> printer)` Creates a new instance of `LpBuffer` that uses `printer` to append usual objects and also `LpStructureUnit`s to a string buffer.

Method Summary
`LpBuffer` | `append(char c)` Appends the specified character to this `LpBuffer`.
`LpBuffer` | `append(CharSequence csq)` Appends the specified character sequence to this `LpBuffer`.
`LpBuffer` | `append(CharSequence csq, int start, int end)` Appends a subsequence of the specified character sequence to this `LpBuffer`.
`LpBuffer` | `append(LpStructureUnit unit)` Appends a textual representation of `unit` to this `LpBuffer`.
`String` | `asString(LpStructureUnit unit)` The call to this method is identical to calling reset(); append(unit); return toString();
`char` | `charAt(int index)` Returns the `char` value in this sequence at the specified index.
`int` | `length()` Returns the length (character count) of this character sequence.
`void` | `reset()` Deletes all characters in this sequence.
`CharSequence` | `subSequence(int start, int end)` Returns a subsequence of the character sequence represented by this object.
`String` | `toString()` Returns the contents of this character sequence as a string.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### printer

    private final LpPrinter<StringWriter> printer

  The `LpPrinter` used to append `LpStructureUnit`s to `buffer`.

### buffer

    private final StringBuffer buffer

  The delegate for manipulating a mutable string.

Constructor Detail

### LpBuffer

    public LpBuffer(LpPrinter<StringWriter> printer)

  Creates a new instance of `LpBuffer` that uses `printer` to append usual objects and also `LpStructureUnit`s to a string buffer.

  Parameters:
    `printer` - will be used to append usual objects and also `LpStructureUnit`s to a string buffer. Shouldn't be manipulated by any other object.

Method Detail

### append

    public LpBuffer append(CharSequence csq)

  Appends the specified character sequence to this `LpBuffer`.

  Specified by:
    `append` in interface `Appendable`
  Parameters:
    `csq` - the `CharSequence` that should be appended to this `LpBuffer`
  Returns:
    a reference to this object after appending

### append

    public LpBuffer append(CharSequence csq,
                           int start,
                           int end)

  Appends a subsequence of the specified character sequence to this `LpBuffer`.

  Specified by:
    `append` in interface `Appendable`
  Parameters:
    `csq` - the character sequence from which a subsequence will be appended. If `csq` is `null`, then characters will be appended as if `csq` contained the four characters `"null"`.
    `start` - the index of the first character in the subsequence
    `end` - the index of the character following the last character in the subsequence
  Returns:
    a reference to this object after appending

### append

    public LpBuffer append(char c)

  Appends the specified character to this `LpBuffer`.

  Specified by:
    `append` in interface `Appendable`
  Parameters:
    `c` - the character to append
  Returns:
    a reference to this object after appending

### length

    public int length()

  Returns the length (character count) of this character sequence.

  Specified by:
    `length` in interface `CharSequence`
  Returns:
    the length of the sequence of characters currently represented by this object
  See Also:
    `CharSequence.length()`

### charAt

    public char charAt(int index)

  Returns the `char` value in this sequence at the specified index.

  Specified by:
    `charAt` in interface `CharSequence`
  Parameters:
    `index` - the index of the character that should be returned. Indexing starts at 0, highest allowed value is `length() - 1`
  Throws:
    `IndexOutOfBoundsException` - if `index` if negative or greater or equal to `length()`
  See Also:
    `length()`, `CharSequence.charAt(int)`

### subSequence

    public CharSequence subSequence(int start,
                                    int end)

  Returns a subsequence of the character sequence represented by this object.

  Specified by:
    `subSequence` in interface `CharSequence`
  Parameters:
    `start` - the start index (inclusive)
    `end` - the end index (exclusive)
  Throws:
    `IndexOutOfBoundsException` - if either of the indexes is negative, or `end` is greater than `length()`, or `start` is greater than `end`
  See Also:
    `CharSequence.subSequence(int, int)`

### reset

    public void reset()

  Deletes all characters in this sequence.

### append

    public LpBuffer append(LpStructureUnit unit)

  Appends a textual representation of `unit` to this `LpBuffer`. The string is constructed in the `#visit()` methods of this class. If `unit` is `null`, the string "null" is appended.

  Parameters:
    `unit` - the `LpStructureUnit` that should be represented as a string and appended to this character sequence
  Returns:
    a reference to this object after appending

### asString

    public String asString(LpStructureUnit unit)

  The call to this method is identical to calling

      reset();
      append(unit);
      return toString();

  Parameters:
    `unit` - the `LpStructureUnit` that should be represented as a string and appended to this character sequence

### toString

    public String toString()

  Returns the contents of this character sequence as a string.

  Specified by:
    `toString` in interface `CharSequence`
  Overrides:
    `toString` in class `Object`
  Returns:
    as specified above

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD