org.ujorm.core
Class RingBuffer

java.lang.Object
  extended by org.ujorm.core.RingBuffer
All Implemented Interfaces:
java.lang.CharSequence

public final class RingBuffer
extends java.lang.Object
implements java.lang.CharSequence

A 'ring buffer' implementation whith a required length of the buffer. See a sample use case of finding some substrings:

    String text = "xxx ${abc} ${def} xyz";
    Reader reader = RingBuffer.createReader(text);
    String word_1 = RingBuffer.findWord(reader, "${", "}");
    assert "abc".equals(word_1)
    String word_2 = RingBuffer.findWord(reader, "${", "}");
    assert "def".equals(word_2)
 

Version:
2001-10-01
Author:
Pavel Ponec
See Also:
Sample of use.

Field Summary
 int length
          Length
static java.nio.charset.Charset UTF8
          The UTF-8 Charset
 
Constructor Summary
RingBuffer(int length)
          Creates new RingBuffer
 
Method Summary
 void add(char c)
           
static java.io.Reader createReader(java.io.File file)
          Create Reader from the UTF-8 encode source
static java.io.Reader createReader(java.io.File file, java.nio.charset.Charset charset)
          Create Reader
static java.io.Reader createReader(java.lang.String text)
          Create Reader
static java.io.Reader createReader(java.net.URL url)
          Create Reader from the UTF-8 encode source
static java.io.Reader createReader(java.net.URL url, java.nio.charset.Charset charset)
          Create Reader
 boolean equals(char[] s)
          The equals test
 boolean equals(java.lang.String s)
          The equals test
static java.lang.String findWord(java.io.Reader reader, java.lang.String beg, java.lang.String end)
          Find a word betveen beg and end text from current cursor and TRIM the result.
static java.lang.String findWord(java.lang.String source, java.lang.String beg, java.lang.String end)
          Find a word betveen beg and end text from the source start and trim the result.
static java.lang.String findWordNoTrim(java.io.Reader reader, java.lang.String beg, java.lang.String end)
          Find a word betveen beg and end text from current cursor.
static java.lang.String findWordNoTrim(java.lang.String source, java.lang.String beg, java.lang.String end)
          Find a word betveen beg and end text from the source start.
 char charAt(int i)
          Returns a character from position 'i'
 int length()
          Length of the String
 java.lang.CharSequence subSequence(int start, int end)
          Get a sub-sequence
 java.lang.String substring(int begIndex, int endIndex)
          Export to the String
 java.lang.String toString()
          Export to the String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UTF8

public static final java.nio.charset.Charset UTF8
The UTF-8 Charset


length

public final int length
Length

Constructor Detail

RingBuffer

public RingBuffer(int length)
Creates new RingBuffer

Method Detail

add

public final void add(char c)

equals

public boolean equals(java.lang.String s)
The equals test


equals

public boolean equals(char[] s)
The equals test


charAt

public char charAt(int i)
Returns a character from position 'i'

Specified by:
charAt in interface java.lang.CharSequence

toString

public java.lang.String toString()
Export to the String.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

substring

public java.lang.String substring(int begIndex,
                                  int endIndex)
Export to the String


length

public final int length()
Length of the String

Specified by:
length in interface java.lang.CharSequence

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Get a sub-sequence

Specified by:
subSequence in interface java.lang.CharSequence

findWord

public static java.lang.String findWord(java.io.Reader reader,
                                        java.lang.String beg,
                                        java.lang.String end)
                                 throws java.io.IOException
Find a word betveen beg and end text from current cursor and TRIM the result. The method is designed for a very large data source (a character stream).
Sample:
    String text = "xxx ${abc} def";
    String word = RingBuffer.findWord(text, "${", "}");
    assert "abc".equals(word)
 

Parameters:
reader - A data source
beg - Start tag (text) where the empty value means find end from the current cursor.
end - End tag (text) must not be empty.
Returns:
Return a result between beg and end tags (texts). The result is newer NULL.
Throws:
java.io.IOException

findWord

public static java.lang.String findWord(java.lang.String source,
                                        java.lang.String beg,
                                        java.lang.String end)
                                 throws java.io.IOException
Find a word betveen beg and end text from the source start and trim the result. The method is designed for a very large data source (a character stream).

Parameters:
source - a Data source
beg - Start tag (text) where the empty value means find end from the current cursor.
end - End tag (text) must not be empty.
Returns:
Return a result between beg and end tags (texts). The result is newer NULL.
Throws:
java.io.IOException

findWordNoTrim

public static java.lang.String findWordNoTrim(java.lang.String source,
                                              java.lang.String beg,
                                              java.lang.String end)
                                       throws java.io.IOException
Find a word betveen beg and end text from the source start. The method is designed for a very large data source (a character stream).
Sample:
    String text = "xxx ${abc} def";
    String word = RingBuffer.findWord(text, "${", "}");
    assert "abc".equals(word)
 

Parameters:
reader - A data source
beg - Start tag (text) where the empty value means find end from the current cursor.
end - End tag (text) must not be empty.
Returns:
Return a result between beg and end tags (texts). The result is newer NULL.
Throws:
java.io.IOException

findWordNoTrim

public static java.lang.String findWordNoTrim(java.io.Reader reader,
                                              java.lang.String beg,
                                              java.lang.String end)
                                       throws java.io.IOException
Find a word betveen beg and end text from current cursor. The method is designed for a very large data source (a character stream).

Parameters:
reader - A data source
beg - Start tag (text) where the empty value means find end from the current cursor.
end - End tag (text) must not be empty.
Returns:
Return a result between beg and end tags (texts). The result is newer NULL.
Throws:
java.io.IOException

createReader

public static java.io.Reader createReader(java.io.File file)
                                   throws java.io.FileNotFoundException
Create Reader from the UTF-8 encode source

Throws:
java.io.FileNotFoundException

createReader

public static java.io.Reader createReader(java.io.File file,
                                          java.nio.charset.Charset charset)
                                   throws java.io.FileNotFoundException
Create Reader

Throws:
java.io.FileNotFoundException

createReader

public static java.io.Reader createReader(java.lang.String text)
Create Reader


createReader

public static java.io.Reader createReader(java.net.URL url)
                                   throws java.io.IOException
Create Reader from the UTF-8 encode source

Throws:
java.io.IOException

createReader

public static java.io.Reader createReader(java.net.URL url,
                                          java.nio.charset.Charset charset)
                                   throws java.io.IOException
Create Reader

Throws:
java.io.IOException


Copyright © 2007-2012 PPonec