org.nihongoresources.utf8
Class uCharArray

java.lang.Object
  extended by org.nihongoresources.utf8.uCharArray
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<java.lang.String>, java.util.Collection<java.lang.String>

public final class uCharArray
extends java.lang.Object
implements java.util.Collection<java.lang.String>, java.io.Serializable

A unicode "character" array class. The characters are actually represented by regular String objects, because char is only 16 bit, while unicode allows for far wider glyphs (at present the widest UTF8 characters are 32 bit, although the UTF8 byte specification technically allows for infinite length bit patterns) In my work I have had to work with three and four byte unicode glyphs, and so I have had a pressing need for this class. Regular java fails hardcore for true unicode work.

See Also:
Serialized Form

Constructor Summary
uCharArray(int size)
          size-allocated but not filled constructor
uCharArray(java.lang.String string)
          String based constructor
uCharArray(java.lang.String[] string)
          String array based constructor
uCharArray(uString string)
          uString based constructor
 
Method Summary
 boolean add(java.lang.String arg0)
           
 boolean addAll(java.util.Collection<? extends java.lang.String> arg)
           
 void clean()
          removes any empty or null elements
 void clear()
           
 boolean contains(java.lang.Object arg)
          Why does the erasure for this method use Object, rather than the interface's generic type? (in this case, String)
 boolean containsAll(java.util.Collection<?> args)
          Again, why does the erasure require rather than ?
 boolean equals(java.lang.Object o)
          equality
 java.lang.String get(int index)
          Since we can't overload the array 'functor' [], we employ a "get" method instead.
 boolean isEmpty()
           
 java.util.Iterator<java.lang.String> iterator()
           
 int length()
          returns the length of this array
static void main(java.lang.String[] args)
           
 java.lang.String pop()
          Pops an element off of the end of the array
 java.lang.String pop(int index)
          Pops an element from somewhere in the array
 boolean push(java.lang.String unicodecharacter)
          Pushes an element onto the end of the array
 boolean remove(java.lang.Object arg)
           
 boolean removeAll(java.util.Collection<?> arg0)
           
 boolean retainAll(java.util.Collection<?> arg0)
           
 void set(int index, java.lang.String unicodecharacter)
          Since we can't overload the array 'functor' [], we employ a "set" method instead.
 int size()
          does the same as length(), but collections require a size() method
 uCharArray slice(int begin, int end)
          The equivalent of substring for Strings.
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] arg)
          Deprecated. 
 java.lang.String toString()
          The benefit of a genuine class: a toString() method (something arrays sorely miss in java).
 java.lang.String toVectorString()
          The benefit of a genuine class: a toString() method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
hashCode
 

Constructor Detail

uCharArray

public uCharArray(int size)
size-allocated but not filled constructor

Parameters:
size -

uCharArray

public uCharArray(java.lang.String[] string)
String array based constructor

Parameters:
string -

uCharArray

public uCharArray(java.lang.String string)
String based constructor

Parameters:
string -

uCharArray

public uCharArray(uString string)
uString based constructor

Parameters:
string -
Method Detail

length

public int length()
returns the length of this array

Returns:

pop

public java.lang.String pop()
Pops an element off of the end of the array

Returns:

pop

public java.lang.String pop(int index)
Pops an element from somewhere in the array

Returns:

push

public boolean push(java.lang.String unicodecharacter)
Pushes an element onto the end of the array

Returns:

get

public java.lang.String get(int index)
Since we can't overload the array 'functor' [], we employ a "get" method instead.

Parameters:
index -
Returns:

set

public void set(int index,
                java.lang.String unicodecharacter)
Since we can't overload the array 'functor' [], we employ a "set" method instead.

Parameters:
index -

slice

public uCharArray slice(int begin,
                        int end)
The equivalent of substring for Strings. I'm not a fan of the Java choice to use begin/end parameters rather than begin/length parameters, but then I don't want to confuse people either, so begin/end it is.

Parameters:
begin - inclusive
end - exclusive
Returns:
Throws:
java.lang.ArrayIndexOutOfBoundsException

clean

public void clean()
removes any empty or null elements


equals

public boolean equals(java.lang.Object o)
equality

Specified by:
equals in interface java.util.Collection<java.lang.String>
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

toString

public java.lang.String toString()
The benefit of a genuine class: a toString() method (something arrays sorely miss in java).

Overrides:
toString in class java.lang.Object
Returns:
A String consisting of the concatenation of all array elements.

toVectorString

public java.lang.String toVectorString()
The benefit of a genuine class: a toString() method.

Returns:
A String consisting of the concatenation of all array elements, glued together with ", " and wrapped by square brackets, akin to how Vector's toString() works.

add

public boolean add(java.lang.String arg0)
Specified by:
add in interface java.util.Collection<java.lang.String>

addAll

public boolean addAll(java.util.Collection<? extends java.lang.String> arg)
Specified by:
addAll in interface java.util.Collection<java.lang.String>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<java.lang.String>

contains

public boolean contains(java.lang.Object arg)
Why does the erasure for this method use Object, rather than the interface's generic type? (in this case, String)

Specified by:
contains in interface java.util.Collection<java.lang.String>

containsAll

public boolean containsAll(java.util.Collection<?> args)
Again, why does the erasure require rather than ?

Specified by:
containsAll in interface java.util.Collection<java.lang.String>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<java.lang.String>

iterator

public java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>
Specified by:
iterator in interface java.util.Collection<java.lang.String>

remove

public boolean remove(java.lang.Object arg)
Specified by:
remove in interface java.util.Collection<java.lang.String>

removeAll

public boolean removeAll(java.util.Collection<?> arg0)
Specified by:
removeAll in interface java.util.Collection<java.lang.String>

retainAll

public boolean retainAll(java.util.Collection<?> arg0)
Specified by:
retainAll in interface java.util.Collection<java.lang.String>

size

public int size()
does the same as length(), but collections require a size() method

Specified by:
size in interface java.util.Collection<java.lang.String>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<java.lang.String>

toArray

@Deprecated
public <T> T[] toArray(T[] arg)
Deprecated. 

Please, please please please... think... This whole construction is just too much of a hack for my taste. Using generics, based on a throw-away argument used onlyto indicate the class? If you're relying on this method for your code functionality, this is a good indicator you are programming against the language, rather than in it. I marked this method as deprecated so that you're reminded by your IDE that this is a ridiculously bad idea to use. If that doesn't deter you, it also throws a "not implemented" exception when you do use it. So don't.

Specified by:
toArray in interface java.util.Collection<java.lang.String>

main

public static void main(java.lang.String[] args)