Author: david.lloyd(a)jboss.com
Date: 2008-10-17 00:10:05 -0400 (Fri, 17 Oct 2008)
New Revision: 4599
Modified:
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java
Log:
javadocs
Modified: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java 2008-10-14
06:04:22 UTC (rev 4598)
+++
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java 2008-10-17
04:10:05 UTC (rev 4599)
@@ -32,6 +32,12 @@
private CollectionUtil() {
}
+ /**
+ * Create an enum map for the given key type.
+ *
+ * @param keyType the key type
+ * @return the new map
+ */
public static <K extends Enum<K>, V> EnumMap<K, V>
enumMap(Class<K> keyType) {
return new EnumMap<K, V>(keyType);
}
@@ -63,6 +69,11 @@
return new ConcurrentReferenceHashMap<K, V>(16, STRONG, WEAK);
}
+ /**
+ * Create a concurrent integer-keyed map.
+ *
+ * @return a concurrent integer-keyed map
+ */
public static <V> ConcurrentIntegerMap<V> concurrentIntegerMap() {
return new EmulatedConcurrentIntegerHashMap<V>(CollectionUtil.<Integer,
V>concurrentMap());
}
@@ -227,6 +238,53 @@
}
/**
+ * Create an immutable map entry.
+ *
+ * @param key the key
+ * @param value the value
+ * @return the entry
+ */
+ public static <K, V> Map.Entry<K, V> entry(final K key, final V value) {
+ return new Map.Entry<K, V>() {
+ public K getKey() {
+ return key;
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public V setValue(final V value) {
+ throw new UnsupportedOperationException("setValue");
+ }
+ };
+ }
+
+ /**
+ * Create a prepopulated hash map. The map will be sized for the number of elements
given.
+ *
+ * @param entries the map entries
+ * @return the prepopulated hash map
+ */
+ public static <K, V> Map<K, V> hashMap(Map.Entry<K, V>... entries)
{
+ final Map<K, V> map = new HashMap<K, V>(entries.length);
+ for (Map.Entry<K,V> e : entries) {
+ map.put(e.getKey(), e.getValue());
+ }
+ return map;
+ }
+
+ /**
+ * Create an unmodifiable prepopulated hash map.
+ *
+ * @param entries the map entries
+ * @return the unmodifiable prepopulated hash map
+ */
+ public static <K, V> Map<K, V> unmodifiableHashMap(Map.Entry<K,
V>... entries) {
+ return Collections.unmodifiableMap(hashMap(entries));
+ }
+
+ /**
* Create an {@code Iterable} view of another {@code Iterable} that exposes no other
methods.
*
* @param original the wrapped instance
@@ -563,6 +621,11 @@
}
}
+ /**
+ * Get the empty iterable.
+ *
+ * @return the empty iterable
+ */
@SuppressWarnings ({"unchecked"})
public static <T> Iterable<T> emptyIterable() {
return (Iterable<T>) EMPTY_ITERABLE;
@@ -576,6 +639,11 @@
}
}
+ /**
+ * Get the empty iterator.
+ *
+ * @return the empty iterator
+ */
@SuppressWarnings ({"unchecked"})
public static <T> Iterator<T> emptyIterator() {
return (Iterator<T>) EMPTY_ITERATOR;
@@ -599,6 +667,12 @@
}
+ /**
+ * Get a reversed view of a list iterator.
+ *
+ * @param original the original iterator
+ * @return the reversed view
+ */
public static <T> ListIterator<T> reverse(ListIterator<T> original)
{
if (original instanceof ReverseListIterator) {
return ((ReverseListIterator<T>)original).original;
@@ -607,6 +681,12 @@
}
}
+ /**
+ * Get an iterable reversed view of a list.
+ *
+ * @param list the list
+ * @return the reversed view
+ */
public static <T> Iterable<T> reverse(final List<T> list) {
return new Iterable<T>() {
public Iterator<T> iterator() {
Show replies by date