Skip to content

Commit

Permalink
Remove unnecessary parenthesis from lambdas (#3968)
Browse files Browse the repository at this point in the history
Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn authored Dec 27, 2023
1 parent ec05a63 commit b08a01c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void play(@Nullable AudioStream audioStream, @Nullable String sinkId, @Nu
AudioSink sink = getSink(sinkId);
if (sink != null) {
Runnable restoreVolume = handleVolumeCommand(volume, sink);
sink.processAndComplete(audioStream).exceptionally((exception) -> {
sink.processAndComplete(audioStream).exceptionally(exception -> {
logger.warn("Error playing '{}': {}", audioStream, exception.getMessage(), exception);
return null;
}).thenRun(restoreVolume);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public void asConfigurableServiceDefinedProperties() {
properties.put(SERVICE_PROPERTY_FACTORY_SERVICE, factory);
properties.put(SERVICE_PROPERTY_LABEL, label);

ConfigurableService configurableService = ConfigurableServiceUtil
.asConfigurableService((key) -> properties.get(key));
ConfigurableService configurableService = ConfigurableServiceUtil.asConfigurableService(properties::get);

assertThat(configurableService.annotationType(), is(ConfigurableService.class));
assertThat(configurableService.category(), is(category));
Expand All @@ -57,8 +56,7 @@ public void asConfigurableServiceDefinedProperties() {
public void asConfigurableServiceUndefinedProperties() {
Properties properties = new Properties();

ConfigurableService configurableService = ConfigurableServiceUtil
.asConfigurableService((key) -> properties.get(key));
ConfigurableService configurableService = ConfigurableServiceUtil.asConfigurableService(properties::get);

assertThat(configurableService.annotationType(), is(ConfigurableService.class));
assertThat(configurableService.category(), is(emptyString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private List<ConfigurableServiceDTO> getServicesByFilter(String filter, Locale l
for (ServiceReference<?> serviceReference : serviceReferences) {
String id = getServiceId(serviceReference);
ConfigurableService configurableService = ConfigurableServiceUtil
.asConfigurableService((key) -> serviceReference.getProperty(key));
.asConfigurableService(serviceReference::getProperty);

String defaultLabel = configurableService.label();
if (defaultLabel.isEmpty()) { // for multi context services the label can be changed and must be read
Expand Down Expand Up @@ -336,7 +336,7 @@ private List<ConfigurableServiceDTO> getServicesByFilter(String filter, Locale l

if (refs != null && refs.length > 0) {
ConfigurableService configurableService = ConfigurableServiceUtil
.asConfigurableService((key) -> refs[0].getProperty(key));
.asConfigurableService(key -> refs[0].getProperty(key));
configDescriptionURI = configurableService.description_uri();
}
} catch (InvalidSyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ protected void addAudioSink(AudioSink audioSink) {
}

protected void removeAudioSink(AudioSink audioSink) {
stopDialogs((dialog) -> dialog.dialogContext.sink().getId().equals(audioSink.getId()));
stopDialogs(dialog -> dialog.dialogContext.sink().getId().equals(audioSink.getId()));
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
Expand All @@ -674,7 +674,7 @@ protected void addAudioSource(AudioSource audioSource) {
}

protected void removeAudioSource(AudioSource audioSource) {
stopDialogs((dialog) -> dialog.dialogContext.source().getId().equals(audioSource.getId()));
stopDialogs(dialog -> dialog.dialogContext.source().getId().equals(audioSource.getId()));
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
Expand All @@ -685,7 +685,7 @@ protected void addKSService(KSService ksService) {

protected void removeKSService(KSService ksService) {
this.ksServices.remove(ksService.getId());
stopDialogs((dialog) -> {
stopDialogs(dialog -> {
var ks = dialog.dialogContext.ks();
return ks != null && ks.getId().equals(ksService.getId());
});
Expand All @@ -699,7 +699,7 @@ protected void addSTTService(STTService sttService) {

protected void removeSTTService(STTService sttService) {
this.sttServices.remove(sttService.getId());
stopDialogs((dialog) -> dialog.dialogContext.stt().getId().equals(sttService.getId()));
stopDialogs(dialog -> dialog.dialogContext.stt().getId().equals(sttService.getId()));
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
Expand All @@ -710,7 +710,7 @@ protected void addTTSService(TTSService ttsService) {

protected void removeTTSService(TTSService ttsService) {
this.ttsServices.remove(ttsService.getId());
stopDialogs((dialog) -> dialog.dialogContext.tts().getId().equals(ttsService.getId()));
stopDialogs(dialog -> dialog.dialogContext.tts().getId().equals(ttsService.getId()));
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
Expand All @@ -721,7 +721,7 @@ protected void addHumanLanguageInterpreter(HumanLanguageInterpreter humanLanguag

protected void removeHumanLanguageInterpreter(HumanLanguageInterpreter humanLanguageInterpreter) {
this.humanLanguageInterpreters.remove(humanLanguageInterpreter.getId());
stopDialogs((dialog) -> dialog.dialogContext.hlis().stream()
stopDialogs(dialog -> dialog.dialogContext.hlis().stream()
.anyMatch(hli -> hli.getId().equals(humanLanguageInterpreter.getId())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ protected List<Item> getMatchingItems(ResourceBundle language, String[] labelFra
@Nullable
private Item filterMatchedItemsByLocation(Map<Item, ItemInterpretationMetadata> itemsData, String locationContext) {
var itemsFilteredByLocation = itemsData.entrySet().stream()
.filter((entry) -> entry.getValue().locationParentNames.contains(locationContext)).toList();
.filter(entry -> entry.getValue().locationParentNames.contains(locationContext)).toList();
if (itemsFilteredByLocation.size() != 1) {
return null;
}
Expand All @@ -1015,7 +1015,7 @@ private static void insertDiscardingMembers(Map<Item, ItemInterpretationMetadata
String name = item.getName();
boolean insert = items.keySet().stream().noneMatch(i -> name.startsWith(i.getName()));
if (insert) {
items.keySet().removeIf((matchedItem) -> matchedItem.getName().startsWith(name));
items.keySet().removeIf(matchedItem -> matchedItem.getName().startsWith(name));
items.put(item, interpretationMetadata);
}
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ private Expression parseItemRuleTokenText(Locale locale, String tokenText, Item
throw new ParseException("The character '|' can not be used alone", 0);
}
Expression expression = seq(tokenText.contains("|") ? alt(Arrays.stream(tokenText.split("\\|"))//
.filter((s) -> !s.isBlank()).toArray()) : tokenText);
.filter(s -> !s.isBlank()).toArray()) : tokenText);
if (optional) {
return opt(expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected void modified(Map<String, Object> properties) {
* @return an instance to use
*/
public static ScheduledExecutorService getScheduledPool(String poolName) {
ExecutorService pool = pools.computeIfAbsent(poolName, (name) -> {
ExecutorService pool = pools.computeIfAbsent(poolName, name -> {
int cfg = getConfig(name);
ScheduledThreadPoolExecutor executor = new WrappedScheduledExecutorService(cfg,
new NamedThreadFactory(name, true, Thread.NORM_PRIORITY));
Expand All @@ -149,7 +149,7 @@ public static ScheduledExecutorService getScheduledPool(String poolName) {
* @return an instance to use
*/
public static ExecutorService getPool(String poolName) {
ExecutorService pool = pools.computeIfAbsent(poolName, (name) -> {
ExecutorService pool = pools.computeIfAbsent(poolName, name -> {
int cfg = getConfig(name);
ThreadPoolExecutor executor = QueueingThreadPoolExecutor.createInstance(name, cfg);
executor.setKeepAliveTime(THREAD_TIMEOUT, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private Checker parseSub(final String cronExpression, final ChronoField chronoFi
return CronAdjuster::isLastWorkingDayInMonth;
} else if (sub.endsWith("W")) {
final int n = parseInt(cronExpression, chronoField, sub.substring(0, sub.length() - 1));
return (temporal) -> isNearestWorkDay(temporal, n);
return temporal -> isNearestWorkDay(temporal, n);
}
// fall through, it is a normal expression
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void loadResultsFromCacheDirectoryTest() throws IOException {
file2Writer.write("falsedata");
}
when(storage.stream())
.thenAnswer((invocation) -> Stream.of(new AbstractMap.SimpleImmutableEntry("key1", metadataSample1),
.thenAnswer(invocation -> Stream.of(new AbstractMap.SimpleImmutableEntry("key1", metadataSample1),
new AbstractMap.SimpleImmutableEntry("key2", metadataSample2)));

// create a LRU cache that will use the above data
Expand Down Expand Up @@ -322,7 +322,7 @@ public void cleanDirectoryOrphanFilesTest() throws IOException {

// prepare storage map for stream operation
when(storage.stream())
.thenAnswer((invocation) -> Stream.of(new AbstractMap.SimpleImmutableEntry("key1", metadataSample1),
.thenAnswer(invocation -> Stream.of(new AbstractMap.SimpleImmutableEntry("key1", metadataSample1),
new AbstractMap.SimpleImmutableEntry("key2", metadataSample2)));

// prepare some files : orphan file
Expand Down Expand Up @@ -386,7 +386,7 @@ public void cleanDirectoryEmptyFilesTest() throws IOException {
public void faultyStreamTest() throws IOException {
MetadataSample metadata = new MetadataSample("meta1", 42);

when(supplier.get()).thenAnswer((invocation) -> new LRUMediaCacheEntry<>("key", inputStreamMock, metadata));
when(supplier.get()).thenAnswer(invocation -> new LRUMediaCacheEntry<>("key", inputStreamMock, metadata));
// In this test the stream will return two bytes of data, then an empty stream so signal its end.
// it will be called twice, so return it twice
when(inputStreamMock.readNBytes(any(Integer.class))).thenReturn(new byte[2], new byte[0], new byte[2],
Expand Down

0 comments on commit b08a01c

Please sign in to comment.