From 84e37b3745ae699a7ea6c1dc569a8e4012b0bf81 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Tue, 8 Nov 2011 22:08:28 -0500 Subject: [PATCH] fix various warnings after enabling more warnings --- .../com/typesafe/config/impl/ConfigInt.java | 3 ++- .../com/typesafe/config/impl/ConfigList.java | 1 + .../com/typesafe/config/impl/ConfigLong.java | 3 ++- .../config/impl/ConfigSubstitution.java | 1 + .../config/impl/DefaultTransformer.java | 22 +++++++++++++++++++ .../config/impl/SimpleConfigObject.java | 1 + 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/typesafe/config/impl/ConfigInt.java b/src/main/java/com/typesafe/config/impl/ConfigInt.java index 1425ff49..fb9906a6 100644 --- a/src/main/java/com/typesafe/config/impl/ConfigInt.java +++ b/src/main/java/com/typesafe/config/impl/ConfigInt.java @@ -22,6 +22,7 @@ final class ConfigInt extends AbstractConfigValue { return value; } + @Override protected boolean canEqual(Object other) { return other instanceof ConfigInt || other instanceof ConfigLong; } @@ -33,7 +34,7 @@ final class ConfigInt extends AbstractConfigValue { return this.value == ((ConfigInt) other).value; } else if (other instanceof ConfigLong) { Long l = ((ConfigLong) other).unwrapped(); - return ((long) l.intValue()) == l && this.value == l.intValue(); + return l.intValue() == l && this.value == l.intValue(); } else { return false; } diff --git a/src/main/java/com/typesafe/config/impl/ConfigList.java b/src/main/java/com/typesafe/config/impl/ConfigList.java index e27db690..89aa6e14 100644 --- a/src/main/java/com/typesafe/config/impl/ConfigList.java +++ b/src/main/java/com/typesafe/config/impl/ConfigList.java @@ -72,6 +72,7 @@ final class ConfigList extends AbstractConfigValue { } } + @Override protected boolean canEqual(Object other) { return other instanceof ConfigList; } diff --git a/src/main/java/com/typesafe/config/impl/ConfigLong.java b/src/main/java/com/typesafe/config/impl/ConfigLong.java index 58cdab74..274e4f6e 100644 --- a/src/main/java/com/typesafe/config/impl/ConfigLong.java +++ b/src/main/java/com/typesafe/config/impl/ConfigLong.java @@ -22,6 +22,7 @@ final class ConfigLong extends AbstractConfigValue { return value; } + @Override protected boolean canEqual(Object other) { return other instanceof ConfigInt || other instanceof ConfigLong; } @@ -33,7 +34,7 @@ final class ConfigLong extends AbstractConfigValue { return this.value == ((ConfigLong) other).value; } else if (other instanceof ConfigInt) { Long l = this.unwrapped(); - return ((long) l.intValue()) == l + return l.intValue() == l && ((ConfigInt) other).unwrapped() == l.intValue(); } else { return false; diff --git a/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java b/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java index 6beef824..627321fb 100644 --- a/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java +++ b/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java @@ -133,6 +133,7 @@ final class ConfigSubstitution extends AbstractConfigValue { return resolved; } + @Override protected boolean canEqual(Object other) { return other instanceof ConfigSubstitution; } diff --git a/src/main/java/com/typesafe/config/impl/DefaultTransformer.java b/src/main/java/com/typesafe/config/impl/DefaultTransformer.java index 6c1e9a84..0d317413 100644 --- a/src/main/java/com/typesafe/config/impl/DefaultTransformer.java +++ b/src/main/java/com/typesafe/config/impl/DefaultTransformer.java @@ -38,6 +38,15 @@ class DefaultTransformer implements ConfigTransformer { return new ConfigBoolean(value.origin(), false); } break; + case LIST: + // can't go STRING to LIST automatically + break; + case OBJECT: + // can't go STRING to OBJECT automatically + break; + case STRING: + // no-op STRING to STRING + break; } } else if (requested == ConfigValueType.STRING) { // if we converted null to string here, then you wouldn't properly @@ -48,6 +57,19 @@ class DefaultTransformer implements ConfigTransformer { case BOOLEAN: return new ConfigString(value.origin(), value.transformToString()); + case NULL: + // want to be sure this throws instead of returning "null" as a + // string + break; + case OBJECT: + // no OBJECT to STRING automatically + break; + case LIST: + // no LIST to STRING automatically + break; + case STRING: + // no-op STRING to STRING + break; } } diff --git a/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java b/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java index c5c2aa07..32e2bf7e 100644 --- a/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java +++ b/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java @@ -70,6 +70,7 @@ class SimpleConfigObject extends AbstractConfigObject { return 41 * (41 + keys.hashCode()) + valuesHash; } + @Override protected boolean canEqual(Object other) { return other instanceof ConfigObject; }