New structure of range classes.
This commit is contained in:
@@ -4,81 +4,67 @@ public trait Range<in T : Comparable<T>> {
|
||||
public fun contains(item : T) : Boolean
|
||||
}
|
||||
|
||||
public class IntRange(public val start : Int, public val size : Int) : Range<Int>, IntIterable {
|
||||
public class IntRange(public val start : Int, public val end : Int) : Range<Int>, IntIterable {
|
||||
public override fun iterator () : IntIterator
|
||||
|
||||
public override fun contains (elem: Int) : Boolean
|
||||
|
||||
public val end : Int
|
||||
|
||||
public class object {
|
||||
public val EMPTY: IntRange
|
||||
}
|
||||
}
|
||||
|
||||
public class LongRange(public val start : Long, public val size : Long) : Range<Long>, LongIterable {
|
||||
public class LongRange(public val start : Long, public val end : Long) : Range<Long>, LongIterable {
|
||||
public override fun iterator () : LongIterator
|
||||
|
||||
public override fun contains (elem: Long) : Boolean
|
||||
|
||||
public val end : Long
|
||||
|
||||
public class object {
|
||||
public val EMPTY: LongRange
|
||||
}
|
||||
}
|
||||
|
||||
public class ByteRange(public val start : Byte, public val size : Int) : Range<Byte>, ByteIterable {
|
||||
public class ByteRange(public val start : Byte, public val end : Byte) : Range<Byte>, ByteIterable {
|
||||
public override fun iterator () : ByteIterator
|
||||
|
||||
public override fun contains (elem: Byte) : Boolean
|
||||
|
||||
public val end : Byte
|
||||
|
||||
public class object {
|
||||
public val EMPTY: ByteRange
|
||||
}
|
||||
}
|
||||
|
||||
public class ShortRange(public val start : Short, public val size : Int) : Range<Short>, ShortIterable {
|
||||
public class ShortRange(public val start : Short, public val end : Short) : Range<Short>, ShortIterable {
|
||||
public override fun iterator () : ShortIterator
|
||||
|
||||
public override fun contains (elem: Short) : Boolean
|
||||
|
||||
public val end : Short
|
||||
|
||||
public class object {
|
||||
public val EMPTY: ShortRange
|
||||
}
|
||||
}
|
||||
|
||||
public class CharRange(public val start : Char, public val size : Int) : Range<Char>, CharIterable {
|
||||
public class CharRange(public val start : Char, public val end : Char) : Range<Char>, CharIterable {
|
||||
public override fun iterator () : CharIterator
|
||||
|
||||
public override fun contains (elem: Char) : Boolean
|
||||
|
||||
public val end : Char
|
||||
|
||||
public class object {
|
||||
public val EMPTY: CharRange
|
||||
}
|
||||
}
|
||||
|
||||
public class FloatRange(public val start : Float, public val size : Float) : Range<Float> {
|
||||
public class FloatRange(public val start : Float, public val end : Float) : Range<Float> {
|
||||
public override fun contains (elem: Float) : Boolean
|
||||
|
||||
public val end : Float
|
||||
|
||||
public class object {
|
||||
public val EMPTY: FloatRange
|
||||
}
|
||||
}
|
||||
|
||||
public class DoubleRange(public val start : Double, public val size : Double) : Range<Double> {
|
||||
public class DoubleRange(public val start : Double, public val end : Double) : Range<Double> {
|
||||
public override fun contains (elem: Double) : Boolean
|
||||
|
||||
public val end : Double
|
||||
|
||||
public class object {
|
||||
public val EMPTY: DoubleRange
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
fun box(): String {
|
||||
if (IntRange(0, 0) != IntRange.EMPTY) {
|
||||
if (IntRange(1, 0) != IntRange.EMPTY) {
|
||||
return IntRange.EMPTY.toString()
|
||||
}
|
||||
if (CharRange(0.toChar(), 0) != CharRange.EMPTY) {
|
||||
if (CharRange(1.toChar(), 0.toChar()) != CharRange.EMPTY) {
|
||||
return CharRange.EMPTY.toString()
|
||||
}
|
||||
if (ByteRange(0, 0) != ByteRange.EMPTY) {
|
||||
if (ByteRange(1, 0) != ByteRange.EMPTY) {
|
||||
return ByteRange.EMPTY.toString()
|
||||
}
|
||||
if (ShortRange(0, 0) != ShortRange.EMPTY) {
|
||||
if (ShortRange(1, 0) != ShortRange.EMPTY) {
|
||||
return ShortRange.EMPTY.toString()
|
||||
}
|
||||
if (FloatRange(0.toFloat(), 0.toFloat()) != FloatRange.EMPTY) {
|
||||
if (FloatRange(1.toFloat(), 0.toFloat()) != FloatRange.EMPTY) {
|
||||
return FloatRange.EMPTY.toString()
|
||||
}
|
||||
if (LongRange(0, 0) != LongRange.EMPTY) {
|
||||
if (LongRange(1, 0) != LongRange.EMPTY) {
|
||||
return LongRange.EMPTY.toString()
|
||||
}
|
||||
if (DoubleRange(0.0, 0.0) != DoubleRange.EMPTY) {
|
||||
if (DoubleRange(1.0, 0.0) != DoubleRange.EMPTY) {
|
||||
return DoubleRange.EMPTY.toString()
|
||||
}
|
||||
return "OK"
|
||||
|
||||
@@ -5,4 +5,4 @@ fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
val String?.indices : IntRange get() = IntRange(0, this!!.length)
|
||||
val String?.indices : IntRange get() = 0..(this!!.length - 1)
|
||||
@@ -16,7 +16,7 @@ fun box(): String {
|
||||
}
|
||||
sb.append(";")
|
||||
|
||||
for (i in IntRange(0, 1)) {
|
||||
for (i in IntRange(0, 0)) {
|
||||
ap(i)
|
||||
}
|
||||
sb.append(";")
|
||||
|
||||
@@ -26,6 +26,13 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerateRanges {
|
||||
private static String castIfNecessary(String what, String thisType, String otherType) {
|
||||
if (thisType.equals("byte") && otherType.equals("char") || thisType.equals("char") && otherType.equals("short")) {
|
||||
return "(" + otherType + ") " + what;
|
||||
}
|
||||
return what;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
PrintStream out = new PrintStream(new FileOutputStream("runtime/src/jet/runtime/Ranges.java"));
|
||||
try {
|
||||
@@ -68,37 +75,17 @@ public class GenerateRanges {
|
||||
resType = "ByteRange";
|
||||
}
|
||||
|
||||
if (resType.equals("FloatRange") || resType.equals("DoubleRange")) {
|
||||
out.println(" public static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {");
|
||||
out.println(" return new " + resType + "(from, to - from);");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
}
|
||||
else {
|
||||
String castIfNecessary;
|
||||
if (t1.equals("byte") && t2.equals("char") || t1.equals("char") && t2.equals("short")) {
|
||||
castIfNecessary = "(" + t2 + ") ";
|
||||
}
|
||||
else {
|
||||
castIfNecessary = "";
|
||||
}
|
||||
|
||||
|
||||
out.println(" public static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {");
|
||||
out.println(" if (from > to) {");
|
||||
out.println(" return " + resType + ".EMPTY;");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" return new " + resType + "(" + castIfNecessary + "from, to - from + 1);");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
}
|
||||
out.println(" public static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {");
|
||||
out.println(" return new " + resType + "("
|
||||
+ castIfNecessary("from", t1, t2) + ", "
|
||||
+ castIfNecessary("to", t2, t1) + ");");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
out.println(" public static IntRange arrayIndices(int length) {");
|
||||
out.println(" return new IntRange(0, length);");
|
||||
out.println(" return new IntRange(0, length - 1);");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class ByteRange implements Range<Byte>, ByteIterable {
|
||||
private final byte start;
|
||||
private final int count;
|
||||
private final byte end;
|
||||
|
||||
public static final ByteRange EMPTY = new ByteRange((byte) 0,0);
|
||||
public static final ByteRange EMPTY = new ByteRange((byte) 1, (byte) 0);
|
||||
|
||||
public ByteRange(byte startValue, int count) {
|
||||
this.start = startValue;
|
||||
this.count = count;
|
||||
public ByteRange(byte start, byte end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,18 +37,11 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
|
||||
|
||||
@Override
|
||||
public boolean contains(Byte item) {
|
||||
if (item == null) return false;
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
public boolean contains(byte item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,13 +54,13 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
|
||||
}
|
||||
|
||||
ByteRange range = (ByteRange) o;
|
||||
return count == range.count && start == range.start;
|
||||
return end == range.end && start == range.start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) start;
|
||||
result = 31 * result + count;
|
||||
result = 31 * result + end;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -76,11 +69,7 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
|
||||
}
|
||||
|
||||
public byte getEnd() {
|
||||
return (byte) (count < 0 ? start + count + 1: count == 0 ? 0 : start+count-1);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return count < 0 ? -count : count;
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class CharRange implements Range<Character>, CharIterable {
|
||||
private final char start;
|
||||
private final int count;
|
||||
private final char end;
|
||||
|
||||
public static final CharRange EMPTY = new CharRange((char) 0,0);
|
||||
public static final CharRange EMPTY = new CharRange((char) 1, (char) 0);
|
||||
|
||||
public CharRange(char startValue, int count) {
|
||||
this.start = startValue;
|
||||
this.count = count;
|
||||
public CharRange(char start, char end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,18 +37,11 @@ public final class CharRange implements Range<Character>, CharIterable {
|
||||
|
||||
@Override
|
||||
public boolean contains(Character item) {
|
||||
if (item == null) return false;
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
public boolean contains(char item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,13 +54,13 @@ public final class CharRange implements Range<Character>, CharIterable {
|
||||
}
|
||||
|
||||
CharRange range = (CharRange) o;
|
||||
return count == range.count && start == range.start;
|
||||
return end == range.end && start == range.start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) start;
|
||||
result = 31 * result + count;
|
||||
result = 31 * result + end;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -76,11 +69,7 @@ public final class CharRange implements Range<Character>, CharIterable {
|
||||
}
|
||||
|
||||
public char getEnd() {
|
||||
return (char) (count < 0 ? start + count + 1: count == 0 ? 0 : start+count-1);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return count < 0 ? -count : count;
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class DoubleRange implements Range<Double> {
|
||||
private final double start;
|
||||
private final double size;
|
||||
private final double end;
|
||||
|
||||
public static final DoubleRange EMPTY = new DoubleRange(0, 0);
|
||||
public static final DoubleRange EMPTY = new DoubleRange(1, 0);
|
||||
|
||||
public DoubleRange(double startValue, double size) {
|
||||
this.start = startValue;
|
||||
this.size = size;
|
||||
public DoubleRange(double start, double end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,11 +37,7 @@ public final class DoubleRange implements Range<Double> {
|
||||
|
||||
@Override
|
||||
public boolean contains(Double item) {
|
||||
if (item == null) return false;
|
||||
if (size >= 0) {
|
||||
return item >= start && item < start + size;
|
||||
}
|
||||
return item <= start && item > start + size;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +51,7 @@ public final class DoubleRange implements Range<Double> {
|
||||
|
||||
DoubleRange range = (DoubleRange) o;
|
||||
|
||||
return Double.compare(range.size, size) == 0 && Double.compare(range.start, start) == 0;
|
||||
return Double.compare(range.end, end) == 0 && Double.compare(range.start, start) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,20 +60,16 @@ public final class DoubleRange implements Range<Double> {
|
||||
long temp;
|
||||
temp = start != +0.0d ? Double.doubleToLongBits(start) : 0L;
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = size != +0.0d ? Double.doubleToLongBits(size) : 0L;
|
||||
temp = end != +0.0d ? Double.doubleToLongBits(end) : 0L;
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
public double getStart() {
|
||||
public double getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public double getEnd() {
|
||||
return size < 0 ? start + size: start + size;
|
||||
}
|
||||
|
||||
public double getSize() {
|
||||
return size < 0 ? -size : size;
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class FloatRange implements Range<Float> {
|
||||
private final float start;
|
||||
private final float size;
|
||||
private final float end;
|
||||
|
||||
public static final FloatRange EMPTY = new FloatRange(0, 0);
|
||||
public static final FloatRange EMPTY = new FloatRange(1, 0);
|
||||
|
||||
public FloatRange(float startValue, float size) {
|
||||
this.start = startValue;
|
||||
this.size = size;
|
||||
public FloatRange(float start, float end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,11 +37,7 @@ public final class FloatRange implements Range<Float> {
|
||||
|
||||
@Override
|
||||
public boolean contains(Float item) {
|
||||
if (item == null) return false;
|
||||
if (size >= 0) {
|
||||
return item >= start && item < start + size;
|
||||
}
|
||||
return item <= start && item > start + size;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,25 +51,21 @@ public final class FloatRange implements Range<Float> {
|
||||
|
||||
FloatRange range = (FloatRange) o;
|
||||
|
||||
return Float.compare(range.size, size) == 0 && Float.compare(range.start, start) == 0;
|
||||
return Float.compare(range.end, end) == 0 && Float.compare(range.start, start) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (start != +0.0f ? Float.floatToIntBits(start) : 0);
|
||||
result = 31 * result + (size != +0.0f ? Float.floatToIntBits(size) : 0);
|
||||
result = 31 * result + (end != +0.0f ? Float.floatToIntBits(end) : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public float getStart() {
|
||||
public float getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public float getEnd() {
|
||||
return size < 0 ? start + size: start + size;
|
||||
}
|
||||
|
||||
public float getSize() {
|
||||
return size < 0 ? -size : size;
|
||||
public float getEnd() {
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class IntRange implements Range<Integer>, IntIterable {
|
||||
private final int start;
|
||||
private final int count;
|
||||
private final int end;
|
||||
|
||||
public static final IntRange EMPTY = new IntRange(0, 0);
|
||||
public static final IntRange EMPTY = new IntRange(1, 0);
|
||||
|
||||
public IntRange(int startValue, int count) {
|
||||
this.start = startValue;
|
||||
this.count = count;
|
||||
public IntRange(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,18 +37,11 @@ public final class IntRange implements Range<Integer>, IntIterable {
|
||||
|
||||
@Override
|
||||
public boolean contains(Integer item) {
|
||||
if (item == null) return false;
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
public boolean contains(int item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,13 +54,13 @@ public final class IntRange implements Range<Integer>, IntIterable {
|
||||
}
|
||||
|
||||
IntRange range = (IntRange) o;
|
||||
return count == range.count && start == range.start;
|
||||
return end == range.end && start == range.start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = start;
|
||||
result = 31 * result + count;
|
||||
result = 31 * result + end;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -76,11 +69,7 @@ public final class IntRange implements Range<Integer>, IntIterable {
|
||||
}
|
||||
|
||||
public int getEnd() {
|
||||
return count < 0 ? start + count + 1: count == 0 ? 0 : start+count-1;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return count < 0 ? -count : count;
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class LongRange implements Range<Long>, LongIterable {
|
||||
private final long start;
|
||||
private final long count;
|
||||
private final long end;
|
||||
|
||||
public static final LongRange EMPTY = new LongRange(0L,0L);
|
||||
public static final LongRange EMPTY = new LongRange(1, 0);
|
||||
|
||||
public LongRange(long startValue, long count) {
|
||||
this.start = startValue;
|
||||
this.count = count;
|
||||
public LongRange(long start, long end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,21 +35,13 @@ public final class LongRange implements Range<Long>, LongIterable {
|
||||
return getStart() + ".." + getEnd();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean contains(Long item) {
|
||||
if (item == null) return false;
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
public boolean contains(long item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,13 +54,13 @@ public final class LongRange implements Range<Long>, LongIterable {
|
||||
}
|
||||
|
||||
LongRange range = (LongRange) o;
|
||||
return count == range.count && start == range.start;
|
||||
return end == range.end && start == range.start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (start ^ (start >>> 32));
|
||||
result = 31 * result + (int) (count ^ (count >>> 32));
|
||||
result = 31 * result + (int) (end ^ (end >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -77,11 +69,7 @@ public final class LongRange implements Range<Long>, LongIterable {
|
||||
}
|
||||
|
||||
public long getEnd() {
|
||||
return count < 0 ? start + count + 1: count == 0 ? 0 : start+count-1;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return count < 0 ? -count : count;
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
|
||||
@AssertInvisibleInResolver
|
||||
public final class ShortRange implements Range<Short>, ShortIterable {
|
||||
private final short start;
|
||||
private final int count;
|
||||
private final short end;
|
||||
|
||||
public static final ShortRange EMPTY = new ShortRange((short) 0,0);
|
||||
public static final ShortRange EMPTY = new ShortRange((short) 1, (short) 0);
|
||||
|
||||
public ShortRange(short startValue, int count) {
|
||||
this.start = startValue;
|
||||
this.count = count;
|
||||
public ShortRange(short start, short end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,18 +37,11 @@ public final class ShortRange implements Range<Short>, ShortIterable {
|
||||
|
||||
@Override
|
||||
public boolean contains(Short item) {
|
||||
if (item == null) return false;
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
public boolean contains(short item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
return start <= item && item <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,13 +54,13 @@ public final class ShortRange implements Range<Short>, ShortIterable {
|
||||
}
|
||||
|
||||
ShortRange range = (ShortRange) o;
|
||||
return count == range.count && start == range.start;
|
||||
return end == range.end && start == range.start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) start;
|
||||
result = 31 * result + count;
|
||||
result = 31 * result + end;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -76,11 +69,7 @@ public final class ShortRange implements Range<Short>, ShortIterable {
|
||||
}
|
||||
|
||||
public short getEnd() {
|
||||
return (short) (count < 0 ? start + count + 1: count == 0 ? 0 : start+count-1);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return count < 0 ? -count : count;
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,328 +22,203 @@ import jet.*;
|
||||
/* This file is generated by org.jetbrains.jet.generators.runtime.GenerateRanges. DO NOT EDIT! */
|
||||
public class Ranges {
|
||||
public static ByteRange rangeTo(byte from, byte to) {
|
||||
if (from > to) {
|
||||
return ByteRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new ByteRange(from, to - from + 1);
|
||||
}
|
||||
return new ByteRange(from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(byte from, short to) {
|
||||
if (from > to) {
|
||||
return ShortRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to - from + 1);
|
||||
}
|
||||
return new ShortRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(byte from, int to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(byte from, long to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(byte from, float to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(byte from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(byte from, char to) {
|
||||
if (from > to) {
|
||||
return CharRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new CharRange((char) from, to - from + 1);
|
||||
}
|
||||
return new CharRange((char) from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, byte to) {
|
||||
if (from > to) {
|
||||
return ShortRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to - from + 1);
|
||||
}
|
||||
return new ShortRange(from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, short to) {
|
||||
if (from > to) {
|
||||
return ShortRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to - from + 1);
|
||||
}
|
||||
return new ShortRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(short from, int to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(short from, long to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(short from, float to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(short from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, char to) {
|
||||
if (from > to) {
|
||||
return ShortRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new ShortRange(from, to - from + 1);
|
||||
}
|
||||
return new ShortRange(from, (short) to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, byte to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, short to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, int to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(int from, long to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(int from, float to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(int from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, char to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, byte to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, short to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, int to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, long to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(long from, float to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(long from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, char to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, byte to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, short to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, int to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, long to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, float to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(float from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, char to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, byte to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, short to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, int to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, long to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, float to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, char to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(char from, byte to) {
|
||||
if (from > to) {
|
||||
return CharRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new CharRange(from, to - from + 1);
|
||||
}
|
||||
return new CharRange(from, (char) to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(char from, short to) {
|
||||
if (from > to) {
|
||||
return ShortRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new ShortRange((short) from, to - from + 1);
|
||||
}
|
||||
return new ShortRange((short) from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(char from, int to) {
|
||||
if (from > to) {
|
||||
return IntRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new IntRange(from, to - from + 1);
|
||||
}
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(char from, long to) {
|
||||
if (from > to) {
|
||||
return LongRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new LongRange(from, to - from + 1);
|
||||
}
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(char from, float to) {
|
||||
return new FloatRange(from, to - from);
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(char from, double to) {
|
||||
return new DoubleRange(from, to - from);
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(char from, char to) {
|
||||
if (from > to) {
|
||||
return CharRange.EMPTY;
|
||||
}
|
||||
else {
|
||||
return new CharRange(from, to - from + 1);
|
||||
}
|
||||
return new CharRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange arrayIndices(int length) {
|
||||
return new IntRange(0, length);
|
||||
return new IntRange(0, length - 1);
|
||||
}
|
||||
|
||||
private Ranges() {}
|
||||
|
||||
Reference in New Issue
Block a user