Avoid contains and get calls on same key in map
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
de593c00a1
commit
d5a7d4a16f
@ -103,8 +103,8 @@ public final class CommandParameters {
|
|||||||
* @param key the key
|
* @param key the key
|
||||||
* @return if the key was specified */
|
* @return if the key was specified */
|
||||||
public boolean getBool(final String key) {
|
public boolean getBool(final String key) {
|
||||||
return booleanArguments.containsKey(key)
|
Boolean val = booleanArguments.get(key);
|
||||||
&& booleanArguments.get(key).booleanValue();
|
return val != null && val.booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the boolean arguments.
|
/** Get the boolean arguments.
|
||||||
|
@ -120,8 +120,7 @@ public final class ParametrizedCommandData {
|
|||||||
* @param flag the boolean flag
|
* @param flag the boolean flag
|
||||||
* @throws InvalidParameterException if the parameter is already defined as a
|
* @throws InvalidParameterException if the parameter is already defined as a
|
||||||
* string parameter */
|
* string parameter */
|
||||||
public void addBooleanParameter(final String flag)
|
public void addBooleanParameter(final String flag) throws InvalidParameterException {
|
||||||
throws InvalidParameterException {
|
|
||||||
if (params.containsKey(flag) && stringParams.containsKey(flag)) {
|
if (params.containsKey(flag) && stringParams.containsKey(flag)) {
|
||||||
throw new InvalidParameterException("Parameter is already defined as string"); //$NON-NLS-1$
|
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 */
|
* @throws InvalidParameterException if the new definition is invalid */
|
||||||
private void checkParam(final String param, final boolean needed)
|
private void checkParam(final String param, final boolean needed)
|
||||||
throws InvalidParameterException {
|
throws InvalidParameterException {
|
||||||
if (stringParams.containsKey(param)) {
|
Boolean val = stringParams.get(param);
|
||||||
final Boolean need = Boolean
|
if (val != null) {
|
||||||
.valueOf(needed || stringParams.get(param).booleanValue());
|
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
|
||||||
stringParams.put(param, need);
|
stringParams.put(param, need);
|
||||||
params.put(param, need);
|
params.put(param, need);
|
||||||
return;
|
return;
|
||||||
@ -182,8 +181,8 @@ public final class ParametrizedCommandData {
|
|||||||
* @param args the command arguments
|
* @param args the command arguments
|
||||||
* @return the command object
|
* @return the command object
|
||||||
* @throws IOException if the command could not be filled. */
|
* @throws IOException if the command could not be filled. */
|
||||||
public CommandParameters getParameters(final ConsoleInput input,
|
public CommandParameters getParameters(final ConsoleInput input, final String... args)
|
||||||
final String... args) throws IOException {
|
throws IOException {
|
||||||
final CommandParameters parameters = new CommandParameters(boolParams,
|
final CommandParameters parameters = new CommandParameters(boolParams,
|
||||||
stringParams.keySet(), strict);
|
stringParams.keySet(), strict);
|
||||||
try {
|
try {
|
||||||
@ -218,7 +217,8 @@ public final class ParametrizedCommandData {
|
|||||||
* @param param the parameter name
|
* @param param the parameter name
|
||||||
* @return if the parameter is needed */
|
* @return if the parameter is needed */
|
||||||
public boolean isNeeded(final String param) {
|
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.
|
/** If the command refuse unrecognized parameters.
|
||||||
|
@ -306,8 +306,8 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
private void notifyMessage(final String message) {
|
private void notifyMessage(final String message) {
|
||||||
synchronized (messageBlockerLock) {
|
synchronized (messageBlockerLock) {
|
||||||
delivering = message;
|
delivering = message;
|
||||||
if (messageBlocker.containsKey(message)) {
|
|
||||||
final Object mLock = messageBlocker.get(message);
|
final Object mLock = messageBlocker.get(message);
|
||||||
|
if (mLock!=null) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mLock.notifyAll();
|
mLock.notifyAll();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user