added some missing sortedSet() methods and kept simpler naming convention of (sorted|Linked)(Map|Set)() for functions to create linked/sorted map/set

This commit is contained in:
James Strachan
2012-04-16 19:48:05 +01:00
parent cabaeab972
commit 89eb7ba4ac
2 changed files with 22 additions and 7 deletions
+8 -1
View File
@@ -20,9 +20,16 @@ public inline fun linkedList<T>(vararg values: T) : LinkedList<T> = values.to(L
/** Returns a new HashSet with a variable number of initial elements */
public inline fun hashSet<T>(vararg values: T) : HashSet<T> = values.to(HashSet<T>(values.size))
/** Returns a new SortedSet with a variable number of initial elements */
/**
* Returns a new [[SortedSet]] with the initial elements
*/
public inline fun sortedSet<T>(vararg values: T) : TreeSet<T> = values.to(TreeSet<T>())
/**
* Returns a new [[SortedSet]] with the given *comparator* and the initial elements
*/
public inline fun sortedSet<T>(comparator: Comparator<T>, vararg values: T) : TreeSet<T> = values.to(TreeSet<T>(comparator))
/**
* Returns a new [[HashMap]] populated with the given tuple values where the first value in each tuple
* is the key and the second value is the value
+14 -6
View File
@@ -6,6 +6,8 @@ import java.util.LinkedList
import java.util.HashSet
import java.util.LinkedHashSet
import java.util.TreeSet
import java.util.SortedSet
import java.util.Comparator
/**
Helper to make jet.Iterator usable in for
@@ -56,14 +58,20 @@ Add iterated elements to java.util.HashSet
public inline fun <T> Iterator<T>.toHashSet() : HashSet<T> = to(HashSet<T>())
/**
Add iterated elements to java.util.LinkedHashSet
*/
public inline fun <T> Iterator<T>.toLinkedHashSet() : LinkedHashSet<T> = to(LinkedHashSet<T>())
* Add iterated elements to a [[LinkedHashSet]] to preserve insertion order
*/
public inline fun <T> Iterator<T>.toLinkedSet() : LinkedHashSet<T> = to(LinkedHashSet<T>())
/**
Add iterated elements to java.util.TreeSet
*/
public inline fun <T> Iterator<T>.toTreeSet() : TreeSet<T> = to(TreeSet<T>())
* Add iterated elements to [[SortedSet]] to ensure iteration is in the order of the default comparator
* for the type
*/
public inline fun <T> Iterator<T>.toSortedSet() : SortedSet<T> = to(TreeSet<T>())
/**
* Add iterated elements to [[SortedSet]] with the given *comparator* to ensure iteration is in the order of the given comparator
*/
public inline fun <T> Iterator<T>.toSortedSet(comparator: Comparator<T>) : SortedSet<T> = to(TreeSet<T>(comparator))
/**
Run function f