New structure of range classes.

This commit is contained in:
Evgeny Gerashchenko
2013-01-23 21:54:45 +04:00
parent 8c4abd4d9c
commit 0e0c048074
13 changed files with 151 additions and 375 deletions
+10 -21
View File
@@ -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
+10 -21
View File
@@ -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
+10 -18
View File
@@ -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;
}
}
+11 -19
View File
@@ -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;
}
}
+10 -21
View File
@@ -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
+10 -22
View File
@@ -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
+10 -21
View File
@@ -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
+50 -175
View File
@@ -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() {}