org.xwiki.velocity.tools
Class CollectionsTool

java.lang.Object
  extended by org.xwiki.velocity.tools.CollectionsTool

public class CollectionsTool
extends Object

Velocity Tool allowing to create various type of collections.

Since:
4.0M1
Version:
$Id: c5b00bd8802723f4940d1adedecdf38d6a559359 $

Constructor Summary
CollectionsTool()
           
 
Method Summary
<E> Collection<E>
disjunction(Collection<E> a, Collection<E> b)
          Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collections.
<E> List<E>
getArrayList()
          Create and return a new ArrayList, an unbounded list with constant access time and good performance for most additions at the end of the list, but which performs poorly when deleting items, when inserting a new item in the list and when appending a new item requires resizing the allocated space.
<E> BlockingQueue<E>
getBlockingQueue()
          Create and return a new BlockingQueue, an unbounded queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element.
<E> List<E>
getLinkedList()
          Create and return a new LinkedList, optimized for insertion and deletion of items, and for sequential iteration over the items, but not for quick access to random positions in the list.
<K,V> Map<K,V>
getMap()
          Create and return a new Map, providing good speed for insertion, retrieval and deletion of items, but with no guarantees on the order of the map.
<K,V> Map<K,V>
getOrderedMap()
          Create and return a new Map, which ensures that iterating the map will always return the entries in the same order as they were added.
<E> Set<E>
getOrderedSet()
          Create and return a new Set, which ensures that iterating the set will always return the entries in the same order as they were added.
<E extends Comparable<E>>
Queue<E>
getPriorityQueue()
          Create and return a new Queue, which instead of the FIFO ordering uses the natural order of the items added to the queue, so that the retrieved item is always the lowest one.
<E> Queue<E>
getQueue()
          Create and return a new Queue, an unbounded list where items are ordered in a FIFO (first-in-first-out) manner.
<E> Set<E>
getSet()
          Create and return a new Set, providing good speed for insertion, retrieval and deletion of items, but with no guarantees on the order of the set.
<K extends Comparable<K>,V>
SortedMap<K,V>
getSortedMap()
          Create and return a new SortedMap, which ensures that iterating the map will always return the entries in the natural order of the keys.
<E extends Comparable<E>>
SortedSet<E>
getSortedSet()
          Create and return a new SortedSet, which ensures that iterating the set will always return the entries in the natural order of the items.
<E> Collection<E>
intersection(Collection<E> a, Collection<E> b)
          Returns a Collection containing the intersection of the given Collections.
<E> boolean
reverse(List<E> input)
          Reverse the order of the elements within a list, so that the last element is moved to the beginning of the list, the next-to-last element to the second position, and so on.
<E extends Comparable<E>>
boolean
sort(List<E> input)
          Sort the elements within a list according to their natural order.
<E> Collection<E>
union(Collection<E> a, Collection<E> b)
          Returns a Collection containing the union of the given Collections.
<E> Collection<E>
unmodifiable(Collection<E> input)
          Returns an unmodifiable view of the specified collection.
<E> List<E>
unmodifiable(List<E> input)
          Returns an unmodifiable view of the specified list.
<K,V> Map<K,V>
unmodifiable(Map<K,V> input)
          Returns an unmodifiable view of the specified map.
<E> Set<E>
unmodifiable(Set<E> input)
          Returns an unmodifiable view of the specified set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionsTool

public CollectionsTool()
Method Detail

getArrayList

public <E> List<E> getArrayList()
Create and return a new ArrayList, an unbounded list with constant access time and good performance for most additions at the end of the list, but which performs poorly when deleting items, when inserting a new item in the list and when appending a new item requires resizing the allocated space.

Type Parameters:
E - the type of the elements in the list
Returns:
a new, empty ArrayList

getLinkedList

public <E> List<E> getLinkedList()
Create and return a new LinkedList, optimized for insertion and deletion of items, and for sequential iteration over the items, but not for quick access to random positions in the list.

Type Parameters:
E - the type of the elements in the list
Returns:
a new, empty LinkedList

getMap

public <K,V> Map<K,V> getMap()
Create and return a new Map, providing good speed for insertion, retrieval and deletion of items, but with no guarantees on the order of the map.

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
Returns:
a new, empty HashMap

getSortedMap

public <K extends Comparable<K>,V> SortedMap<K,V> getSortedMap()
Create and return a new SortedMap, which ensures that iterating the map will always return the entries in the natural order of the keys.

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
Returns:
a new, empty TreeMap

getOrderedMap

public <K,V> Map<K,V> getOrderedMap()
Create and return a new Map, which ensures that iterating the map will always return the entries in the same order as they were added.

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
Returns:
a new, empty LinkedHashMap

getSet

public <E> Set<E> getSet()
Create and return a new Set, providing good speed for insertion, retrieval and deletion of items, but with no guarantees on the order of the set.

Type Parameters:
E - the type of the elements in the set
Returns:
a new, empty HashSet

getSortedSet

public <E extends Comparable<E>> SortedSet<E> getSortedSet()
Create and return a new SortedSet, which ensures that iterating the set will always return the entries in the natural order of the items.

Type Parameters:
E - the type of the elements in the set
Returns:
a new, empty TreeSet

getOrderedSet

public <E> Set<E> getOrderedSet()
Create and return a new Set, which ensures that iterating the set will always return the entries in the same order as they were added.

Type Parameters:
E - the type of the elements in the set
Returns:
a new, empty LinkedHashSet

getQueue

public <E> Queue<E> getQueue()
Create and return a new Queue, an unbounded list where items are ordered in a FIFO (first-in-first-out) manner.

Type Parameters:
E - the type of the elements in the queue
Returns:
a new, empty LinkedList

getBlockingQueue

public <E> BlockingQueue<E> getBlockingQueue()
Create and return a new BlockingQueue, an unbounded queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element.

Type Parameters:
E - the type of the elements in the queue
Returns:
a new, empty BlockingQueue

getPriorityQueue

public <E extends Comparable<E>> Queue<E> getPriorityQueue()
Create and return a new Queue, which instead of the FIFO ordering uses the natural order of the items added to the queue, so that the retrieved item is always the lowest one. All the items added to this queue must be non-null and be comparable with the other items in the queue.

Type Parameters:
E - the type of the elements in the queue
Returns:
a new, empty PriorityQueue

unmodifiable

public <E> List<E> unmodifiable(List<E> input)
Returns an unmodifiable view of the specified list.

Type Parameters:
E - the type of the elements in the list
Parameters:
input - the list to wrap in an unmodifiable bridge
Returns:
an unmodifiable view of the list

unmodifiable

public <K,V> Map<K,V> unmodifiable(Map<K,V> input)
Returns an unmodifiable view of the specified map.

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
Parameters:
input - the map to wrap in an unmodifiable bridge
Returns:
an unmodifiable view of the map

unmodifiable

public <E> Set<E> unmodifiable(Set<E> input)
Returns an unmodifiable view of the specified set.

Type Parameters:
E - the type of the elements in the set
Parameters:
input - the set to wrap in an unmodifiable bridge
Returns:
an unmodifiable view of the set

unmodifiable

public <E> Collection<E> unmodifiable(Collection<E> input)
Returns an unmodifiable view of the specified collection.

Type Parameters:
E - the type of the elements in the collection
Parameters:
input - the collection to wrap in an unmodifiable bridge
Returns:
an unmodifiable view of the collection

union

public <E> Collection<E> union(Collection<E> a,
                               Collection<E> b)
Returns a Collection containing the union of the given Collections.

Type Parameters:
E - the type of the elements in the collection
Parameters:
a - the first collection, must be non-null
b - the second collection, must be non-null
Returns:
the union of the two collections

intersection

public <E> Collection<E> intersection(Collection<E> a,
                                      Collection<E> b)
Returns a Collection containing the intersection of the given Collections.

Type Parameters:
E - the type of the elements in the collection
Parameters:
a - the first collection, must be non-null
b - the second collection, must be non-null
Returns:
the intersection of the two collections

disjunction

public <E> Collection<E> disjunction(Collection<E> a,
                                     Collection<E> b)
Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collections.

Type Parameters:
E - the type of the elements in the collection
Parameters:
a - the first collection, must be non-null
b - the second collection, must be non-null
Returns:
the symmetric difference of the two collections

reverse

public <E> boolean reverse(List<E> input)
Reverse the order of the elements within a list, so that the last element is moved to the beginning of the list, the next-to-last element to the second position, and so on. The input list is modified in place, so this operation will succeed only if the list is modifiable.

Type Parameters:
E - the type of the elements in the list
Parameters:
input - the list to reverse
Returns:
true if the list was successfully reversed, false otherwise

sort

public <E extends Comparable<E>> boolean sort(List<E> input)
Sort the elements within a list according to their natural order. The input list is modified in place, so this operation will succeed only if the list is modifiable.

Type Parameters:
E - the type of the elements in the list
Parameters:
input - the list to sort
Returns:
true if the list was successfully sorted, false otherwise


Copyright © 2004-2012 XWiki. All Rights Reserved.