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

com.autonomousapps.internal.utils.comparators.kt Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.autonomousapps.internal.utils

internal class LexicographicIterableComparator> : Comparator> {
  override fun compare(left: Iterable?, right: Iterable?): Int {
    if (left === right) return 0
    if (left == null || right == null) return if (left == null) -1 else 1

    val leftIterator = left.iterator()
    val rightIterator = right.iterator()

    while (leftIterator.hasNext() && rightIterator.hasNext()) {
      val compareResult = leftIterator.next().compareTo(rightIterator.next())
      if (compareResult != 0) {
        return compareResult
      }
    }

    if (leftIterator.hasNext()) return 1
    if (rightIterator.hasNext()) return -1

    return 0
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy