GWT Tk 0.2.3

asquare.gwt.tk.client.util
Class GwtUtil

java.lang.Object
  extended by asquare.gwt.tk.client.util.GwtUtil

public class GwtUtil
extends Object

General utility methods for working with in GWT.


Constructor Summary
GwtUtil()
           
 
Method Summary
static void arrayCopy(Object src, int srcPos, Object dest, int destPos, int length)
          Copies elements from the src array to the dest array.
static boolean equals(String a, String b)
          Tests two Strings for equality.
static void rangeCheck(int first, int size, int n, boolean extend)
          Checks that a number is contained within the specified range.
static void rangeCheck(List list, int index, boolean adding)
          Checks that the specified index is valid for the list (the GWT emulation of Vector does not perform range checking).
static Object[] toArray(List src, Object[] dest)
          Copies all of the elements in list to array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GwtUtil

public GwtUtil()
Method Detail

rangeCheck

public static void rangeCheck(List list,
                              int index,
                              boolean adding)
                       throws IndexOutOfBoundsException
Checks that the specified index is valid for the list (the GWT emulation of Vector does not perform range checking). A flag is passed to indicate whether the range should be extended by 1 to allow for adding a last element. Throws an exception if the index is out of bounds for the list.

Parameters:
list - the list to check against
index - the index to range check
adding - true to allow for adding at the index after last element in list
Throws:
IndexOutOfBoundsException - if the index is out of range

rangeCheck

public static void rangeCheck(int first,
                              int size,
                              int n,
                              boolean extend)
                       throws IndexOutOfBoundsException
Checks that a number is contained within the specified range. A flag is passed to indicate whether the range should be extended by 1 (to allow for adding a last element). Throws an exception if the index is out of bounds for the range.

Parameters:
first - the first allowable number
size - the size of the allowed range
n - the index to range check
extend - true to extend the size of the range by 1
Throws:
IndexOutOfBoundsException - if the index is out of range

arrayCopy

public static void arrayCopy(Object src,
                             int srcPos,
                             Object dest,
                             int destPos,
                             int length)
Copies elements from the src array to the dest array.

Parameters:
src - the source array
srcPos - the starting position in the source array
dest - the destination array
destPos - the starting position in the destination array
length - the number of array elements to copy
Throws:
NullPointerException - if src or dest is null
IndexOutOfBoundsException - if srcPos < 0 || destPos < 0 || length < 0 || (srcPos + length > src.length) || (destPos + length > dest.length)
ArrayStoreException - if an element in src cannot not be copied to dest due to a type mismatch
See Also:
System.arraycopy(Object, int, Object, int, int)

toArray

public static Object[] toArray(List src,
                               Object[] dest)
Copies all of the elements in list to array. Similar to List.toArray(Object[]) except this does not automatically expand the array size.

Parameters:
src - a list
dest - a non-primitive array
Throws:
NullPointerException - if src or dest is null
IndexOutOfBoundsException - if dest is not large enough to contain all of the list elements.
ArrayStoreException - if an element in list cannot not be copied to dest due to a type mismatch

equals

public static boolean equals(String a,
                             String b)
Tests two Strings for equality. Same as String.equals(Object). Either argument may be null.

Parameters:
a - a String, or null
b - a String, or null
Returns:
true if (a == b || a != null && a.equals(b))

GWT Tk 0.2.3

© 2007 Mat Gessel