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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 abstract fun nextShort(): jet.Short
}
@@ -99,7 +99,7 @@ fun <T> List<T>.backwards() : Iterable<T> = object : Iterable<T> {
object : jet.Iterator<T> {
var current = size()
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>
{
override val hasNext: Boolean = false
override fun hasNext(): Boolean = false
override fun next(): T {
throw UnsupportedOperationException()
}
@@ -1,8 +1,7 @@
import java.util.Enumeration
inline fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> {
override val hasNext: Boolean
get() = hasMoreElements()
override fun hasNext(): Boolean = hasMoreElements()
override fun next() = nextElement()
}
@@ -1,8 +1,7 @@
import java.util.Enumeration
inline fun <T> java.util.Enumeration<T>.iterator() = object : Iterator<T> {
public override val hasNext: Boolean
get() = hasMoreElements()
public override fun hasNext(): Boolean = hasMoreElements()
public override fun next() = nextElement()
}
@@ -5,11 +5,11 @@
import java.util.*
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 {
var k = 0
while(hasNext)
while(hasNext())
operation(k++, next())
}
@@ -6,7 +6,7 @@ import java.util.*
import jet.Iterator
fun <T, U: Collection<in T>> Iterator<T>.to(container: U) : U {
while(hasNext)
while(hasNext())
container.add(next())
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 {
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
+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) {
var idx = 0
while (idx != length && iter.hasNext) {
while (idx != length && iter.hasNext()) {
assertEquals(value(idx++), iter.next(), "Invalid element")
}
assertEquals(length, idx, "Invalid length")
assertFalse(iter.hasNext, "Invalid length (hasNext)")
assertFalse(iter.hasNext(), "Invalid length (hasNext())")
}
class ArraysTest {