Avoid contains and get calls on same key in map

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2018-10-14 09:59:46 -04:00
parent de593c00a1
commit d5a7d4a16f
3 changed files with 14 additions and 14 deletions

View File

@ -103,8 +103,8 @@ public final class CommandParameters {
* @param key the key
* @return if the key was specified */
public boolean getBool(final String key) {
return booleanArguments.containsKey(key)
&& booleanArguments.get(key).booleanValue();
Boolean val = booleanArguments.get(key);
return val != null && val.booleanValue();
}
/** Get the boolean arguments.

View File

@ -120,8 +120,7 @@ public final class ParametrizedCommandData {
* @param flag the boolean flag
* @throws InvalidParameterException if the parameter is already defined as a
* string parameter */
public void addBooleanParameter(final String flag)
throws InvalidParameterException {
public void addBooleanParameter(final String flag) throws InvalidParameterException {
if (params.containsKey(flag) && stringParams.containsKey(flag)) {
throw new InvalidParameterException("Parameter is already defined as string"); //$NON-NLS-1$
}
@ -152,9 +151,9 @@ public final class ParametrizedCommandData {
* @throws InvalidParameterException if the new definition is invalid */
private void checkParam(final String param, final boolean needed)
throws InvalidParameterException {
if (stringParams.containsKey(param)) {
final Boolean need = Boolean
.valueOf(needed || stringParams.get(param).booleanValue());
Boolean val = stringParams.get(param);
if (val != null) {
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
stringParams.put(param, need);
params.put(param, need);
return;
@ -182,8 +181,8 @@ public final class ParametrizedCommandData {
* @param args the command arguments
* @return the command object
* @throws IOException if the command could not be filled. */
public CommandParameters getParameters(final ConsoleInput input,
final String... args) throws IOException {
public CommandParameters getParameters(final ConsoleInput input, final String... args)
throws IOException {
final CommandParameters parameters = new CommandParameters(boolParams,
stringParams.keySet(), strict);
try {
@ -218,7 +217,8 @@ public final class ParametrizedCommandData {
* @param param the parameter name
* @return if the parameter is needed */
public boolean isNeeded(final String param) {
return params.containsKey(param) && params.get(param).booleanValue();
Boolean val = params.get(param);
return val != null && val.booleanValue();
}
/** If the command refuse unrecognized parameters.

View File

@ -306,8 +306,8 @@ public final class ReadingRunnable implements Runnable {
private void notifyMessage(final String message) {
synchronized (messageBlockerLock) {
delivering = message;
if (messageBlocker.containsKey(message)) {
final Object mLock = messageBlocker.get(message);
if (mLock!=null) {
synchronized (mLock) {
mLock.notifyAll();
}