Replace for ..-1 with until (#1513)

This commit is contained in:
Ross Nicoll 2017-09-26 13:37:13 +01:00 committed by GitHub
parent 63168c0299
commit e1b040ba0e
4 changed files with 10 additions and 10 deletions

View File

@ -14,11 +14,11 @@ class RepeatingBytesInputStream(val bytesToRepeat: ByteArray, val numberOfBytes:
}
}
override fun read(byteArray: ByteArray, offset: Int, length: Int): Int {
val until = Math.min(Math.min(offset + length, byteArray.size), offset + bytesLeft)
for (i in offset .. until - 1) {
val lastIdx = Math.min(Math.min(offset + length, byteArray.size), offset + bytesLeft)
for (i in offset until lastIdx) {
byteArray[i] = bytesToRepeat[(numberOfBytes - bytesLeft + i - offset) % bytesToRepeat.size]
}
val bytesRead = until - offset
val bytesRead = lastIdx - offset
bytesLeft -= bytesRead
return if (bytesRead == 0 && bytesLeft == 0) -1 else bytesRead
}

View File

@ -613,7 +613,7 @@ class CryptoUtilsTest {
val encodedPrivK1 = privK1.encoded
// fail on malformed key.
for (i in 0..encodedPrivK1.size - 1) {
for (i in 0 until encodedPrivK1.size) {
val b = encodedPrivK1[i]
encodedPrivK1[i] = b.inc()
try {

View File

@ -29,7 +29,7 @@ class LinearInterpolator(private val xs: DoubleArray, private val ys: DoubleArra
require(x > x0) { "Can't interpolate below $x0" }
for (i in 1..xs.size - 1) {
for (i in 1 until xs.size) {
if (xs[i] == x) return xs[i]
else if (xs[i] > x) return interpolateBetween(x, xs[i - 1], xs[i], ys[i - 1], ys[i])
}
@ -78,15 +78,15 @@ class CubicSplineInterpolator(private val xs: DoubleArray, private val ys: Doubl
val h = DoubleArray(n)
val g = DoubleArray(n)
for (i in 0..n - 1)
for (i in 0 until n)
h[i] = xs[i + 1] - xs[i]
for (i in 1..n - 1)
for (i in 1 until n)
g[i] = 3 / h[i] * (ys[i + 1] - ys[i]) - 3 / h[i - 1] * (ys[i] - ys[i - 1])
// Solve tridiagonal linear system (using Crout Factorization)
val m = DoubleArray(n)
val z = DoubleArray(n)
for (i in 1..n - 1) {
for (i in 1 until n) {
val l = 2 * (xs[i + 1] - xs[i - 1]) - h[i - 1] * m[i - 1]
m[i] = h[i] / l
z[i] = (g[i] - h[i - 1] * z[i - 1]) / l
@ -98,7 +98,7 @@ class CubicSplineInterpolator(private val xs: DoubleArray, private val ys: Doubl
}
val segmentMap = TreeMap<Double, Polynomial>()
for (i in 0..n - 1) {
for (i in 0 until n) {
val coefficients = doubleArrayOf(ys[i], b[i], c[i], d[i])
segmentMap.put(xs[i], Polynomial(coefficients))
}

View File

@ -277,7 +277,7 @@ val crossCashTest = LoadTest<CrossCashCommand, CrossCashState>(
minimumMatches.forEach { originator, consumedTxs ->
if (consumedTxs > 0) {
newNodeDiffQueues!!
for (i in 0..consumedTxs - 1) {
for (i in 0 until consumedTxs) {
val (issuer, quantity) = newNodeDiffQueues[originator]!!.removeAt(0)
newNodeVault.put(issuer, (newNodeVault[issuer] ?: 0L) + quantity)
}