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
+9 -9
View File
@@ -33,7 +33,7 @@ public abstract trait jet.BooleanIterable : jet.Iterable<jet.Boolean> {
} }
public abstract class jet.BooleanIterator : jet.Iterator<jet.Boolean> { public abstract class jet.BooleanIterator : jet.Iterator<jet.Boolean> {
public final /*constructor*/ fun <init>(): jet.BooleanIterator public final /*constructor*/ fun <init>(): jet.BooleanIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Boolean public open override /*1*/ fun next(): jet.Boolean
public abstract fun nextBoolean(): jet.Boolean public abstract fun nextBoolean(): jet.Boolean
} }
@@ -115,7 +115,7 @@ public abstract trait jet.ByteIterable : jet.Iterable<jet.Byte> {
} }
public abstract class jet.ByteIterator : jet.Iterator<jet.Byte> { public abstract class jet.ByteIterator : jet.Iterator<jet.Byte> {
public final /*constructor*/ fun <init>(): jet.ByteIterator public final /*constructor*/ fun <init>(): jet.ByteIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Byte public open override /*1*/ fun next(): jet.Byte
public abstract fun nextByte(): jet.Byte public abstract fun nextByte(): jet.Byte
} }
@@ -208,7 +208,7 @@ public abstract trait jet.CharIterable : jet.Iterable<jet.Char> {
} }
public abstract class jet.CharIterator : jet.Iterator<jet.Char> { public abstract class jet.CharIterator : jet.Iterator<jet.Char> {
public final /*constructor*/ fun <init>(): jet.CharIterator public final /*constructor*/ fun <init>(): jet.CharIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Char public open override /*1*/ fun next(): jet.Char
public abstract fun nextChar(): jet.Char public abstract fun nextChar(): jet.Char
} }
@@ -312,7 +312,7 @@ public abstract trait jet.DoubleIterable : jet.Iterable<jet.Double> {
} }
public abstract class jet.DoubleIterator : jet.Iterator<jet.Double> { public abstract class jet.DoubleIterator : jet.Iterator<jet.Double> {
public final /*constructor*/ fun <init>(): jet.DoubleIterator public final /*constructor*/ fun <init>(): jet.DoubleIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Double public open override /*1*/ fun next(): jet.Double
public abstract fun nextDouble(): jet.Double public abstract fun nextDouble(): jet.Double
} }
@@ -504,7 +504,7 @@ public abstract trait jet.FloatIterable : jet.Iterable<jet.Float> {
} }
public abstract class jet.FloatIterator : jet.Iterator<jet.Float> { public abstract class jet.FloatIterator : jet.Iterator<jet.Float> {
public final /*constructor*/ fun <init>(): jet.FloatIterator public final /*constructor*/ fun <init>(): jet.FloatIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Float public open override /*1*/ fun next(): jet.Float
public abstract fun nextFloat(): jet.Float public abstract fun nextFloat(): jet.Float
} }
@@ -702,7 +702,7 @@ public abstract trait jet.IntIterable : jet.Iterable<jet.Int> {
} }
public abstract class jet.IntIterator : jet.Iterator<jet.Int> { public abstract class jet.IntIterator : jet.Iterator<jet.Int> {
public final /*constructor*/ fun <init>(): jet.IntIterator public final /*constructor*/ fun <init>(): jet.IntIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Int public open override /*1*/ fun next(): jet.Int
public abstract fun nextInt(): jet.Int public abstract fun nextInt(): jet.Int
} }
@@ -725,7 +725,7 @@ public abstract trait jet.Iterable</*0*/ out T : jet.Any?> : jet.Any {
public abstract fun iterator(): jet.Iterator<T> public abstract fun iterator(): jet.Iterator<T>
} }
public abstract trait jet.Iterator</*0*/ out T : jet.Any?> : jet.Any { public abstract trait jet.Iterator</*0*/ out T : jet.Any?> : jet.Any {
public abstract val hasNext: jet.Boolean public abstract fun hasNext(): jet.Boolean
public abstract fun next(): T public abstract fun next(): T
} }
public final class jet.Long : jet.Number, jet.Comparable<jet.Long> { public final class jet.Long : jet.Number, jet.Comparable<jet.Long> {
@@ -813,7 +813,7 @@ public abstract trait jet.LongIterable : jet.Iterable<jet.Long> {
} }
public abstract class jet.LongIterator : jet.Iterator<jet.Long> { public abstract class jet.LongIterator : jet.Iterator<jet.Long> {
public final /*constructor*/ fun <init>(): jet.LongIterator public final /*constructor*/ fun <init>(): jet.LongIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Long public open override /*1*/ fun next(): jet.Long
public abstract fun nextLong(): jet.Long public abstract fun nextLong(): jet.Long
} }
@@ -928,7 +928,7 @@ public abstract trait jet.ShortIterable : jet.Iterable<jet.Short> {
} }
public abstract class jet.ShortIterator : jet.Iterator<jet.Short> { public abstract class jet.ShortIterator : jet.Iterator<jet.Short> {
public final /*constructor*/ fun <init>(): jet.ShortIterator public final /*constructor*/ fun <init>(): jet.ShortIterator
public abstract override /*1*/ val hasNext: jet.Boolean public abstract override /*1*/ fun hasNext(): jet.Boolean
public open override /*1*/ fun next(): jet.Short public open override /*1*/ fun next(): jet.Short
public abstract fun nextShort(): jet.Short public abstract fun nextShort(): jet.Short
} }
@@ -99,7 +99,7 @@ fun <T> List<T>.backwards() : Iterable<T> = object : Iterable<T> {
object : jet.Iterator<T> { object : jet.Iterator<T> {
var current = size() var current = size()
override fun next() : T = get(--current) override fun next() : T = get(--current)
override val hasNext : Boolean get() = current > 0 override fun hasNext() : Boolean = current > 0
} }
} }
@@ -21,7 +21,7 @@ class MyIterable<T> : Iterable<T>
class MyIterator : Iterator<T> class MyIterator : Iterator<T>
{ {
override val hasNext: Boolean = false override fun hasNext(): Boolean = false
override fun next(): T { override fun next(): T {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
@@ -1,8 +1,7 @@
import java.util.Enumeration import java.util.Enumeration
inline fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> { inline fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> {
override val hasNext: Boolean override fun hasNext(): Boolean = hasMoreElements()
get() = hasMoreElements()
override fun next() = nextElement() override fun next() = nextElement()
} }
@@ -1,8 +1,7 @@
import java.util.Enumeration import java.util.Enumeration
inline fun <T> java.util.Enumeration<T>.iterator() = object : Iterator<T> { inline fun <T> java.util.Enumeration<T>.iterator() = object : Iterator<T> {
public override val hasNext: Boolean public override fun hasNext(): Boolean = hasMoreElements()
get() = hasMoreElements()
public override fun next() = nextElement() public override fun next() = nextElement()
} }
@@ -5,11 +5,11 @@
import java.util.* import java.util.*
import jet.Iterator import jet.Iterator
fun <T> Iterator<T>.foreach(operation: (element: T) -> Unit) : Unit = while(hasNext) operation(next()) fun <T> Iterator<T>.foreach(operation: (element: T) -> Unit) : Unit = while(hasNext()) operation(next())
fun <T> Iterator<T>.foreach(operation: (index: Int, element: T) -> Unit) : Unit { fun <T> Iterator<T>.foreach(operation: (index: Int, element: T) -> Unit) : Unit {
var k = 0 var k = 0
while(hasNext) while(hasNext())
operation(k++, next()) operation(k++, next())
} }
@@ -6,7 +6,7 @@ import java.util.*
import jet.Iterator import jet.Iterator
fun <T, U: Collection<in T>> Iterator<T>.to(container: U) : U { fun <T, U: Collection<in T>> Iterator<T>.to(container: U) : U {
while(hasNext) while(hasNext())
container.add(next()) container.add(next())
return container return container
} }
@@ -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 { public inline fun <T> Array<T>.reduce(operation: (T, T) -> T): T {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: T = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun BooleanArray.reduce(operation: (Boolean, Boolean) -> Boolean): Boolean {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Boolean = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun ByteArray.reduce(operation: (Byte, Byte) -> Byte): Byte {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Byte = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun CharArray.reduce(operation: (Char, Char) -> Char): Char {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Char = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun DoubleArray.reduce(operation: (Double, Double) -> Double): Double {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Double = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun FloatArray.reduce(operation: (Float, Float) -> Float): Float {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Float = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun IntArray.reduce(operation: (Int, Int) -> Int): Int {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Int = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun LongArray.reduce(operation: (Long, Long) -> Long): Long {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Long = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 { public inline fun ShortArray.reduce(operation: (Short, Short) -> Short): Short {
val iterator = this.iterator().sure() val iterator = this.iterator().sure()
if (!iterator.hasNext) { if (!iterator.hasNext()) {
throw UnsupportedOperationException("Empty iterable can't be reduced") throw UnsupportedOperationException("Empty iterable can't be reduced")
} }
var result: Short = iterator.next() //compiler doesn't understand that result will initialized anyway 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()) 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 fun nextChar(): Char = get(index++)
public override val hasNext: Boolean public override fun hasNext(): Boolean = index < length
get() = index < length
} }
/** Returns the string if it is not null or the empty string if its null */ /** 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 return head
} }
override val hasNext: Boolean override fun hasNext(): Boolean = !cur.empty
get() = !cur.empty
} }
class object { 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 */ /** Returns an [Iterator] of bytes over an input stream */
public fun InputStream.iterator() : ByteIterator = public fun InputStream.iterator() : ByteIterator =
object: ByteIterator() { object: ByteIterator() {
override val hasNext : Boolean override fun hasNext() : Boolean = available() > 0
get() = available() > 0
public override fun nextByte() : Byte = read().toByte() 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 { public inline fun Reader.forEachLine(block: (String) -> Any): Unit {
this.use{ this.use{
val iter = buffered().lineIterator() val iter = buffered().lineIterator()
while (iter.hasNext) { while (iter.hasNext()) {
val elem = iter.next() val elem = iter.next()
block(elem) block(elem)
} }
@@ -238,8 +237,7 @@ class LineIterator(val reader: BufferedReader) : Iterator<String> {
private var nextValue: String? = null private var nextValue: String? = null
private var done = false private var done = false
override val hasNext: Boolean override fun hasNext(): Boolean {
get() {
if (nextValue == null && !done) { if (nextValue == null && !done) {
nextValue = reader.readLine() nextValue = reader.readLine()
if (nextValue == null) done = true if (nextValue == null) done = true
@@ -248,7 +246,7 @@ class LineIterator(val reader: BufferedReader) : Iterator<String> {
} }
public override fun next(): String { public override fun next(): String {
if (!hasNext) { if (!hasNext()) {
throw NoSuchElementException() throw NoSuchElementException()
} }
val answer = nextValue val answer = nextValue
+2 -2
View File
@@ -5,12 +5,12 @@ import org.junit.Test as test
fun <T> checkContent(val iter : Iterator<T>, val length : Int, val value : (Int) -> T) { fun <T> checkContent(val iter : Iterator<T>, val length : Int, val value : (Int) -> T) {
var idx = 0 var idx = 0
while (idx != length && iter.hasNext) { while (idx != length && iter.hasNext()) {
assertEquals(value(idx++), iter.next(), "Invalid element") assertEquals(value(idx++), iter.next(), "Invalid element")
} }
assertEquals(length, idx, "Invalid length") assertEquals(length, idx, "Invalid length")
assertFalse(iter.hasNext, "Invalid length (hasNext)") assertFalse(iter.hasNext(), "Invalid length (hasNext())")
} }
class ArraysTest { class ArraysTest {