Reduce SAT warnings (#3932)

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-12-19 20:37:57 +01:00
committed by GitHub
parent 8bed621c8c
commit 24b1784d44
7 changed files with 22 additions and 21 deletions
@@ -50,7 +50,7 @@ public class CurrencyServiceConfigOptionProvider implements ConfigOptionProvider
@Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
if ("system:units".equals(uri.toString()) && param.equals("currencyProvider")) {
if ("system:units".equals(uri.toString()) && "currencyProvider".equals(param)) {
return currencyProviders.stream().map(this::mapProvider).toList();
}
return null;
@@ -59,14 +59,17 @@ public class ProcessAddonFinder extends BaseAddonFinder {
// also tries to mitigate differences on different operating systems
String getProcessCommandProcess(ProcessHandle h) {
Optional<String> command = h.info().command();
if (command.isPresent())
if (command.isPresent()) {
return command.get();
}
Optional<String[]> args = h.info().arguments();
if (!args.isPresent())
if (!args.isPresent()) {
return "";
}
String[] argsArray = args.get();
if (argsArray.length < 1)
if (argsArray.length < 1) {
return "";
}
return argsArray[0];
}
@@ -498,7 +498,6 @@ public class PersistenceManager implements ItemRegistryChangeListener, StateChan
}
if (getMatchingConfigurations(FORECAST).anyMatch(configuration -> appliesToItem(configuration, item))) {
scheduleNextPersistedForecastForItem(item.getName());
}
}
}
@@ -90,7 +90,6 @@ public class StandardInterpreter extends AbstractRuleBasedInterpreter {
@Override
public void createRules(@Nullable Locale locale) {
/****************************** ENGLISH ******************************/
if (locale == null || Objects.equals(locale.getLanguage(), Locale.ENGLISH.getLanguage())) {
@@ -173,7 +172,6 @@ public class StandardInterpreter extends AbstractRuleBasedInterpreter {
/****************************** GERMAN ******************************/
if (locale == null || Objects.equals(locale.getLanguage(), Locale.GERMAN.getLanguage())) {
Expression einAnAus = alt(cmd("ein", OnOffType.ON), cmd("an", OnOffType.ON), cmd("aus", OnOffType.OFF));
Expression denDieDas = opt(alt("den", "die", "das"));
Expression schalte = alt("schalt", "schalte", "mach");
@@ -237,7 +235,6 @@ public class StandardInterpreter extends AbstractRuleBasedInterpreter {
seq(schalte, denDieDas), /* item */ seq(opt("auf"), labeledCmd)//
), //
Locale.GERMAN).toArray(Rule[]::new));
}
/****************************** FRENCH ******************************/
@@ -1240,7 +1240,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
if (tokenText.contains("?")) {
throw new ParseException("The character '?' can only be used at the end of the expression", 0);
}
if (tokenText.equals("|")) {
if ("|".equals(tokenText)) {
throw new ParseException("The character '|' can not be used alone", 0);
}
Expression expression = seq(tokenText.contains("|") ? alt(Arrays.stream(tokenText.split("\\|"))//
@@ -1542,7 +1542,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
public record ItemFilter(Set<String> itemNames, Set<String> excludedItemNames, Set<String> itemTags,
Set<String> itemSemantics) {
private static final ItemFilter allInstance = new ItemFilter(Set.of(), Set.of(), Set.of(), Set.of());
private static final ItemFilter ALL_INSTANCE = new ItemFilter(Set.of(), Set.of(), Set.of(), Set.of());
public boolean filterItem(Item item, MetadataRegistry metadataRegistry) {
if (!itemNames.isEmpty() && !itemNames.contains(item.getName())) {
return false;
@@ -1563,7 +1563,7 @@ public abstract class AbstractRuleBasedInterpreter implements HumanLanguageInter
}
public static ItemFilter all() {
return allInstance;
return ALL_INSTANCE;
}
public static ItemFilter forItem(Item item) {
@@ -244,7 +244,7 @@ public class StandardInterpreterTest {
@Test
public void allowHandleQuestionWithCustomCommand() throws InterpretationException {
var trigger_item = new StringItem("trigger_item") {
var triggerItem = new StringItem("trigger_item") {
@Override
public @Nullable CommandDescription getCommandDescription() {
return () -> List.of(new CommandOption("day", "day"), new CommandOption("time", "time"));
@@ -255,20 +255,20 @@ public class StandardInterpreterTest {
return getCommandDescription();
}
};
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, trigger_item.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, triggerItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "what $cmd$ is it", null));
List<Item> items = List.of(trigger_item);
List<Item> items = List.of(triggerItem);
when(itemRegistryMock.getItems()).thenReturn(items);
assertEquals(OK_RESPONSE, standardInterpreter.interpret(Locale.ENGLISH, "what time is it?"));
verify(eventPublisherMock, times(1))
.post(ItemEventFactory.createCommandEvent(trigger_item.getName(), new StringType("time")));
.post(ItemEventFactory.createCommandEvent(triggerItem.getName(), new StringType("time")));
reset(eventPublisherMock);
}
@Test
public void allowForceCustomCommand() throws InterpretationException {
var trigger_item = new StringItem("trigger_item") {
var triggerItem = new StringItem("trigger_item") {
@Override
public @Nullable CommandDescription getCommandDescription() {
return () -> List.of(new CommandOption("day", "day"), new CommandOption("time", "time"));
@@ -286,14 +286,14 @@ public class StandardInterpreterTest {
};
HashMap<String, Object> configuration = new HashMap<>();
configuration.put(IS_FORCED_CONFIGURATION, true);
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, trigger_item.getName());
MetadataKey voiceMetadataKey = new MetadataKey(VOICE_SYSTEM_NAMESPACE, triggerItem.getName());
when(metadataRegistryMock.get(voiceMetadataKey))
.thenReturn(new Metadata(voiceMetadataKey, "what $cmd$ is it", configuration));
List<Item> items = List.of(trigger_item);
List<Item> items = List.of(triggerItem);
when(itemRegistryMock.getItems()).thenReturn(items);
assertEquals(OK_RESPONSE, standardInterpreter.interpret(Locale.ENGLISH, "what time is it?"));
verify(eventPublisherMock, times(1))
.post(ItemEventFactory.createCommandEvent(trigger_item.getName(), new StringType("time")));
.post(ItemEventFactory.createCommandEvent(triggerItem.getName(), new StringType("time")));
reset(eventPublisherMock);
}
@@ -104,10 +104,12 @@ public class TimeSeries {
@Override
public boolean equals(@Nullable Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TimeSeries that = (TimeSeries) o;
return Objects.equals(states, that.states) && policy == that.policy;
}