fixing stupid bug introduced in previous commit
simplification of api
This commit is contained in:
@@ -256,7 +256,7 @@ trait Range<in T : Comparable<T>> {
|
||||
fun contains(item : T) : Boolean
|
||||
}
|
||||
|
||||
class IntRange(val start : Int, val size : Int, val isReversed : Boolean = false) : Range<Int>, IntIterable {
|
||||
class IntRange(val start : Int, val size : Int) : Range<Int>, IntIterable {
|
||||
fun iterator () : IntIterator
|
||||
|
||||
fun contains (elem: Int) : Boolean
|
||||
@@ -266,9 +266,11 @@ class IntRange(val start : Int, val size : Int, val isReversed : Boolean = false
|
||||
fun minus() : IntRange
|
||||
|
||||
fun step(step: Int) : IntIterator
|
||||
|
||||
val isReversed : Boolean
|
||||
}
|
||||
|
||||
class LongRange(val start : Long, val size : Long, val isReversed : Boolean = false) : Range<Long>, LongIterable {
|
||||
class LongRange(val start : Long, val size : Long) : Range<Long>, LongIterable {
|
||||
fun iterator () : LongIterator
|
||||
|
||||
fun contains (elem: Long) : Boolean
|
||||
@@ -278,9 +280,11 @@ class LongRange(val start : Long, val size : Long, val isReversed : Boolean = fa
|
||||
fun minus() : LongRange
|
||||
|
||||
fun step(step: Long) : LongIterator
|
||||
|
||||
val isReversed : Boolean
|
||||
}
|
||||
|
||||
class ByteRange(val start : Byte, val size : Int, val isReversed : Boolean = false) : Range<Byte>, ByteIterable {
|
||||
class ByteRange(val start : Byte, val size : Int) : Range<Byte>, ByteIterable {
|
||||
fun iterator () : ByteIterator
|
||||
|
||||
fun contains (elem: Byte) : Boolean
|
||||
@@ -290,9 +294,11 @@ class ByteRange(val start : Byte, val size : Int, val isReversed : Boolean = fal
|
||||
fun minus() : ByteRange
|
||||
|
||||
fun step(step: Int) : ByteIterator
|
||||
|
||||
val isReversed : Boolean
|
||||
}
|
||||
|
||||
class ShortRange(val start : Short, val size : Int, val isReversed : Boolean = false) : Range<Short>, ShortIterable {
|
||||
class ShortRange(val start : Short, val size : Int) : Range<Short>, ShortIterable {
|
||||
fun iterator () : ShortIterator
|
||||
|
||||
fun contains (elem: Byte) : Boolean
|
||||
@@ -302,9 +308,11 @@ class ShortRange(val start : Short, val size : Int, val isReversed : Boolean = f
|
||||
fun minus() : ShortRange
|
||||
|
||||
fun step(step: Int) : ShortIterator
|
||||
|
||||
val isReversed : Boolean
|
||||
}
|
||||
|
||||
class CharRange(val start : Char, val size : Int, val isReversed : Boolean = false) : Range<Char>, CharIterable {
|
||||
class CharRange(val start : Char, val size : Int) : Range<Char>, CharIterable {
|
||||
fun iterator () : CharIterator
|
||||
|
||||
fun contains (elem: Char) : Boolean
|
||||
@@ -314,6 +322,8 @@ class CharRange(val start : Char, val size : Int, val isReversed : Boolean = fal
|
||||
fun minus() : CharRange
|
||||
|
||||
fun step(step: Int) : CharIterator
|
||||
|
||||
val isReversed : Boolean
|
||||
}
|
||||
|
||||
abstract class Number : Hashable {
|
||||
|
||||
@@ -2,9 +2,6 @@ fun box() : String {
|
||||
val r1 = IntRange(1, 4)
|
||||
if(r1.end != 4 || r1.isReversed || r1.size != 4) return "fail"
|
||||
|
||||
val r2 = IntRange(1, 4, true)
|
||||
if(r2.end != -2 || !r2.isReversed || r2.size != 4) return "fail"
|
||||
|
||||
val r3 = -(0..5)
|
||||
if(r3.start != 5 || r3.end != 0 || !r3.isReversed || r3.size != 6) return "fail"
|
||||
|
||||
@@ -14,9 +11,6 @@ fun box() : String {
|
||||
val r5 = ByteRange(1, 4)
|
||||
if(r5.end != 4.byt || r5.isReversed || r5.size != 4) return "fail"
|
||||
|
||||
val r6 = ByteRange(1, 4, true)
|
||||
if(r6.end != -2.byt || !r6.isReversed) return "fail"
|
||||
|
||||
val r7 = -(0.byt..5.byt)
|
||||
if(r7.start != 5.byt || r7.end != 0.byt || !r7.isReversed) return "fail"
|
||||
|
||||
@@ -26,9 +20,6 @@ fun box() : String {
|
||||
val r10 = ShortRange(1, 4)
|
||||
if(r10.end != 4.sht || r10.isReversed || r10.size != 4) return "fail"
|
||||
|
||||
val r11 = ShortRange(1, 4, true)
|
||||
if(r11.end != -2.sht || !r11.isReversed) return "fail"
|
||||
|
||||
val r12 = -(0.sht..5.sht)
|
||||
if(r12.start != 5.sht || r12.end != 0.sht || !r12.isReversed) return "fail"
|
||||
|
||||
@@ -38,9 +29,6 @@ fun box() : String {
|
||||
val r14 = CharRange('a', 4)
|
||||
if(r14.end != 'd' || r14.isReversed || r14.size != 4) return "fail"
|
||||
|
||||
val r15 = CharRange('D', 4, true)
|
||||
if(r15.end != 'A' || !r15.isReversed) return "fail"
|
||||
|
||||
val r16 = -('a'..'e')
|
||||
if(r16.start != 'e' || r16.end != 'a' || !r16.isReversed) return "fail"
|
||||
|
||||
|
||||
@@ -11,14 +11,6 @@ public final class ByteRange implements Range<Byte>, ByteIterable, JetObject {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public ByteRange(byte startValue, int count, boolean reversed) {
|
||||
this(startValue, reversed ? -count : count);
|
||||
}
|
||||
|
||||
public ByteRange(byte startValue, int count, boolean reversed, int defaultMask) {
|
||||
this(startValue, reversed ? -count : count, (defaultMask & 4) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Byte item) {
|
||||
if (item == null) return false;
|
||||
@@ -71,15 +63,6 @@ public final class ByteRange implements Range<Byte>, ByteIterable, JetObject {
|
||||
return new ByteRange((byte) 0, length);
|
||||
}
|
||||
|
||||
public static ByteRange rangeTo(byte from, byte to) {
|
||||
if(from > to) {
|
||||
return new ByteRange(to, from-to+1, true);
|
||||
}
|
||||
else {
|
||||
return new ByteRange(from, to-from+1);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyIterator extends ByteIterator {
|
||||
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(MyIterator.class, false);
|
||||
|
||||
|
||||
@@ -11,14 +11,6 @@ public final class CharRange implements Range<Character>, CharIterable, JetObjec
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public CharRange(char startValue, int count, boolean reversed) {
|
||||
this(startValue, reversed ? -count : count);
|
||||
}
|
||||
|
||||
public CharRange(char startValue, int count, boolean reversed, int defaultMask) {
|
||||
this(startValue, reversed ? -count : count, (defaultMask & 4) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Character item) {
|
||||
if (item == null) return false;
|
||||
@@ -71,15 +63,6 @@ public final class CharRange implements Range<Character>, CharIterable, JetObjec
|
||||
return new CharRange((char) 0, length);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(char from, char to) {
|
||||
if(from > to) {
|
||||
return new CharRange(to, from-to+1, true);
|
||||
}
|
||||
else {
|
||||
return new CharRange(from, to-from+1);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyIterator extends CharIterator {
|
||||
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(MyIterator.class, false);
|
||||
|
||||
|
||||
@@ -11,14 +11,6 @@ public final class IntRange implements Range<Integer>, IntIterable, JetObject {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public IntRange(int startValue, int count, boolean reversed) {
|
||||
this(startValue, reversed ? -count : count);
|
||||
}
|
||||
|
||||
public IntRange(int startValue, int count, boolean reversed, int defaultMask) {
|
||||
this(startValue, reversed ? -count : count, (defaultMask & 4) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Integer item) {
|
||||
if (item == null) return false;
|
||||
@@ -71,15 +63,6 @@ public final class IntRange implements Range<Integer>, IntIterable, JetObject {
|
||||
return new IntRange(0, length);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, int to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyIterator extends IntIterator {
|
||||
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(MyIterator.class, false);
|
||||
|
||||
@@ -92,8 +75,15 @@ public final class IntRange implements Range<Integer>, IntIterable, JetObject {
|
||||
public MyIterator(int startValue, int count, int step) {
|
||||
cur = startValue;
|
||||
this.step = step;
|
||||
reversed = count < 0;
|
||||
this.count = reversed ? -count : count;
|
||||
if(count < 0) {
|
||||
reversed = count < 0;
|
||||
count = -count;
|
||||
startValue += count;
|
||||
}
|
||||
else {
|
||||
reversed = false;
|
||||
}
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,14 +11,6 @@ public final class LongRange implements Range<Long>, LongIterable, JetObject {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public LongRange(long startValue, long count, boolean reversed) {
|
||||
this(startValue, reversed ? -count : count);
|
||||
}
|
||||
|
||||
public LongRange(int startValue, int count, boolean reversed, int defaultMask) {
|
||||
this(startValue, reversed ? -count : count, (defaultMask & 4) == 0);
|
||||
}
|
||||
|
||||
public LongIterator step(long step) {
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
|
||||
@@ -11,14 +11,6 @@ public final class ShortRange implements Range<Short>, ShortIterable, JetObject
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public ShortRange(short startValue, int count, boolean reversed) {
|
||||
this(startValue, reversed ? -count : count);
|
||||
}
|
||||
|
||||
public ShortRange(short startValue, int count, boolean reversed, int defaultMask) {
|
||||
this(startValue, reversed ? -count : count, (defaultMask & 4) == 0);
|
||||
}
|
||||
|
||||
public ShortIterator step(int step) {
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
@@ -71,15 +63,6 @@ public final class ShortRange implements Range<Short>, ShortIterable, JetObject
|
||||
return new ShortRange((byte) 0, length);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, short to) {
|
||||
if(from > to) {
|
||||
return new ShortRange(to, from-to+1, true);
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to-from+1);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyIterator extends ShortIterator {
|
||||
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(MyIterator.class, false);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Ranges {
|
||||
|
||||
public static ByteRange rangeTo(byte from, byte to) {
|
||||
if(from > to) {
|
||||
return new ByteRange(to, from-to+1, true);
|
||||
return new ByteRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new ByteRange(from, to-from+1);
|
||||
@@ -23,7 +23,7 @@ public class Ranges {
|
||||
|
||||
public static ShortRange rangeTo(byte from, short to) {
|
||||
if(from > to) {
|
||||
return new ShortRange(to, from-to+1, true);
|
||||
return new ShortRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to-from+1);
|
||||
@@ -32,7 +32,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(byte from, int to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -41,7 +41,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(byte from, long to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -50,7 +50,7 @@ public class Ranges {
|
||||
|
||||
public static CharRange rangeTo(byte from, char to) {
|
||||
if(from > to) {
|
||||
return new CharRange(to, from-to+1, true);
|
||||
return new CharRange((char) from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new CharRange((char) from, to-from+1);
|
||||
@@ -59,7 +59,7 @@ public class Ranges {
|
||||
|
||||
public static ShortRange rangeTo(short from, byte to) {
|
||||
if(from > to) {
|
||||
return new ShortRange(to, from-to+1, true);
|
||||
return new ShortRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to-from+1);
|
||||
@@ -68,7 +68,7 @@ public class Ranges {
|
||||
|
||||
public static ShortRange rangeTo(short from, short to) {
|
||||
if(from > to) {
|
||||
return new ShortRange(to, from-to+1, true);
|
||||
return new ShortRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to-from+1);
|
||||
@@ -77,7 +77,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(short from, int to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -86,7 +86,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(short from, long to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -95,7 +95,7 @@ public class Ranges {
|
||||
|
||||
public static ShortRange rangeTo(short from, char to) {
|
||||
if(from > to) {
|
||||
return new ShortRange((short) to, from-to+1, true);
|
||||
return new ShortRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to-from+1);
|
||||
@@ -104,7 +104,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(int from, byte to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -113,7 +113,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(int from, short to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -122,7 +122,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(int from, int to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -131,7 +131,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(int from, long to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -140,7 +140,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(int from, char to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -149,7 +149,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(long from, byte to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -158,7 +158,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(long from, short to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -167,7 +167,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(long from, int to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -176,7 +176,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(long from, long to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -185,7 +185,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(long from, char to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -194,7 +194,7 @@ public class Ranges {
|
||||
|
||||
public static CharRange rangeTo(char from, byte to) {
|
||||
if(from > to) {
|
||||
return new CharRange((char) to, from-to+1, true);
|
||||
return new CharRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new CharRange(from, to-from+1);
|
||||
@@ -203,7 +203,7 @@ public class Ranges {
|
||||
|
||||
public static ShortRange rangeTo(char from, short to) {
|
||||
if(from > to) {
|
||||
return new ShortRange(to, from-to+1, true);
|
||||
return new ShortRange((short) from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new ShortRange((short) from, to-from+1);
|
||||
@@ -212,7 +212,7 @@ public class Ranges {
|
||||
|
||||
public static IntRange rangeTo(char from, int to) {
|
||||
if(from > to) {
|
||||
return new IntRange(to, from-to+1, true);
|
||||
return new IntRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to-from+1);
|
||||
@@ -221,7 +221,7 @@ public class Ranges {
|
||||
|
||||
public static LongRange rangeTo(char from, long to) {
|
||||
if(from > to) {
|
||||
return new LongRange(to, from-to+1, true);
|
||||
return new LongRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to-from+1);
|
||||
@@ -230,7 +230,7 @@ public class Ranges {
|
||||
|
||||
public static CharRange rangeTo(char from, char to) {
|
||||
if(from > to) {
|
||||
return new CharRange(to, from-to+1, true);
|
||||
return new CharRange(from, to-from-1);
|
||||
}
|
||||
else {
|
||||
return new CharRange(from, to-from+1);
|
||||
@@ -266,7 +266,7 @@ public class Ranges {
|
||||
|
||||
System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {" +
|
||||
"\n if(from > to) {\n" +
|
||||
" return new " + resType + "(to, from-to+1, true);\n" +
|
||||
" return new " + resType + "(from, to-from-1);\n" +
|
||||
" }\n" +
|
||||
" else {\n" +
|
||||
" return new " + resType + "(from, to-from+1);\n" +
|
||||
|
||||
Reference in New Issue
Block a user