mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 23:01:05 +08:00
move newNumber to ConfigNumber rather than AbstractConfigValue
This commit is contained in:
parent
3610dc8d76
commit
d1e12fdd36
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user