org.norther.tammi.acorn.util
Class Collections

java.lang.Object
  extended by org.norther.tammi.acorn.util.Collections

public abstract class Collections
extends Object

Collection utilities.

Author:
Ilkka Priha

Field Summary
static Comparator ALPHA_NUMERIC_COMPARATOR
          An alpha-numeric comparator.
static Comparator DEFAULT_COMPARATOR
          A default comparator.
static Enumeration EMPTY_ENUMERATION
          An empty unmodifiable enumeration.
static Iterator EMPTY_ITERATOR
          An empty unmodifiable iterator.
static List EMPTY_LIST
          An empty unmodifiable list.
static ListIterator EMPTY_LIST_ITERATOR
          An empty unmodifiable list iterator.
static OrderedMap EMPTY_MAP
          An empty unmodifiable map.
static OrderedSet EMPTY_SET
          An empty unmodifiable set.
static Comparator REVERSE_COMPARATOR
          A reverse comparator.
 
Constructor Summary
Collections()
           
 
Method Summary
static void append(Map source, Map target, boolean noDuplicates)
          Appends a map to another one.
static int indexOf(Object source, Object object)
          Gets the index of the specified object in the source.
static int indexOf(Object source, Object object, int fromIndex, int toIndex)
          Gets the index of the specified object within the specified range of the source.
static void insert(Map source, int index, Map target, boolean noDuplicates)
          Inserts a map into another one.
static int[] order(Object source)
          Orders the specified source into ascending order and returns the new order as an array of indeces.
static int[] order(Object source, boolean reverse)
          Orders the specified source into ascending or descending order and returns the new order as an array of indeces.
static int[] order(Object source, Comparator comp)
          Orders the specified source to the order induced by the specified comparator and returns the new order as an array of indeces.
static Object sort(Object source)
          Sorts the specified source into ascending order.
static Object sort(Object source, Comparator comp)
          Sorts the specified source to the order induced by the specified comparator.
static Object sort(Object source, int[] order)
          Sorts the specified source into the specified order.
static Object sort(Object array, int fromIndex, int toIndex)
          Sorts the specified range of the specified array into ascending order.
static boolean subset(String prefix, String delims, boolean plainKeysOnly, boolean absentKeysOnly, Map source, ConcurrentMap subset)
          Collects a subset of the given map from key-value pairs having the specified prefix and optionally absent in the subset.
static boolean subset(String prefix, String delims, boolean plainKeysOnly, Map source, Map subset)
          Collects a subset of the given map from key-value pairs having the specified prefix.
static boolean subset(String prefix, String delims, Map source)
          Collects a subset of the given map by removing key-value pairs having the specified prefix.
static boolean subset(String prefix, String delims, Map source, Map subset)
          Collects a subset of the given map from key-value pairs having the specified prefix.
static boolean subset(String prefix, String suffix, String delims, boolean plainKeysOnly, boolean absentKeysOnly, Map source, ConcurrentMap subset)
          Collects a subset of the given map from key-value pairs having the specified prefix and/or suffix and optionally absent in the subset.
static boolean subset(String prefix, String suffix, String delims, boolean plainKeysOnly, Map source, Map subset)
          Collects a subset of the given map from key-value pairs having the specified prefix and/or suffix.
static boolean subset(String prefix, String suffix, String delims, Map source)
          Collects a subset of the given map by removing key-value pairs having the specified prefix and/or suffix.
static boolean subset(String prefix, String suffix, String delims, Map source, Map subset)
          Collects a subset of the given map from key-value pairs having the specified prefix and/or suffix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_LIST

public static final List EMPTY_LIST
An empty unmodifiable list.


EMPTY_SET

public static final OrderedSet EMPTY_SET
An empty unmodifiable set.


EMPTY_MAP

public static final OrderedMap EMPTY_MAP
An empty unmodifiable map.


EMPTY_ITERATOR

public static final Iterator EMPTY_ITERATOR
An empty unmodifiable iterator.


EMPTY_LIST_ITERATOR

public static final ListIterator EMPTY_LIST_ITERATOR
An empty unmodifiable list iterator.


EMPTY_ENUMERATION

public static final Enumeration EMPTY_ENUMERATION
An empty unmodifiable enumeration.


DEFAULT_COMPARATOR

public static final Comparator DEFAULT_COMPARATOR
A default comparator.


REVERSE_COMPARATOR

public static final Comparator REVERSE_COMPARATOR
A reverse comparator.


ALPHA_NUMERIC_COMPARATOR

public static final Comparator ALPHA_NUMERIC_COMPARATOR
An alpha-numeric comparator.

Constructor Detail

Collections

public Collections()
Method Detail

indexOf

public static int indexOf(Object source,
                          Object object)
Gets the index of the specified object in the source. The source can be any array, List, OrderedSet or OrderedMap.

Parameters:
source - the source.
object - the object.
Returns:
the found index or -1.

indexOf

public static int indexOf(Object source,
                          Object object,
                          int fromIndex,
                          int toIndex)
Gets the index of the specified object within the specified range of the source. The source can be any array, List, OrderedSet or OrderedMap.

Parameters:
source - the source.
object - the object.
fromIndex - the index to start from, inclusive.
toIndex - the index to end to, exclusive.
Returns:
the found index or -1.

sort

public static Object sort(Object source)
Sorts the specified source into ascending order. The source can be any array, List, Map or Collection. Arrays and lists are sorted in place, others in an appropriate new collection.

Parameters:
source - the source to sort.
Returns:
the sorted source.

sort

public static Object sort(Object source,
                          Comparator comp)
Sorts the specified source to the order induced by the specified comparator. The source can be any array, List, Map or Collection. Arrays and lists are sorted in place, others in an appropriate new collection.

Note that primitive arrays are converted to the corresponding object arrays.

Parameters:
source - the source to sort.
comp - the comparator.
Returns:
the sorted source.

sort

public static Object sort(Object array,
                          int fromIndex,
                          int toIndex)
Sorts the specified range of the specified array into ascending order. The array is sorted in place and the original array returned.

Parameters:
array - the array to sort.
fromIndex - the index to start from, inclusive.
toIndex - the index to end to, exclusive.
Returns:
the original array sorted in place.

sort

public static Object sort(Object source,
                          int[] order)
Sorts the specified source into the specified order. The source can be any array, List, Map or Collection. Arrays, lists and sorted maps are sorted in place, others in an appropriate new collection.

Parameters:
source - the source to sort.
order - an array of ordered indeces.
Returns:
the sorted source.

order

public static int[] order(Object source)
Orders the specified source into ascending order and returns the new order as an array of indeces. The source can be any array, List, Map or Collection. The original source remains intact.

Parameters:
source - the source to order.
Returns:
an array of ordered indeces.

order

public static int[] order(Object source,
                          boolean reverse)
Orders the specified source into ascending or descending order and returns the new order as an array of indeces. The source can be any array, List, Map or Collection. The original source remains intact.

Parameters:
source - the source to order.
reverse - true for reversed order.
Returns:
an array of ordered indeces.

order

public static int[] order(Object source,
                          Comparator comp)
Orders the specified source to the order induced by the specified comparator and returns the new order as an array of indeces. The source can be any array, List, Map or Collection. The original source remains intact.

Parameters:
source - the source to order.
comp - the comparator.
Returns:
an array of ordered indeces.

append

public static void append(Map source,
                          Map target,
                          boolean noDuplicates)
Appends a map to another one. If both contain the same key, an array containing both values is added. If either or both values are arrays, they will be merged. The values of the target map come always first.

Parameters:
source - the source map.
target - the destination map.
noDuplicates - true to remove duplicates, false otherwise.

insert

public static void insert(Map source,
                          int index,
                          Map target,
                          boolean noDuplicates)
Inserts a map into another one. If both contain the same key, an array containing both values is added. If either or both values are arrays, they will be merged. The values of the source map are located at the specified index of the values of the second one (-1 at the end).

Parameters:
source - the source map.
index - the index.
target - the target map.
noDuplicates - true to remove duplicates, false otherwise.

subset

public static boolean subset(String prefix,
                             String delims,
                             Map source)
Collects a subset of the given map by removing key-value pairs having the specified prefix.

Parameters:
prefix - a key prefix (may be null).
delims - key delimiters (may be null).
source - the source map.
Returns:
false for an unmodified subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String suffix,
                             String delims,
                             Map source)
Collects a subset of the given map by removing key-value pairs having the specified prefix and/or suffix.

Parameters:
prefix - a key prefix (may be null).
suffix - a key suffix (may be null).
delims - key delimiters (may be null).
source - the source map.
Returns:
false for an unmodified subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String delims,
                             Map source,
                             Map subset)
Collects a subset of the given map from key-value pairs having the specified prefix. The prefix is removed from keys in the subset.

Parameters:
prefix - a key prefix (may be null).
delims - key delimiters (may be null).
source - the source map.
subset - the target map.
Returns:
false for an empty subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String suffix,
                             String delims,
                             Map source,
                             Map subset)
Collects a subset of the given map from key-value pairs having the specified prefix and/or suffix. The prefix and suffix are removed from keys in the subset.

Parameters:
prefix - a key prefix (may be null).
suffix - a key suffix (may be null).
delims - key delimiters (may be null).
source - the source map.
subset - the target map.
Returns:
false for an empty subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String delims,
                             boolean plainKeysOnly,
                             Map source,
                             Map subset)
Collects a subset of the given map from key-value pairs having the specified prefix. The prefix is removed from keys in the subset. Subkeys, which are not plain names, may optionally be omitted.

Parameters:
prefix - a key prefix (may be null).
delims - key delimiters(may be null).
plainKeysOnly - true to accept keys without delimiters only.
source - the source map.
subset - the target map.
Returns:
false for an empty subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String suffix,
                             String delims,
                             boolean plainKeysOnly,
                             Map source,
                             Map subset)
Collects a subset of the given map from key-value pairs having the specified prefix and/or suffix. The prefix and suffix are removed from keys in the subset. Subkeys, which are not plain names, may optionally be omitted.

Parameters:
prefix - a key prefix (may be null).
suffix - a key suffix (may be null).
delims - key delimiters (may be null).
plainKeysOnly - true to accept keys without delimiters only.
source - the source map.
subset - the target map.
Returns:
false for an empty subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String delims,
                             boolean plainKeysOnly,
                             boolean absentKeysOnly,
                             Map source,
                             ConcurrentMap subset)
Collects a subset of the given map from key-value pairs having the specified prefix and optionally absent in the subset. The prefix is removed from keys in the subset. Subkeys, which are not plain names, may optionally be omitted.

Parameters:
prefix - a key prefix (may be null).
delims - key delimiters (may be null).
plainKeysOnly - true to accept keys without delimiters only.
absentKeysOnly - true to accept keys absent in the subset only.
source - the source map.
subset - the target map.
Returns:
false for an empty subset, true otherwise.

subset

public static boolean subset(String prefix,
                             String suffix,
                             String delims,
                             boolean plainKeysOnly,
                             boolean absentKeysOnly,
                             Map source,
                             ConcurrentMap subset)
Collects a subset of the given map from key-value pairs having the specified prefix and/or suffix and optionally absent in the subset. The prefix and suffix are removed from keys in the subset. Subkeys, which are not plain names, may optionally be omitted.

Parameters:
prefix - a key prefix (may be null).
suffix - a key suffix (may be null).
delims - key delimiters (may be null).
plainKeysOnly - true to accept keys without delimiters only.
absentKeysOnly - true to accept keys absent in the subset only.
source - the source map.
subset - the target map.
Returns:
false for an empty subset, true otherwise.


Copyright © 2004 The Norther Organization. All rights reserved.