public class CyclicStringBuffer extends Object
String
buffer.
Stores up to <size>
characters in cyclic buffer and allows
to simply append new characters to the end or prepend new characters
to the beginning of the buffer without necessity to move buffer content.
Modifier and Type | Field and Description |
---|---|
private int |
beg
Current beginning of valid characters storage.
|
private char[] |
buff
Buffer content.
|
private int |
len
Count of valid characters in the buffer.
|
private static Logger |
LOGGER
Logger instance for this class.
|
private int |
size
Buffer size.
|
Constructor and Description |
---|
CyclicStringBuffer(int size)
Creates an instance of cyclic
String buffer. |
Modifier and Type | Method and Description |
---|---|
boolean |
append(char c)
Appends character at the end of the buffer.
|
boolean |
equals(String s)
Compares buffer content to the specific
String . |
boolean |
prepend(char c)
Appends character at the beginning of the buffer.
|
void |
resize(int size)
Resize cyclic
String buffer. |
String |
toString()
Returns
String stored in buffer. |
private static final Logger LOGGER
private int size
private char[] buff
private int len
private int beg
public CyclicStringBuffer(int size)
String
buffer.
size
- Cyclic String
buffer size.public void resize(int size)
String
buffer.
Content of buffer will be removed.
size
- New cyclic String
buffer size.public boolean append(char c)
c
- Character to be appended.true
when buffer was full and first
character in the buffer got overwritten or false
otherwise.public boolean prepend(char c)
c
- Character to be prepended.true
when buffer was full and last
character in the buffer got overwritten or false
otherwise.public boolean equals(String s)
String
.
Empty String
value and null
value are considered
as equivalent and are equal to zero length buffer content.
true
if buffer content represents
String
equivalent to this provided string
or false
otherwise.Copyright © 2013. All Rights Reserved.