Package org.xwiki.velocity.tools
Class CollectionTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- org.apache.velocity.tools.generic.CollectionTool
-
- org.xwiki.velocity.tools.CollectionTool
-
- All Implemented Interfaces:
Serializable
public class CollectionTool extends org.apache.velocity.tools.generic.CollectionTool
Velocity Tool allowing to create various type of collections.- Since:
- 12.1RC1
- Version:
- $Id: 500e8a441ab8e38420b033cb6b1da320541a7402 $
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CollectionTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <E> Collection<E>
disjunction(Collection<E> a, Collection<E> b)
Returns aCollection
containing the exclusive disjunction (symmetric difference) of the givenCollection
s.<E> List<E>
getArrayList()
Create and return a newArrayList
, 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 newBlockingQueue
, 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 newLinkedList
, 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 newMap
, 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 newMap
, 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 newSet
, 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 newQueue
, 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 newQueue
, an unbounded list where items are ordered in a FIFO (first-in-first-out) manner.<E> Set<E>
getSet()
Create and return a newSet
, 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 newSortedMap
, 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 newSortedSet
, 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 aCollection
containing the intersection of the givenCollection
s.<E> boolean
reverseModifiable(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>>
booleansortModifiable(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 aCollection
containing the union of the givenCollection
s.<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 org.apache.velocity.tools.generic.CollectionTool
configure, getComparable, getStringsDelimiter, getStringsTrim, internalSort, setStringsDelimiter, setStringsTrim, sort, sort, sort, sort, sort, sort, sort, sort, sort, sort, sort, sort, split
-
-
-
-
Method Detail
-
getArrayList
public <E> List<E> getArrayList()
Create and return a newArrayList
, 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 newLinkedList
, 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 newMap
, 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 mapV
- 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 newSortedMap
, 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 mapV
- the type of mapped values- Returns:
- a new, empty
TreeMap
-
getOrderedMap
public <K,V> Map<K,V> getOrderedMap()
Create and return a newMap
, 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 mapV
- the type of mapped values- Returns:
- a new, empty
LinkedHashMap
-
getSet
public <E> Set<E> getSet()
Create and return a newSet
, 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 newSortedSet
, 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 newSet
, 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 newQueue
, 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 newBlockingQueue
, 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 newQueue
, 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 mapV
- 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 aCollection
containing the union of the givenCollection
s.- Type Parameters:
E
- the type of the elements in the collection- Parameters:
a
- the first collection, must be non-nullb
- 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 aCollection
containing the intersection of the givenCollection
s.- Type Parameters:
E
- the type of the elements in the collection- Parameters:
a
- the first collection, must be non-nullb
- 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 aCollection
containing the exclusive disjunction (symmetric difference) of the givenCollection
s.- Type Parameters:
E
- the type of the elements in the collection- Parameters:
a
- the first collection, must be non-nullb
- the second collection, must be non-null- Returns:
- the symmetric difference of the two collections
-
reverseModifiable
public <E> boolean reverseModifiable(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
-
sortModifiable
public <E extends Comparable<E>> boolean sortModifiable(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
-
-