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
|
||||
* @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.
|
||||
|
@ -93,7 +93,7 @@ import net.bigeon.gclc.manager.EmptyInput;
|
||||
public final class ParametrizedCommandData {
|
||||
|
||||
/** The boolean parameters mandatory status. */
|
||||
private final Set<String> boolParams = new HashSet<>();
|
||||
private final Set<String> boolParams = new HashSet<>();
|
||||
|
||||
/** The string parameters mandatory status. */
|
||||
private final Map<String, Boolean> stringParams = new ConcurrentHashMap<>();
|
||||
@ -101,7 +101,7 @@ public final class ParametrizedCommandData {
|
||||
private final Map<String, Boolean> params = new ConcurrentHashMap<>();
|
||||
/** The restriction of provided parameters on execution to declared paramters in
|
||||
* the status maps. */
|
||||
private final boolean strict;
|
||||
private final boolean strict;
|
||||
|
||||
/** The data for the parametrized command. */
|
||||
public ParametrizedCommandData() {
|
||||
@ -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.
|
||||
|
@ -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);
|
||||
final Object mLock = messageBlocker.get(message);
|
||||
if (mLock!=null) {
|
||||
synchronized (mLock) {
|
||||
mLock.notifyAll();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user