move newNumber to ConfigNumber rather than AbstractConfigValue

This commit is contained in:
Havoc Pennington 2011-11-16 15:08:29 -05:00
parent 3610dc8d76
commit d1e12fdd36
4 changed files with 23 additions and 23 deletions

View File

@ -121,22 +121,4 @@ abstract class AbstractConfigValue implements ConfigValue {
String transformToString() {
return null;
}
static ConfigNumber newNumber(ConfigOrigin origin, long number,
String originalText) {
if (number <= Integer.MAX_VALUE && number >= Integer.MIN_VALUE)
return new ConfigInt(origin, (int) number, originalText);
else
return new ConfigLong(origin, number, originalText);
}
static ConfigNumber newNumber(ConfigOrigin origin, double number,
String originalText) {
long asLong = (long) number;
if (asLong == number) {
return newNumber(origin, asLong, originalText);
} else {
return new ConfigDouble(origin, number, originalText);
}
}
}

View File

@ -62,4 +62,22 @@ abstract class ConfigNumber extends AbstractConfigValue {
}
return (int) (asLong ^ (asLong >>> 32));
}
static ConfigNumber newNumber(ConfigOrigin origin, long number,
String originalText) {
if (number <= Integer.MAX_VALUE && number >= Integer.MIN_VALUE)
return new ConfigInt(origin, (int) number, originalText);
else
return new ConfigLong(origin, number, originalText);
}
static ConfigNumber newNumber(ConfigOrigin origin, double number,
String originalText) {
long asLong = (long) number;
if (asLong == number) {
return newNumber(origin, asLong, originalText);
} else {
return new ConfigDouble(origin, number, originalText);
}
}
}

View File

@ -265,18 +265,18 @@ final class Tokens {
}
static Token newInt(ConfigOrigin origin, int value, String originalText) {
return newValue(AbstractConfigValue.newNumber(origin, value,
return newValue(ConfigNumber.newNumber(origin, value,
originalText));
}
static Token newDouble(ConfigOrigin origin, double value,
String originalText) {
return newValue(AbstractConfigValue.newNumber(origin, value,
return newValue(ConfigNumber.newNumber(origin, value,
originalText));
}
static Token newLong(ConfigOrigin origin, long value, String originalText) {
return newValue(AbstractConfigValue.newNumber(origin, value,
return newValue(ConfigNumber.newNumber(origin, value,
originalText));
}

View File

@ -408,8 +408,8 @@ class ConfigValueTest extends TestUtils {
@Test
def newNumberWorks() {
def nL(v: Long) = AbstractConfigValue.newNumber(fakeOrigin(), v, null)
def nD(v: Double) = AbstractConfigValue.newNumber(fakeOrigin(), v, null)
def nL(v: Long) = ConfigNumber.newNumber(fakeOrigin(), v, null)
def nD(v: Double) = ConfigNumber.newNumber(fakeOrigin(), v, null)
// the general idea is that the destination type should depend
// only on the actual numeric value, not on the type of the source