1 /*
2  * Copyright 2016-2019 JetBrains s.r.o.
3  * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4  */
5 
6 package androidx.compose.runtime.external.kotlinx.collections.immutable.internal
7 
8 import kotlin.jvm.JvmStatic
9 
10 internal object ListImplementation {
11 
12     @JvmStatic
checkElementIndexnull13     internal fun checkElementIndex(index: Int, size: Int) {
14         if (index < 0 || index >= size) {
15             throw IndexOutOfBoundsException("index: $index, size: $size")
16         }
17     }
18 
19     @JvmStatic
checkPositionIndexnull20     internal fun checkPositionIndex(index: Int, size: Int) {
21         if (index < 0 || index > size) {
22             throw IndexOutOfBoundsException("index: $index, size: $size")
23         }
24     }
25 
26     @JvmStatic
checkRangeIndexesnull27     internal fun checkRangeIndexes(fromIndex: Int, toIndex: Int, size: Int) {
28         if (fromIndex < 0 || toIndex > size) {
29             throw IndexOutOfBoundsException("fromIndex: $fromIndex, toIndex: $toIndex, size: $size")
30         }
31         if (fromIndex > toIndex) {
32             throw IllegalArgumentException("fromIndex: $fromIndex > toIndex: $toIndex")
33         }
34     }
35 
36     @JvmStatic
orderedHashCodenull37     internal fun orderedHashCode(c: Collection<*>): Int {
38         var hashCode = 1
39         for (e in c) {
40             hashCode = 31 * hashCode + (e?.hashCode() ?: 0)
41         }
42         return hashCode
43     }
44 
45     @JvmStatic
orderedEqualsnull46     internal fun orderedEquals(c: Collection<*>, other: Collection<*>): Boolean {
47         if (c.size != other.size) return false
48 
49         val otherIterator = other.iterator()
50         for (elem in c) {
51             val elemOther = otherIterator.next()
52             if (elem != elemOther) {
53                 return false
54             }
55         }
56         return true
57     }
58 }