tests changed

val hasNext -> fun hasNext()
This commit is contained in:
Svetlana Isakova
2012-08-14 14:47:04 +04:00
parent f96fe4879a
commit e1281953e7
20 changed files with 42 additions and 48 deletions
@@ -155,12 +155,12 @@ public inline fun <T> Array<T>.foldRight(initial: T, operation: (T, T) -> T): T
*/
public inline fun <T> Array<T>.reduce(operation: (T, T) -> T): T {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun BooleanArray.foldRight(initial: Boolean, operation: (Boolean,
*/
public inline fun BooleanArray.reduce(operation: (Boolean, Boolean) -> Boolean): Boolean {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Boolean = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun ByteArray.foldRight(initial: Byte, operation: (Byte, Byte) ->
*/
public inline fun ByteArray.reduce(operation: (Byte, Byte) -> Byte): Byte {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Byte = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun CharArray.foldRight(initial: Char, operation: (Char, Char) ->
*/
public inline fun CharArray.reduce(operation: (Char, Char) -> Char): Char {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Char = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun DoubleArray.foldRight(initial: Double, operation: (Double, Dou
*/
public inline fun DoubleArray.reduce(operation: (Double, Double) -> Double): Double {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Double = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun FloatArray.foldRight(initial: Float, operation: (Float, Float)
*/
public inline fun FloatArray.reduce(operation: (Float, Float) -> Float): Float {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Float = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun IntArray.foldRight(initial: Int, operation: (Int, Int) -> Int)
*/
public inline fun IntArray.reduce(operation: (Int, Int) -> Int): Int {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Int = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun LongArray.foldRight(initial: Long, operation: (Long, Long) ->
*/
public inline fun LongArray.reduce(operation: (Long, Long) -> Long): Long {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Long = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
@@ -155,12 +155,12 @@ public inline fun ShortArray.foldRight(initial: Short, operation: (Short, Short)
*/
public inline fun ShortArray.reduce(operation: (Short, Short) -> Short): Short {
val iterator = this.iterator().sure()
if (!iterator.hasNext) {
if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced")
}
var result: Short = iterator.next() //compiler doesn't understand that result will initialized anyway
while (iterator.hasNext) {
while (iterator.hasNext()) {
result = operation(result, iterator.next())
}
+1 -2
View File
@@ -38,8 +38,7 @@ public inline fun CharSequence.iterator() : CharIterator = object: jet.CharItera
public override fun nextChar(): Char = get(index++)
public override val hasNext: Boolean
get() = index < length
public override fun hasNext(): Boolean = index < length
}
/** Returns the string if it is not null or the empty string if its null */
@@ -35,8 +35,7 @@ abstract class FunctionalList<T>(public val size: Int) {
return head
}
override val hasNext: Boolean
get() = !cur.empty
override fun hasNext(): Boolean = !cur.empty
}
class object {
+4 -6
View File
@@ -172,8 +172,7 @@ public inline fun <T: Closeable, R> T.use(block: (T)-> R) : R {
/** Returns an [Iterator] of bytes over an input stream */
public fun InputStream.iterator() : ByteIterator =
object: ByteIterator() {
override val hasNext : Boolean
get() = available() > 0
override fun hasNext() : Boolean = available() > 0
public override fun nextByte() : Byte = read().toByte()
}
@@ -215,7 +214,7 @@ public inline fun Writer.buffered(bufferSize: Int = defaultBufferSize): Buffered
public inline fun Reader.forEachLine(block: (String) -> Any): Unit {
this.use{
val iter = buffered().lineIterator()
while (iter.hasNext) {
while (iter.hasNext()) {
val elem = iter.next()
block(elem)
}
@@ -238,8 +237,7 @@ class LineIterator(val reader: BufferedReader) : Iterator<String> {
private var nextValue: String? = null
private var done = false
override val hasNext: Boolean
get() {
override fun hasNext(): Boolean {
if (nextValue == null && !done) {
nextValue = reader.readLine()
if (nextValue == null) done = true
@@ -248,7 +246,7 @@ class LineIterator(val reader: BufferedReader) : Iterator<String> {
}
public override fun next(): String {
if (!hasNext) {
if (!hasNext()) {
throw NoSuchElementException()
}
val answer = nextValue