Skip to content

Commit

Permalink
Reduce SAT warnings (openhab#3932)
Browse files Browse the repository at this point in the history
Signed-off-by: Holger Friedrich <[email protected]>
  • Loading branch information
holgerfriedrich authored Dec 19, 2023
1 parent 8bed621 commit 24b1784
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void removeCurrencyProvider(CurrencyProvider currencyProvider) {
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ public ProcessAddonFinder() {
// 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];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ public void addItem(Item item) {
}
if (getMatchingConfigurations(FORECAST).anyMatch(configuration -> appliesToItem(configuration, item))) {
scheduleNextPersistedForecastForItem(item.getName());

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public Set<Locale> getSupportedLocales() {

@Override
public void createRules(@Nullable Locale locale) {

/****************************** ENGLISH ******************************/

if (locale == null || Objects.equals(locale.getLanguage(), Locale.ENGLISH.getLanguage())) {
Expand Down Expand Up @@ -173,7 +172,6 @@ public void createRules(@Nullable Locale locale) {
/****************************** 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");
Expand Down Expand Up @@ -237,7 +235,6 @@ public void createRules(@Nullable Locale locale) {
seq(schalte, denDieDas), /* item */ seq(opt("auf"), labeledCmd)//
), //
Locale.GERMAN).toArray(Rule[]::new));

}

/****************************** FRENCH ******************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ private Expression parseItemRuleTokenText(Locale locale, String tokenText, Item
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("\\|"))//
Expand Down Expand Up @@ -1542,7 +1542,7 @@ public List<Class<? extends Command>> getCommandClasses(@Nullable Item ignored)
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;
Expand All @@ -1563,7 +1563,7 @@ public boolean filterItem(Item item, MetadataRegistry metadataRegistry) {
}

public static ItemFilter all() {
return allInstance;
return ALL_INSTANCE;
}

public static ItemFilter forItem(Item item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void allowUseCustomCommandCommands() throws InterpretationException {

@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"));
Expand All @@ -255,20 +255,20 @@ public void allowHandleQuestionWithCustomCommand() throws InterpretationExceptio
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"));
Expand All @@ -286,14 +286,14 @@ public void allowForceCustomCommand() throws InterpretationException {
};
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public record Entry(Instant timestamp, State state) {

@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;
}
Expand Down

0 comments on commit 24b1784

Please sign in to comment.