mirror of
https://github.com/lightbend/config.git
synced 2025-01-28 21:20:07 +08:00
various fixes suggested by findbugs
This commit is contained in:
parent
cd6bf42cdc
commit
d0ac801720
@ -100,7 +100,7 @@ public final class Config {
|
||||
return units.toNanos(Long.parseLong(numberString));
|
||||
} else {
|
||||
long nanosInUnit = units.toNanos(1);
|
||||
return (new Double(Double.parseDouble(numberString) * nanosInUnit)).longValue();
|
||||
return (long) (Double.parseDouble(numberString) * nanosInUnit);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ConfigException.BadValue(originForException, pathForException,
|
||||
@ -175,8 +175,7 @@ public final class Config {
|
||||
if (numberString.matches("[0-9]+")) {
|
||||
return Long.parseLong(numberString) * units.bytes;
|
||||
} else {
|
||||
return (new Double(Double.parseDouble(numberString)
|
||||
* units.bytes)).longValue();
|
||||
return (long) (Double.parseDouble(numberString) * units.bytes);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ConfigException.BadValue(originForException,
|
||||
|
@ -14,14 +14,14 @@ import java.util.Set;
|
||||
* subclass of ConfigException.WrongType thrown if the value is null. The "path"
|
||||
* parameters for all the getters have periods between the key names, so the
|
||||
* path "a.b.c" looks for key c in object b in object a in the root object.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* TODO If you need to look up a key with a period in its name, there isn't a
|
||||
* way to do it right now.
|
||||
*
|
||||
*
|
||||
* TODO add OrNull variants of all these getters? Or better to avoid convenience
|
||||
* API for that?
|
||||
*
|
||||
*
|
||||
* TODO should it implement Map<String, ? extends ConfigValue> with the mutators
|
||||
* throwing ?
|
||||
*/
|
||||
@ -60,6 +60,8 @@ public interface ConfigObject extends ConfigValue {
|
||||
ConfigValue get(String path);
|
||||
|
||||
/** Get value as a size in bytes (parses special strings like "128M") */
|
||||
// rename getSizeInBytes ? clearer. allows a megabyte version
|
||||
// or just getBytes is consistent with getMilliseconds
|
||||
Long getMemorySize(String path);
|
||||
|
||||
/**
|
||||
|
@ -187,10 +187,11 @@ abstract class AbstractConfigObject extends AbstractConfigValue implements
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String key : objects.keySet()) {
|
||||
List<AbstractConfigObject> stackForKey = objects.get(key);
|
||||
for (Map.Entry<String, List<AbstractConfigObject>> entry : objects
|
||||
.entrySet()) {
|
||||
List<AbstractConfigObject> stackForKey = entry.getValue();
|
||||
AbstractConfigObject obj = merge(origin, stackForKey, transformer);
|
||||
merged.put(key, obj);
|
||||
merged.put(entry.getKey(), obj);
|
||||
}
|
||||
|
||||
return new SimpleConfigObject(origin, transformer, merged);
|
||||
|
@ -174,9 +174,10 @@ public class ConfigImpl {
|
||||
private static AbstractConfigObject loadEnvVariables() {
|
||||
Map<String, String> env = System.getenv();
|
||||
Map<String, AbstractConfigValue> m = new HashMap<String, AbstractConfigValue>();
|
||||
for (String key : env.keySet()) {
|
||||
for (Map.Entry<String, String> entry : env.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
m.put(key, new ConfigString(
|
||||
new SimpleConfigOrigin("env var " + key), env.get(key)));
|
||||
new SimpleConfigOrigin("env var " + key), entry.getValue()));
|
||||
}
|
||||
return new SimpleConfigObject(new SimpleConfigOrigin("env variables"),
|
||||
defaultConfigTransformer(), m);
|
||||
|
@ -26,7 +26,8 @@ final class Substitution {
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof Substitution) {
|
||||
Substitution that = (Substitution) other;
|
||||
return this.reference == that.reference && this.style == that.style;
|
||||
return this.reference.equals(that.reference)
|
||||
&& this.style == that.style;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ final class Tokens {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 41 * (41 * (41 + super.hashCode()) + value.hashCode())
|
||||
+ new Boolean(isPath()).hashCode();
|
||||
+ Boolean.valueOf(isPath()).hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user