kotlin.Comparator

Comparator

typealias Comparator<T> = Comparator<T>

Platform and version requirements: Kotlin 1.1

Functions

compare

abstract fun compare(a: T, b: T): Int

Inherited Functions

equals

open operator fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

hashCode

open fun hashCode(): Int

Returns a hash code value for the object. The general contract of hashCode is:

toString

open fun toString(): String

Returns a string representation of the object.

Extension Functions

reversed

fun <T> Comparator<T>.reversed(): Comparator<T>

Returns a comparator that imposes the reverse ordering of this comparator.

then

infix fun <T> Comparator<T>.then(
    comparator: Comparator<in T>
): Comparator<T>

Combines this comparator and the given comparator such that the latter is applied only when the former considered values equal.

thenBy

fun <T> Comparator<T>.thenBy(
    selector: (T) -> Comparable<*>?
): Comparator<T>

Creates a comparator comparing values after the primary comparator defined them equal. It uses the function to transform value to a Comparable instance for comparison.

fun <T, K> Comparator<T>.thenBy(
    comparator: Comparator<in K>, 
    selector: (T) -> K
): Comparator<T>

Creates a comparator comparing values after the primary comparator defined them equal. It uses the selector function to transform values and then compares them with the given comparator.

thenByDescending

fun <T> Comparator<T>.thenByDescending(
    selector: (T) -> Comparable<*>?
): Comparator<T>

Creates a descending comparator using the primary comparator and the function to transform value to a Comparable instance for comparison.

fun <T, K> Comparator<T>.thenByDescending(
    comparator: Comparator<in K>, 
    selector: (T) -> K
): Comparator<T>

Creates a descending comparator comparing values after the primary comparator defined them equal. It uses the selector function to transform values and then compares them with the given comparator.

thenComparator

fun <T> Comparator<T>.thenComparator(
    comparison: (a: T, b: T) -> Int
): Comparator<T>

Creates a comparator using the primary comparator and function to calculate a result of comparison.

thenDescending

infix fun <T> Comparator<T>.thenDescending(
    comparator: Comparator<in T>
): Comparator<T>

Combines this comparator and the given comparator such that the latter is applied only when the former considered values equal.

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-comparator/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部