Fix null type mismatch errors (#2976)
This fixes the null type errors in Eclipse which were introduced by #2906. Signed-off-by: Wouter Born <github@maindrain.net>pull/2978/head
parent
ad3a3c1caf
commit
86ee4dc2b5
|
@ -13,16 +13,13 @@
|
|||
package org.openhab.core.automation.module.script;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
|
@ -81,7 +78,7 @@ public class ScriptTransformationServiceTest {
|
|||
|
||||
@Test
|
||||
public void success() throws TransformationException {
|
||||
String returnValue = service.transform(SCRIPT_TYPE + ":" + SCRIPT_UID, "input");
|
||||
String returnValue = Objects.requireNonNull(service.transform(SCRIPT_TYPE + ":" + SCRIPT_UID, "input"));
|
||||
|
||||
assertThat(returnValue, is(SCRIPT_OUTPUT));
|
||||
}
|
||||
|
|
|
@ -290,37 +290,35 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
|||
|
||||
@Override
|
||||
public String interpret(String text, @Nullable String hliIdList) throws InterpretationException {
|
||||
List<HumanLanguageInterpreter> interpreters;
|
||||
List<HumanLanguageInterpreter> interpreters = new ArrayList<>();
|
||||
if (hliIdList == null) {
|
||||
HumanLanguageInterpreter interpreter = getHLI();
|
||||
if (interpreter == null) {
|
||||
throw new InterpretationException("No human language interpreter available!");
|
||||
if (interpreter != null) {
|
||||
interpreters.add(interpreter);
|
||||
}
|
||||
interpreters = List.of(interpreter);
|
||||
} else {
|
||||
interpreters = getHLIsByIds(hliIdList);
|
||||
if (interpreters.isEmpty()) {
|
||||
throw new InterpretationException("No human language interpreter can be found for " + hliIdList);
|
||||
}
|
||||
|
||||
if (!interpreters.isEmpty()) {
|
||||
Locale locale = localeProvider.getLocale();
|
||||
for (var interpreter : interpreters) {
|
||||
try {
|
||||
String answer = interpreter.interpret(locale, text);
|
||||
logger.debug("Interpretation result: {}", answer);
|
||||
return answer;
|
||||
} catch (InterpretationException e) {
|
||||
logger.debug("Interpretation exception: {}", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
String answer = null;
|
||||
InterpretationException error = null;
|
||||
Locale locale = localeProvider.getLocale();
|
||||
for (var interpreter : interpreters) {
|
||||
try {
|
||||
answer = interpreter.interpret(locale, text);
|
||||
logger.debug("Interpretation result: {}", answer);
|
||||
error = null;
|
||||
break;
|
||||
} catch (InterpretationException e) {
|
||||
logger.debug("Interpretation exception: {}", e.getMessage());
|
||||
error = e;
|
||||
}
|
||||
|
||||
if (hliIdList == null) {
|
||||
throw new InterpretationException("No human language interpreter available!");
|
||||
} else {
|
||||
throw new InterpretationException("No human language interpreter can be found for " + hliIdList);
|
||||
}
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
private @Nullable Voice getVoice(String id) {
|
||||
|
@ -354,27 +352,13 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
|||
// Return the first concrete AudioFormat found
|
||||
for (AudioFormat currentAudioFormat : audioFormats) {
|
||||
// Check if currentAudioFormat is abstract
|
||||
if (null == currentAudioFormat.getCodec()) {
|
||||
if ((null == currentAudioFormat.getCodec()) || (null == currentAudioFormat.getContainer())
|
||||
|| (null == currentAudioFormat.isBigEndian()) || (null == currentAudioFormat.getBitDepth())) {
|
||||
continue;
|
||||
}
|
||||
if (null == currentAudioFormat.getContainer()) {
|
||||
continue;
|
||||
}
|
||||
if (null == currentAudioFormat.isBigEndian()) {
|
||||
continue;
|
||||
}
|
||||
if (null == currentAudioFormat.getBitDepth()) {
|
||||
continue;
|
||||
}
|
||||
if (null == currentAudioFormat.getBitRate()) {
|
||||
continue;
|
||||
}
|
||||
if (null == currentAudioFormat.getFrequency()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prefer WAVE container
|
||||
if (!AudioFormat.CONTAINER_WAVE.equals(currentAudioFormat.getContainer())) {
|
||||
if ((null == currentAudioFormat.getBitRate()) || (null == currentAudioFormat.getFrequency())
|
||||
|| !AudioFormat.CONTAINER_WAVE.equals(currentAudioFormat.getContainer())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -388,15 +372,9 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
|||
AudioFormat format = currentAudioFormat;
|
||||
|
||||
// Not all Codecs and containers can be supported
|
||||
if (null == format.getCodec()) {
|
||||
continue;
|
||||
}
|
||||
if (null == format.getContainer()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prefer WAVE container
|
||||
if (!AudioFormat.CONTAINER_WAVE.equals(format.getContainer())) {
|
||||
if ((null == format.getCodec()) || (null == format.getContainer())
|
||||
|| !AudioFormat.CONTAINER_WAVE.equals(format.getContainer())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -813,7 +791,7 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
|||
}
|
||||
|
||||
private Set<Voice> getAllVoicesSorted(Locale locale) {
|
||||
return ttsServices.values().stream().map(s -> s.getAvailableVoices()).flatMap(Collection::stream)
|
||||
return ttsServices.values().stream().map(TTSService::getAvailableVoices).flatMap(Collection::stream)
|
||||
.sorted(createVoiceComparator(locale)).collect(Collectors
|
||||
.collectingAndThen(Collectors.toCollection(LinkedHashSet::new), Collections::unmodifiableSet));
|
||||
}
|
||||
|
@ -836,9 +814,8 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
|||
return (tts1 == null || tts2 == null) ? 0
|
||||
: tts1.getLabel(locale).compareToIgnoreCase(tts2.getLabel(locale));
|
||||
};
|
||||
Comparator<Voice> byVoiceLocale = (Voice v1, Voice v2) -> {
|
||||
return v1.getLocale().getDisplayName(locale).compareToIgnoreCase(v2.getLocale().getDisplayName(locale));
|
||||
};
|
||||
Comparator<Voice> byVoiceLocale = (Voice v1, Voice v2) -> v1.getLocale().getDisplayName(locale)
|
||||
.compareToIgnoreCase(v2.getLocale().getDisplayName(locale));
|
||||
return byTTSLabel.thenComparing(byVoiceLocale).thenComparing(Voice::getLabel);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue