org.zkoss.util
Class CollectionsX

java.lang.Object
  extended by org.zkoss.util.CollectionsX

public class CollectionsX
extends java.lang.Object

The collection related utilities.

Author:
tomyeh
See Also:
Collections

Nested Class Summary
static class CollectionsX.ArrayCollection
          An readonly collection on top of an array.
static class CollectionsX.ArrayEnumeration
          An enumeration on top of an array.
static class CollectionsX.ArrayIterator
          An iterator on top of an array.
static class CollectionsX.ArrayList
          An readonly list on top of an array.
static class CollectionsX.ArrayListIterator
           
static class CollectionsX.CollectionEnumeration
          An enumeration on top of a collection or iterator.
static class CollectionsX.EnumerationIterator
          An iterator that iterates thru an Enumeration.
static class CollectionsX.OneCollection
          A collection that contains only one element.
static class CollectionsX.OneEnumeration
          An enumeration that enumerates one element.
static class CollectionsX.OneIterator
          An iterator that iterates one element.
 
Field Summary
static java.util.Enumeration EMPTY_ENUMERATION
          Empty enumeration.
static java.util.Iterator EMPTY_ITERATOR
          Empty iterator.
 
Constructor Summary
CollectionsX()
           
 
Method Summary
static int addAll(java.util.Collection col, java.util.Enumeration enm)
          Adds all elements returned by the enumerator to a collection.
static int addAll(java.util.Collection col, java.util.Iterator iter)
          Adds all elements returned by the iterator to a collection.
static int addAll(java.util.Collection col, java.lang.Object[] ary)
          Adds all elements of an array to a collection.
static boolean isIntersected(java.util.Set a, java.util.Set b)
          Tests whether two sets has any intersection.
static java.util.Iterator iterator(java.lang.Object obj)
          Based on the given collection type of Object, return an iterator.
static java.util.Collection parse(java.util.Collection c, java.lang.String src, char separator)
          Parses a string into a list.
static java.util.Collection parse(java.util.Collection c, java.lang.String src, char separator, boolean escBackslash)
          Parses a string into a list.
static java.util.Collection parse(java.util.Collection c, java.lang.String src, char separator, boolean escBackslash, boolean parenthesis)
          Parses a string into a list.
static java.lang.Object[] toArray(java.util.Collection col, int from, int to)
          Returns the specified range of the specified collection into a new array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ITERATOR

public static final java.util.Iterator EMPTY_ITERATOR
Empty iterator.


EMPTY_ENUMERATION

public static final java.util.Enumeration EMPTY_ENUMERATION
Empty enumeration.

Constructor Detail

CollectionsX

public CollectionsX()
Method Detail

toArray

public static final java.lang.Object[] toArray(java.util.Collection col,
                                               int from,
                                               int to)
Returns the specified range of the specified collection into a new array. The initial index of the range (from) must lie between zero and col.size, inclusive. The final index of the range (to), which must be greater than or equal to from.

The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Parameters:
col - the collection to be copied.
from - the initial index of the range to be copied, inclusive.
to - the final index of the range to be copied, exclusive.
Since:
3.0.6

addAll

public static final int addAll(java.util.Collection col,
                               java.util.Iterator iter)
Adds all elements returned by the iterator to a collection.

Parameters:
iter - the iterator; null is OK
Returns:
the number element being added

addAll

public static final int addAll(java.util.Collection col,
                               java.util.Enumeration enm)
Adds all elements returned by the enumerator to a collection.

Parameters:
enm - the enumeration; null is OK
Returns:
the number element being added

addAll

public static final int addAll(java.util.Collection col,
                               java.lang.Object[] ary)
Adds all elements of an array to a collection.

Parameters:
ary - the array; null is OK
Returns:
the number element being added

isIntersected

public static final boolean isIntersected(java.util.Set a,
                                          java.util.Set b)
Tests whether two sets has any intersection.


parse

public static final java.util.Collection parse(java.util.Collection c,
                                               java.lang.String src,
                                               char separator)
Parses a string into a list. It is the same as parse(c, src, separator, true, false). Refer to parse(Collection, String, char, boolean, boolean) for details.

Throws:
IllegalSyntaxException - if syntax errors
See Also:
Maps.parse(java.util.Map, java.lang.String, char, char), parse(Collection, String, char, boolean, boolean)

parse

public static final java.util.Collection parse(java.util.Collection c,
                                               java.lang.String src,
                                               char separator,
                                               boolean escBackslash)
Parses a string into a list. It is the same as parse(c, src, separator, escBackslash, false). Refer to parse(Collection, String, char, boolean, boolean) for details.

Throws:
IllegalSyntaxException - if syntax errors
See Also:
Maps.parse(java.util.Map, java.lang.String, char, char), parse(Collection, String, char, boolean, boolean)

parse

public static final java.util.Collection parse(java.util.Collection c,
                                               java.lang.String src,
                                               char separator,
                                               boolean escBackslash,
                                               boolean parenthesis)
Parses a string into a list. To quote a string, both '\'' and '"' are OK. Whitespaces are trimmed between quotation and separators.

Unlike Java, quotation could spread over multiple lines.

Example,
a b , ' c d',"'f'", '1' "2", 3
generate a list of "a b", "c d", "'f'", "1", "2" and "3". Note: the separator between "1" and "2" is optional.

Note: Like Java, if the string is ending with a separator, it will be ignored.

Example,
a, , b,
generate a list of "a", "", "b".

Parameters:
c - the collection to hold the parsed results; a linked list is created if c is null.
src - the string to parse
separator - the separator, e.g., ',', '\n' or ' '. Note: if separator is ' ', it denotes any white space.
escBackslash - whether to treat '\\' specially (as escape char)
parenthesis - whether to parse parenthesis in the value, {}, () and []. If true, the separator is ignored inside the parenthesis. Specify true if the value might contain EL expressions.
Returns:
the c collection if not null; or a linked list if c is null (so you can cast it to List)
Throws:
IllegalSyntaxException - if syntax errors
Since:
3.0.6
See Also:
Maps.parse(java.util.Map, java.lang.String, char, char)

iterator

public static final java.util.Iterator iterator(java.lang.Object obj)
Based on the given collection type of Object, return an iterator. The Collection type of object can be Collection, Map (return the entry), or Array.



Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo