primitive iterators
This commit is contained in:
@@ -887,7 +887,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
generateFromResolvedCall(resolvedCall.getThisObject());
|
||||
}
|
||||
else {
|
||||
receiver.put(typeMapper.mapType(((ClassDescriptor)resolvedCall.getResultingDescriptor().getContainingDeclaration()).getDefaultType()), v);
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) resolvedCall.getResultingDescriptor().getContainingDeclaration();
|
||||
if(CodegenUtil.isInterface(containingDeclaration))
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
else
|
||||
receiver.put(typeMapper.mapType(containingDeclaration.getDefaultType()), v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ public class JetTypeMapper {
|
||||
public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/runtime/SharedVar$Char");
|
||||
public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/runtime/SharedVar$Long");
|
||||
public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/runtime/SharedVar$Boolean");
|
||||
public static final Type TYPE_BOOLEAN_ITERATOR = Type.getObjectType("jet/BooleanIterator");
|
||||
public static final Type TYPE_CHAR_ITERATOR = Type.getObjectType("jet/CharIterator");
|
||||
public static final Type TYPE_BYTE_ITERATOR = Type.getObjectType("jet/ByteIterator");
|
||||
public static final Type TYPE_SHORT_ITERATOR = Type.getObjectType("jet/ShortIterator");
|
||||
public static final Type TYPE_INT_ITERATOR = Type.getObjectType("jet/IntIterator");
|
||||
public static final Type TYPE_LONG_ITERATOR = Type.getObjectType("jet/LongIterator");
|
||||
public static final Type TYPE_FLOAT_ITERATOR = Type.getObjectType("jet/FloatIterator");
|
||||
public static final Type TYPE_DOUBLE_ITERATOR = Type.getObjectType("jet/DoubleIterator");
|
||||
|
||||
public JetTypeMapper(JetStandardLibrary standardLibrary, BindingContext bindingContext) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
|
||||
@@ -32,34 +32,42 @@ public class ArrayIterator implements IntrinsicMethod {
|
||||
if(containingDeclaration.equals(standardLibrary.getArray())) {
|
||||
codegen.generateTypeInfo(funDescriptor.getReturnType().getArguments().get(0).getType());
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;Ljet/typeinfo/TypeInfo;)Ljet/Iterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getByteArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([B)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([B)Ljet/ByteIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_BYTE_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getShortArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([S)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([S)Ljet/ShortIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_SHORT_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getIntArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([I)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([I)Ljet/IntIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_INT_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getLongArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([J)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([J)Ljet/LongIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_LONG_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getFloatArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([F)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([F)Ljet/FloatIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_FLOAT_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getDoubleArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([D)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([D)Ljet/DoubleIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_DOUBLE_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getCharArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([C)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([C)Ljet/CharIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_CHAR_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getBooleanArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Z)Ljet/Iterator;");
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Z)Ljet/BooleanIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_BOOLEAN_ITERATOR);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException(containingDeclaration.toString());
|
||||
}
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_ITERATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
||||
*/
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public class KotlinCompiler {
|
||||
private KotlinCompiler() {
|
||||
}
|
||||
|
||||
public static class Arguments {
|
||||
@Argument(value = "output", description = "output directory")
|
||||
public String outputDir;
|
||||
|
||||
@@ -53,6 +53,38 @@ trait Iterator<out T> {
|
||||
val hasNext : Boolean
|
||||
}
|
||||
|
||||
abstract open class ByteIterator : Iterator<Byte> {
|
||||
fun nextByte() : Byte
|
||||
}
|
||||
|
||||
abstract open class ShortIterator : Iterator<Short> {
|
||||
fun nextShort() : Short
|
||||
}
|
||||
|
||||
abstract open class CharIterator : Iterator<Char> {
|
||||
fun nextChar() : Char
|
||||
}
|
||||
|
||||
abstract open class IntIterator : Iterator<Int> {
|
||||
fun nextInt() : Int
|
||||
}
|
||||
|
||||
abstract open class LongIterator : Iterator<Long> {
|
||||
fun nextLong() : Long
|
||||
}
|
||||
|
||||
abstract open class FloatIterator : Iterator<Float> {
|
||||
fun nextFloat() : Float
|
||||
}
|
||||
|
||||
abstract open class DoubleIterator : Iterator<Double> {
|
||||
fun nextDouble() : Double
|
||||
}
|
||||
|
||||
abstract open class BooleanIterator : Iterator<Boolean> {
|
||||
fun nextBoolean() : Boolean
|
||||
}
|
||||
|
||||
trait Iterable<out T> {
|
||||
fun iterator() : Iterator<T>
|
||||
}
|
||||
@@ -70,7 +102,7 @@ class ByteArray(val size : Int) {
|
||||
fun get(index : Int) : Byte
|
||||
fun set(index : Int, value : Byte) : Unit
|
||||
|
||||
fun iterator() : Iterator<Byte>
|
||||
fun iterator() : ByteIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -79,7 +111,7 @@ class ShortArray(val size : Int) {
|
||||
fun get(index : Int) : Short
|
||||
fun set(index : Int, value : Short) : Unit
|
||||
|
||||
fun iterator() : Iterator<Short>
|
||||
fun iterator() : ShortIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -88,7 +120,7 @@ class IntArray(val size : Int) {
|
||||
fun get(index : Int) : Int
|
||||
fun set(index : Int, value : Int) : Unit
|
||||
|
||||
fun iterator() : Iterator<Int>
|
||||
fun iterator() : IntIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -97,7 +129,7 @@ class LongArray(val size : Int) {
|
||||
fun get(index : Int) : Long
|
||||
fun set(index : Int, value : Long) : Unit
|
||||
|
||||
fun iterator() : Iterator<Long>
|
||||
fun iterator() : LongIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -106,7 +138,7 @@ class FloatArray(val size : Int) {
|
||||
fun get(index : Int) : Float
|
||||
fun set(index : Int, value : Float) : Unit
|
||||
|
||||
fun iterator() : Iterator<Float>
|
||||
fun iterator() : FloatIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -115,7 +147,7 @@ class DoubleArray(val size : Int) {
|
||||
fun get(index : Int) : Double
|
||||
fun set(index : Int, value : Double) : Unit
|
||||
|
||||
fun iterator() : Iterator<Double>
|
||||
fun iterator() : DoubleIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -124,7 +156,7 @@ class CharArray(val size : Int) {
|
||||
fun get(index : Int) : Char
|
||||
fun set(index : Int, value : Char) : Unit
|
||||
|
||||
fun iterator() : Iterator<Char>
|
||||
fun iterator() : CharIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
@@ -133,7 +165,7 @@ class BooleanArray(val size : Int) {
|
||||
fun get(index : Int) : Boolean
|
||||
fun set(index : Int, value : Boolean) : Unit
|
||||
|
||||
fun iterator() : Iterator<Boolean>
|
||||
fun iterator() : BooleanIterator
|
||||
|
||||
val indices : IntRange
|
||||
}
|
||||
|
||||
@@ -63,14 +63,70 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testPrimitiveIterator () throws Exception {
|
||||
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
|
||||
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.nextByte()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorByte () throws Exception {
|
||||
loadText("fun box() { for(x in ByteArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorShort () throws Exception {
|
||||
loadText("fun box() { for(x in ShortArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorInt () throws Exception {
|
||||
loadText("fun box() { for(x in IntArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorLong () throws Exception {
|
||||
loadText("fun box() { for(x in LongArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorFloat () throws Exception {
|
||||
loadText("fun box() { for(x in FloatArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorDouble () throws Exception {
|
||||
loadText("fun box() { for(x in DoubleArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorChar () throws Exception {
|
||||
loadText("fun box() { for(x in CharArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIteratorBoolean () throws Exception {
|
||||
loadText("fun box() { for(x in BooleanArray(5)) { java.lang.System.out?.println(x) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testLongIterator () throws Exception {
|
||||
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
|
||||
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.nextLong()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class BooleanIterator implements Iterator<Boolean> {
|
||||
public final Boolean next() {
|
||||
return nextBoolean();
|
||||
}
|
||||
|
||||
public abstract boolean nextBoolean();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class ByteIterator implements Iterator<Byte> {
|
||||
public final Byte next() {
|
||||
return nextByte();
|
||||
}
|
||||
|
||||
public abstract byte nextByte();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class CharIterator implements Iterator<Character> {
|
||||
public final Character next() {
|
||||
return nextChar();
|
||||
}
|
||||
|
||||
public abstract char nextChar();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class DoubleIterator implements Iterator<Double> {
|
||||
public final Double next() {
|
||||
return nextDouble();
|
||||
}
|
||||
|
||||
public abstract double nextDouble();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class FloatIterator implements Iterator<Float> {
|
||||
public final Float next() {
|
||||
return nextFloat();
|
||||
}
|
||||
|
||||
public abstract float nextFloat();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class IntIterator implements Iterator<Integer> {
|
||||
public final Integer next() {
|
||||
return nextInt();
|
||||
}
|
||||
|
||||
public abstract int nextInt();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class LongIterator implements Iterator<Long> {
|
||||
public final Long next() {
|
||||
return nextLong();
|
||||
}
|
||||
|
||||
public abstract long nextLong();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jet;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public abstract class ShortIterator implements Iterator<Short> {
|
||||
public final Short next() {
|
||||
return nextShort();
|
||||
}
|
||||
|
||||
public abstract short nextShort();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package jet.runtime;
|
||||
|
||||
import jet.Iterator;
|
||||
import jet.JetObject;
|
||||
import jet.*;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import jet.typeinfo.TypeInfoProjection;
|
||||
|
||||
@@ -46,17 +45,23 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
return new GenericIterator<T>(array, elementTypeInfo);
|
||||
}
|
||||
|
||||
private static class ByteIterator extends ArrayIterator<Byte> {
|
||||
private static class ArrayByteIterator extends ByteIterator {
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayByteIterator.class, false);
|
||||
|
||||
private final byte[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ByteIterator.class, false);
|
||||
private int index;
|
||||
|
||||
private ByteIterator(byte[] array) {
|
||||
super(array.length);
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayByteIterator(byte[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte next() {
|
||||
public byte nextByte() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -66,21 +71,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Byte> iterator(byte[] array) {
|
||||
return new ByteIterator(array);
|
||||
public static ByteIterator iterator(byte[] array) {
|
||||
return new ArrayByteIterator(array);
|
||||
}
|
||||
|
||||
private static class ShortIterator extends ArrayIterator<Short> {
|
||||
private static class ArrayShortIterator extends ShortIterator {
|
||||
private final short[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ShortIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayShortIterator.class, false);
|
||||
|
||||
private ShortIterator(short[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayShortIterator(short[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short next() {
|
||||
public short nextShort() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -90,21 +101,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Short> iterator(short[] array) {
|
||||
return new ShortIterator(array);
|
||||
public static ShortIterator iterator(short[] array) {
|
||||
return new ArrayShortIterator(array);
|
||||
}
|
||||
|
||||
private static class IntegerIterator extends ArrayIterator<Integer> {
|
||||
private static class ArrayIntegerIterator extends IntIterator {
|
||||
private final int[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(IntegerIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayIntegerIterator.class, false);
|
||||
|
||||
private IntegerIterator(int[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayIntegerIterator(int[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer next() {
|
||||
public int nextInt() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -114,21 +131,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Integer> iterator(int[] array) {
|
||||
return new IntegerIterator(array);
|
||||
public static IntIterator iterator(int[] array) {
|
||||
return new ArrayIntegerIterator(array);
|
||||
}
|
||||
|
||||
private static class LongIterator extends ArrayIterator<Long> {
|
||||
private static class ArrayLongIterator extends LongIterator {
|
||||
private final long[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(LongIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayLongIterator.class, false);
|
||||
|
||||
private LongIterator(long[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayLongIterator(long[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long next() {
|
||||
public long nextLong() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -138,21 +161,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Long> iterator(long[] array) {
|
||||
return new LongIterator(array);
|
||||
public static LongIterator iterator(long[] array) {
|
||||
return new ArrayLongIterator(array);
|
||||
}
|
||||
|
||||
private static class FloatIterator extends ArrayIterator<Float> {
|
||||
private static class ArrayFloatIterator extends FloatIterator {
|
||||
private final float[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(FloatIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayFloatIterator.class, false);
|
||||
|
||||
private FloatIterator(float[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayFloatIterator(float[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float next() {
|
||||
public float nextFloat() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -162,21 +191,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Float> iterator(float[] array) {
|
||||
return new FloatIterator(array);
|
||||
public static FloatIterator iterator(float[] array) {
|
||||
return new ArrayFloatIterator(array);
|
||||
}
|
||||
|
||||
private static class DoubleIterator extends ArrayIterator<Double> {
|
||||
private static class ArrayDoubleIterator extends DoubleIterator {
|
||||
private final double[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(DoubleIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayDoubleIterator.class, false);
|
||||
|
||||
private DoubleIterator(double[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayDoubleIterator(double[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double next() {
|
||||
public double nextDouble() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -186,21 +221,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Double> iterator(double[] array) {
|
||||
return new DoubleIterator(array);
|
||||
public static DoubleIterator iterator(double[] array) {
|
||||
return new ArrayDoubleIterator(array);
|
||||
}
|
||||
|
||||
private static class CharacterIterator extends ArrayIterator<Character> {
|
||||
private static class ArrayCharacterIterator extends CharIterator {
|
||||
private final char[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(CharacterIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayCharacterIterator.class, false);
|
||||
|
||||
private CharacterIterator(char[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayCharacterIterator(char[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Character next() {
|
||||
public char nextChar() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -210,21 +251,27 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Character> iterator(char[] array) {
|
||||
return new CharacterIterator(array);
|
||||
public static CharIterator iterator(char[] array) {
|
||||
return new ArrayCharacterIterator(array);
|
||||
}
|
||||
|
||||
private static class BooleanIterator extends ArrayIterator<Boolean> {
|
||||
private static class ArrayBooleanIterator extends BooleanIterator {
|
||||
private final boolean[] array;
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(BooleanIterator.class, false);
|
||||
private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(ArrayBooleanIterator.class, false);
|
||||
|
||||
private BooleanIterator(boolean[] array) {
|
||||
super(array.length);
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public boolean getHasNext() {
|
||||
return index < array.length;
|
||||
}
|
||||
|
||||
private ArrayBooleanIterator(boolean[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean next() {
|
||||
public boolean nextBoolean() {
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@@ -234,39 +281,7 @@ public abstract class ArrayIterator<T> implements Iterator<T>, JetObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterator<Boolean> iterator(boolean[] array) {
|
||||
return new BooleanIterator(array);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] strings = {"Byte", "byte", "Short", "short", "Integer", "int", "Long", "long", "Float", "float", "Double", "double", "Character", "char", "Boolean", "boolean"};
|
||||
for(int i = 0; i != strings.length; i += 2) {
|
||||
String boxed = strings[i];
|
||||
String unboxed = strings[i+1];
|
||||
System.out.println(" private static class " + boxed + "Iterator extends ArrayIterator<" + boxed + "> {\n" +
|
||||
" private final " + unboxed + "[] array;\n" +
|
||||
" private static final TypeInfo typeInfo = TypeInfo.getTypeInfo(" + boxed + "Iterator.class, false);\n" +
|
||||
"\n" +
|
||||
" private " + boxed + "Iterator(" + unboxed + "[] array) {\n" +
|
||||
" super(array.length);\n" +
|
||||
" this.array = array;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" @Override\n" +
|
||||
" public " + boxed + " next() {\n" +
|
||||
" return array[index++];\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" @Override\n" +
|
||||
" public TypeInfo<?> getTypeInfo() {\n" +
|
||||
" return typeInfo;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" public static Iterator<" + boxed + "> iterator(" + unboxed + "[] array) {\n" +
|
||||
" return new " + boxed + "Iterator(array);\n" +
|
||||
" }\n" +
|
||||
"");
|
||||
}
|
||||
public static BooleanIterator iterator(boolean[] array) {
|
||||
return new ArrayBooleanIterator(array);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user