org.jqurantree.arabic
Class ArabicTextBuilder

java.lang.Object
  extended by org.jqurantree.arabic.ArabicTextBuilder

public class ArabicTextBuilder
extends java.lang.Object

The ArabicTextBuilder class is used to construct ArabicText by wrapping a mutable sequence of ArabicCharacters. Since ArabicText instances are immutable, a builder is required to construct new instances. This class is analogous to the Java StringBuilder class. The class manages an internal byte[] buffer which grows on demand.

Author:
Kais Dukes

Constructor Summary
ArabicTextBuilder()
          Creates a new Arabic text builder with the default initial capacity.
ArabicTextBuilder(int characterCapacity)
          Creates a new Arabic text builder with the specified character capacity.
 
Method Summary
 void add(CharacterType characterType)
          Appends a new character to the end of the buffer.
 void add(CharacterType characterType, DiacriticType... diaciritcTypes)
          Appends a new character with attached diacritics to the end of the buffer.
 void add(DiacriticType diacriticType)
          Attaches a diacritic to the last character in the buffer.
 void addWhitespace()
          Appends a space character to the end of the buffer.
 byte[] toByteArray()
          Gets a copy of the internal byte[] buffer holding only used characters.
 java.lang.String toString()
          Converts the Arabic text builder to a string.
 ArabicText toText()
          Creates a new ArabicText instance from the characters in the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArabicTextBuilder

public ArabicTextBuilder()
Creates a new Arabic text builder with the default initial capacity.


ArabicTextBuilder

public ArabicTextBuilder(int characterCapacity)
Creates a new Arabic text builder with the specified character capacity.

Parameters:
characterCapacity - the initial size of the byte[] buffer measured in characters. Each character will occupy 3 bytes in the buffer.
Method Detail

add

public void add(CharacterType characterType)
Appends a new character to the end of the buffer.

Parameters:
characterType - the type of Arabic letter or Quranic symbol to append, such as Alif or Ba.

add

public void add(DiacriticType diacriticType)
Attaches a diacritic to the last character in the buffer.

Parameters:
diacriticType - the type of diacritic to attach, such as Fatha or Shadda.

add

public void add(CharacterType characterType,
                DiacriticType... diaciritcTypes)
Appends a new character with attached diacritics to the end of the buffer.

Parameters:
characterType - the type of Arabic letter or Quranic symbol to append, such as Alif or Ba.
diaciritcTypes - a list of diacritics to attach, such as Fatha or Shadda.

addWhitespace

public void addWhitespace()
Appends a space character to the end of the buffer.


toString

public java.lang.String toString()
Converts the Arabic text builder to a string. The returned string will represent the characters in the buffer using Unicode encoding.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the characters in the buffer using Unicode encoding

toText

public ArabicText toText()
Creates a new ArabicText instance from the characters in the buffer.

Returns:
a new ArabicText instance

toByteArray

public byte[] toByteArray()
Gets a copy of the internal byte[] buffer holding only used characters.

Returns:
a byte[] array


Copyright© Kais Dukes, 2009. All Rights Reserved.