- Notifications
You must be signed in to change notification settings - Fork 44
Config add getBoolean, getInt, getLong, getDouble, getString #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@ ## master #21 +/- ## ============================================ + Coverage 80.88% 81.08% +0.19% - Complexity 793 804 +11 ============================================ Files 79 79 Lines 2611 2638 +27 Branches 236 242 +6 ============================================ + Hits 2112 2139 +27 Misses 380 380 Partials 119 119
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve title: add Config getXxValue for number type
return this.allConfig.get(option); | ||
} | ||
| ||
public int getByte(String key, byte defaultValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not call get(TypedOption)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The algorithm specific parameters are not in ComputerOptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove getByte and getShort
if (value == null) { | ||
return defaultValue; | ||
} else { | ||
return Double.parseDouble(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check exception and throw more friendly exception
return Integer.parseInt(value); | ||
} catch (Exception e) { | ||
throw new ComputerException( | ||
"Can't parse '%s' into int for key '%s'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't parse byte value from '%s' for key '%s'
} | ||
} | ||
| ||
public int getShort(String key, short defaultValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this method
if (value == null) { | ||
return defaultValue; | ||
} else { | ||
return Boolean.parseBoolean(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no exception when parseBoolean, anything not "true" will regard it "false".
public static boolean parseBoolean(String s) {
return ((s != null) && s.equalsIgnoreCase("true"));
}
return this.allConfig.get(option); | ||
} | ||
| ||
public boolean getBoolean(String key, boolean defaultValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also update PR title
"Can't parse boolean value from '%s' for key '%s'", | ||
value, key); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
Config config = new Config(options); | ||
Assert.assertEquals(value, config.getString(KEY, defaultValue)); | ||
Assert.assertEquals(defaultValue, | ||
config.getString(KEY_EMPTY, defaultValue)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test pass defaultValue=null
No description provided.