[refactor] Use mapping computeIfPresent/Absent for conditional branch
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
d726312341
commit
8643b69054
@ -103,7 +103,7 @@ public final class CommandParameters {
|
||||
* @param key the key
|
||||
* @return if the key was specified */
|
||||
public boolean isActive(final String key) {
|
||||
Boolean val = booleanArguments.get(key);
|
||||
final Boolean val = booleanArguments.get(key);
|
||||
return val != null && val.booleanValue();
|
||||
}
|
||||
|
||||
@ -198,9 +198,8 @@ public final class CommandParameters {
|
||||
* @param string the key
|
||||
* @param value the value */
|
||||
public void set(final String string, final boolean value) {
|
||||
if (booleanArguments.containsKey(string)) {
|
||||
booleanArguments.put(string, Boolean.valueOf(value));
|
||||
}
|
||||
booleanArguments.computeIfPresent(string,
|
||||
(final String k, final Boolean v) -> Boolean.valueOf(value));
|
||||
}
|
||||
|
||||
/** Set a string parameter value.
|
||||
@ -208,8 +207,7 @@ public final class CommandParameters {
|
||||
* @param string the key
|
||||
* @param value the value */
|
||||
public void set(final String string, final String value) {
|
||||
if (stringArguments.containsKey(string)) {
|
||||
stringArguments.put(string, value);
|
||||
}
|
||||
stringArguments.computeIfPresent(string,
|
||||
(final String k, final String v) -> value);
|
||||
}
|
||||
}
|
||||
|
@ -149,14 +149,16 @@ public final class ParametrizedCommandData {
|
||||
* @param needed if the parameter is needed
|
||||
* @throws InvalidParameterException if the new definition is invalid */
|
||||
private void checkParam(final String param, final boolean needed) {
|
||||
final Boolean val = stringParams.get(param);
|
||||
if (val != null) {
|
||||
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
|
||||
stringParams.put(param, need);
|
||||
final Boolean val = stringParams.computeIfPresent(param,
|
||||
(final String k, final Boolean v) -> {
|
||||
final Boolean need = Boolean.valueOf(needed || v.booleanValue());
|
||||
params.put(param, need);
|
||||
return;
|
||||
return need;
|
||||
});
|
||||
if (val == null) {
|
||||
throw new InvalidParameterException(
|
||||
"Parameter is already defined as boolean"); //$NON-NLS-1$
|
||||
}
|
||||
throw new InvalidParameterException("Parameter is already defined as boolean"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/** Retrieve the boolean parameters (aka flags).
|
||||
|
@ -202,9 +202,7 @@ public final class ReadingRunnable implements Runnable {
|
||||
public void waitForDelivery(final String message) throws InterruptedException {
|
||||
Object mLock;
|
||||
synchronized (messageBlockerLock) {
|
||||
if (!messageBlocker.containsKey(message)) {
|
||||
messageBlocker.put(message, new Object());
|
||||
}
|
||||
messageBlocker.computeIfAbsent(message, (final String k) -> new Object());
|
||||
mLock = messageBlocker.get(message);
|
||||
}
|
||||
synchronized (mLock) {
|
||||
|
Loading…
Reference in New Issue
Block a user