moved the Map<String,String>.toProperties() helper function into the standard library and added a test case

This commit is contained in:
James Strachan
2012-08-02 11:57:12 +01:00
parent 94cdbb0f08
commit 137eee3f45
3 changed files with 22 additions and 10 deletions
@@ -7,6 +7,7 @@ import java.util.Map
import java.util.Map.Entry as JEntry
import java.util.SortedMap
import java.util.TreeMap
import java.util.Properties
// Map APIs
@@ -31,6 +32,19 @@ public inline fun <K,V> java.util.Map<K,V>.toSortedMap(): SortedMap<K,V> = toMap
public inline fun <K,V> java.util.Map<K,V>.toSortedMap(comparator: Comparator<K>): SortedMap<K,V> = toMap<K,V>(TreeMap(comparator)) as SortedMap<K,V>
/**
* Converts this [[Map]] to a [[Properties]] object
*
* @includeFunctionBody ../../test/MapTest.kt toProperties
*/
public inline fun Map<String, String>.toProperties(): Properties {
val answer = Properties()
for (e in this) {
answer.put(e.key, e.value)
}
return answer
}
/**
* Returns a new List containing the results of applying the given *transform* function to each [[Map.Entry]] in this [[Map]]
*