Removed upto() and downto() member functions from number types

#KT-2519 fixed
This commit is contained in:
Evgeny Gerashchenko
2012-08-07 22:05:36 +04:00
parent a4031225d0
commit b1fa44aa4d
7 changed files with 60 additions and 644 deletions
+54 -386
View File
@@ -28,7 +28,7 @@ public class Ranges {
private Ranges() {
}
public static ByteRange upTo(byte from, byte to) {
public static ByteRange rangeTo(byte from, byte to) {
if (from > to) {
return ByteRange.empty;
}
@@ -37,16 +37,7 @@ public class Ranges {
}
}
public static ByteRange downTo(byte from, byte to) {
if (from >= to) {
return new ByteRange(from, to - from - 1);
}
else {
return ByteRange.empty;
}
}
public static ShortRange upTo(byte from, short to) {
public static ShortRange rangeTo(byte from, short to) {
if (from > to) {
return ShortRange.empty;
}
@@ -55,16 +46,7 @@ public class Ranges {
}
}
public static ShortRange downTo(byte from, short to) {
if (from >= to) {
return new ShortRange(from, to - from - 1);
}
else {
return ShortRange.empty;
}
}
public static IntRange upTo(byte from, int to) {
public static IntRange rangeTo(byte from, int to) {
if (from > to) {
return IntRange.empty;
}
@@ -73,16 +55,7 @@ public class Ranges {
}
}
public static IntRange downTo(byte from, int to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static LongRange upTo(byte from, long to) {
public static LongRange rangeTo(byte from, long to) {
if (from > to) {
return LongRange.empty;
}
@@ -91,32 +64,15 @@ public class Ranges {
}
}
public static LongRange downTo(byte from, long to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static FloatRange upTo(byte from, float to) {
public static FloatRange rangeTo(byte from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(byte from, float to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(byte from, double to) {
public static DoubleRange rangeTo(byte from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(byte from, double to) {
return new DoubleRange(from, to - from);
}
public static CharRange upTo(byte from, char to) {
public static CharRange rangeTo(byte from, char to) {
if (from > to) {
return CharRange.empty;
}
@@ -125,16 +81,7 @@ public class Ranges {
}
}
public static CharRange downTo(byte from, char to) {
if (from >= to) {
return new CharRange((char) from, to - from - 1);
}
else {
return CharRange.empty;
}
}
public static ShortRange upTo(short from, byte to) {
public static ShortRange rangeTo(short from, byte to) {
if (from > to) {
return ShortRange.empty;
}
@@ -143,16 +90,7 @@ public class Ranges {
}
}
public static ShortRange downTo(short from, byte to) {
if (from >= to) {
return new ShortRange(from, to - from - 1);
}
else {
return ShortRange.empty;
}
}
public static ShortRange upTo(short from, short to) {
public static ShortRange rangeTo(short from, short to) {
if (from > to) {
return ShortRange.empty;
}
@@ -161,16 +99,7 @@ public class Ranges {
}
}
public static ShortRange downTo(short from, short to) {
if (from >= to) {
return new ShortRange(from, to - from - 1);
}
else {
return ShortRange.empty;
}
}
public static IntRange upTo(short from, int to) {
public static IntRange rangeTo(short from, int to) {
if (from > to) {
return IntRange.empty;
}
@@ -179,16 +108,7 @@ public class Ranges {
}
}
public static IntRange downTo(short from, int to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static LongRange upTo(short from, long to) {
public static LongRange rangeTo(short from, long to) {
if (from > to) {
return LongRange.empty;
}
@@ -197,32 +117,15 @@ public class Ranges {
}
}
public static LongRange downTo(short from, long to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static FloatRange upTo(short from, float to) {
public static FloatRange rangeTo(short from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(short from, float to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(short from, double to) {
public static DoubleRange rangeTo(short from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(short from, double to) {
return new DoubleRange(from, to - from);
}
public static ShortRange upTo(short from, char to) {
public static ShortRange rangeTo(short from, char to) {
if (from > to) {
return ShortRange.empty;
}
@@ -231,16 +134,7 @@ public class Ranges {
}
}
public static ShortRange downTo(short from, char to) {
if (from >= to) {
return new ShortRange(from, to - from - 1);
}
else {
return ShortRange.empty;
}
}
public static IntRange upTo(int from, byte to) {
public static IntRange rangeTo(int from, byte to) {
if (from > to) {
return IntRange.empty;
}
@@ -249,16 +143,7 @@ public class Ranges {
}
}
public static IntRange downTo(int from, byte to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static IntRange upTo(int from, short to) {
public static IntRange rangeTo(int from, short to) {
if (from > to) {
return IntRange.empty;
}
@@ -267,16 +152,7 @@ public class Ranges {
}
}
public static IntRange downTo(int from, short to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static IntRange upTo(int from, int to) {
public static IntRange rangeTo(int from, int to) {
if (from > to) {
return IntRange.empty;
}
@@ -285,16 +161,7 @@ public class Ranges {
}
}
public static IntRange downTo(int from, int to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static LongRange upTo(int from, long to) {
public static LongRange rangeTo(int from, long to) {
if (from > to) {
return LongRange.empty;
}
@@ -303,32 +170,15 @@ public class Ranges {
}
}
public static LongRange downTo(int from, long to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static FloatRange upTo(int from, float to) {
public static FloatRange rangeTo(int from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(int from, float to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(int from, double to) {
public static DoubleRange rangeTo(int from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(int from, double to) {
return new DoubleRange(from, to - from);
}
public static IntRange upTo(int from, char to) {
public static IntRange rangeTo(int from, char to) {
if (from > to) {
return IntRange.empty;
}
@@ -337,16 +187,7 @@ public class Ranges {
}
}
public static IntRange downTo(int from, char to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static LongRange upTo(long from, byte to) {
public static LongRange rangeTo(long from, byte to) {
if (from > to) {
return LongRange.empty;
}
@@ -355,16 +196,7 @@ public class Ranges {
}
}
public static LongRange downTo(long from, byte to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static LongRange upTo(long from, short to) {
public static LongRange rangeTo(long from, short to) {
if (from > to) {
return LongRange.empty;
}
@@ -373,16 +205,7 @@ public class Ranges {
}
}
public static LongRange downTo(long from, short to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static LongRange upTo(long from, int to) {
public static LongRange rangeTo(long from, int to) {
if (from > to) {
return LongRange.empty;
}
@@ -391,16 +214,7 @@ public class Ranges {
}
}
public static LongRange downTo(long from, int to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static LongRange upTo(long from, long to) {
public static LongRange rangeTo(long from, long to) {
if (from > to) {
return LongRange.empty;
}
@@ -409,32 +223,15 @@ public class Ranges {
}
}
public static LongRange downTo(long from, long to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static FloatRange upTo(long from, float to) {
public static FloatRange rangeTo(long from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(long from, float to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(long from, double to) {
public static DoubleRange rangeTo(long from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(long from, double to) {
return new DoubleRange(from, to - from);
}
public static LongRange upTo(long from, char to) {
public static LongRange rangeTo(long from, char to) {
if (from > to) {
return LongRange.empty;
}
@@ -443,128 +240,63 @@ public class Ranges {
}
}
public static LongRange downTo(long from, char to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static FloatRange upTo(float from, byte to) {
public static FloatRange rangeTo(float from, byte to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(float from, byte to) {
public static FloatRange rangeTo(float from, short to) {
return new FloatRange(from, to - from);
}
public static FloatRange upTo(float from, short to) {
public static FloatRange rangeTo(float from, int to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(float from, short to) {
public static FloatRange rangeTo(float from, long to) {
return new FloatRange(from, to - from);
}
public static FloatRange upTo(float from, int to) {
public static FloatRange rangeTo(float from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(float from, int to) {
public static DoubleRange rangeTo(float from, double to) {
return new DoubleRange(from, to - from);
}
public static FloatRange rangeTo(float from, char to) {
return new FloatRange(from, to - from);
}
public static FloatRange upTo(float from, long to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(float from, long to) {
return new FloatRange(from, to - from);
}
public static FloatRange upTo(float from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(float from, float to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(float from, double to) {
public static DoubleRange rangeTo(double from, byte to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(float from, double to) {
public static DoubleRange rangeTo(double from, short to) {
return new DoubleRange(from, to - from);
}
public static FloatRange upTo(float from, char to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(float from, char to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(double from, byte to) {
public static DoubleRange rangeTo(double from, int to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, byte to) {
public static DoubleRange rangeTo(double from, long to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange upTo(double from, short to) {
public static DoubleRange rangeTo(double from, float to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, short to) {
public static DoubleRange rangeTo(double from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange upTo(double from, int to) {
public static DoubleRange rangeTo(double from, char to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, int to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange upTo(double from, long to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, long to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange upTo(double from, float to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, float to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange upTo(double from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange upTo(double from, char to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(double from, char to) {
return new DoubleRange(from, to - from);
}
public static CharRange upTo(char from, byte to) {
public static CharRange rangeTo(char from, byte to) {
if (from > to) {
return CharRange.empty;
}
@@ -573,16 +305,7 @@ public class Ranges {
}
}
public static CharRange downTo(char from, byte to) {
if (from >= to) {
return new CharRange(from, to - from - 1);
}
else {
return CharRange.empty;
}
}
public static ShortRange upTo(char from, short to) {
public static ShortRange rangeTo(char from, short to) {
if (from > to) {
return ShortRange.empty;
}
@@ -591,16 +314,7 @@ public class Ranges {
}
}
public static ShortRange downTo(char from, short to) {
if (from >= to) {
return new ShortRange((short) from, to - from - 1);
}
else {
return ShortRange.empty;
}
}
public static IntRange upTo(char from, int to) {
public static IntRange rangeTo(char from, int to) {
if (from > to) {
return IntRange.empty;
}
@@ -609,16 +323,7 @@ public class Ranges {
}
}
public static IntRange downTo(char from, int to) {
if (from >= to) {
return new IntRange(from, to - from - 1);
}
else {
return IntRange.empty;
}
}
public static LongRange upTo(char from, long to) {
public static LongRange rangeTo(char from, long to) {
if (from > to) {
return LongRange.empty;
}
@@ -627,32 +332,15 @@ public class Ranges {
}
}
public static LongRange downTo(char from, long to) {
if (from >= to) {
return new LongRange(from, to - from - 1);
}
else {
return LongRange.empty;
}
}
public static FloatRange upTo(char from, float to) {
public static FloatRange rangeTo(char from, float to) {
return new FloatRange(from, to - from);
}
public static FloatRange downTo(char from, float to) {
return new FloatRange(from, to - from);
}
public static DoubleRange upTo(char from, double to) {
public static DoubleRange rangeTo(char from, double to) {
return new DoubleRange(from, to - from);
}
public static DoubleRange downTo(char from, double to) {
return new DoubleRange(from, to - from);
}
public static CharRange upTo(char from, char to) {
public static CharRange rangeTo(char from, char to) {
if (from > to) {
return CharRange.empty;
}
@@ -661,15 +349,6 @@ public class Ranges {
}
}
public static CharRange downTo(char from, char to) {
if (from >= to) {
return new CharRange(from, to - from - 1);
}
else {
return CharRange.empty;
}
}
public static void main(String[] args) {
List<String> strings = Arrays.asList("byte", "short", "int", "long", "float", "double", "char");
for (String t1 : strings) {
@@ -698,15 +377,12 @@ public class Ranges {
}
if (resType.equals("FloatRange") || resType.equals("DoubleRange")) {
System.out.println("\npublic static " + resType + " upTo(" + t1 + " from, " + t2 + " to) {\n" +
" return new " + resType + "(from, to-from);\n" +
"}");
System.out.println("\npublic static " + resType + " downTo(" + t1 + " from, " + t2 + " to) {\n" +
System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {\n" +
" return new " + resType + "(from, to-from);\n" +
"}");
}
else {
System.out.println("\npublic static " + resType + " upTo(" + t1 + " from, " + t2 + " to) {" +
System.out.println("\npublic static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {" +
"\n if(from > to) {\n" +
" return " + resType + ".empty;\n" +
" }\n" +
@@ -714,14 +390,6 @@ public class Ranges {
" return new " + resType + "(from, to-from+1);\n" +
" }\n" +
"}");
System.out.println("\npublic static " + resType + " downTo(" + t1 + " from, " + t2 + " to) {" +
"\n if(from >= to) {\n" +
" return new " + resType + "(from, to-from-1);\n" +
" }\n" +
" else {\n" +
" return " + resType + ".empty;\n" +
" }\n" +
"}");
}
}
}