All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.collections.MapsJVM.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
package kotlin

import java.util.Comparator
import java.util.LinkedHashMap
import java.util.SortedMap
import java.util.TreeMap
import java.util.Properties

// Map APIs

/**
 * Converts this [[Map]] to a [[LinkedHashMap]] so future insertion orders are maintained
 */
public fun  Map.toLinkedMap(): LinkedHashMap = toMap(LinkedHashMap(size)) as LinkedHashMap

/**
 * Converts this [[Map]] to a [[SortedMap]] so iteration order will be in key order
 *
 * @includeFunctionBody ../../test/collections/MapTest.kt toSortedMap
 */
public fun  Map.toSortedMap(): SortedMap = toMap(TreeMap()) as SortedMap

/**
 * Converts this [[Map]] to a [[SortedMap]] using the given *comparator* so that iteration order will be in the order
 * defined by the comparator
 *
 * @includeFunctionBody ../../test/collections/MapTest.kt toSortedMapWithComparator
 */
public fun  Map.toSortedMap(comparator: Comparator): SortedMap = toMap(TreeMap(comparator)) as SortedMap


/**
 * Converts this [[Map]] to a [[Properties]] object
 *
 * @includeFunctionBody ../../test/collections/MapTest.kt toProperties
 */
public fun Map.toProperties(): Properties {
    val answer = Properties()
    for (e in this) {
        answer.put(e.key, e.value)
    }
    return answer
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy