various fixes suggested by findbugs

This commit is contained in:
Havoc Pennington 2011-11-09 00:07:43 -05:00
parent cd6bf42cdc
commit d0ac801720
6 changed files with 18 additions and 14 deletions

View File

@ -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,

View File

@ -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);
/**

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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();
}
}