Reduce SAT warnings (#17406)

* Reduce SAT warnings

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2024-09-13 17:20:11 +02:00
committed by GitHub
parent 2d61ffc409
commit 54fd13b0c1
107 changed files with 146 additions and 216 deletions
@@ -55,7 +55,7 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault
public class StateFilterProfile implements StateProfile {
private final static String OPERATOR_NAME_PATTERN = Stream.of(StateCondition.ComparisonType.values())
private static final String OPERATOR_NAME_PATTERN = Stream.of(StateCondition.ComparisonType.values())
.map(StateCondition.ComparisonType::name)
// We want to match the longest operator first, e.g. `GTE` before `GT`
.sorted(Comparator.comparingInt(String::length).reversed())
@@ -63,13 +63,13 @@ public class StateFilterProfile implements StateProfile {
// so we can have conditions against input data without needing a leading space, e.g. `GTE 0`
.collect(Collectors.joining("|", "(?:(?<=\\S)\\s+|^\\s*)(?:", ")\\s"));
private final static String OPERATOR_SYMBOL_PATTERN = Stream.of(StateCondition.ComparisonType.values())
private static final String OPERATOR_SYMBOL_PATTERN = Stream.of(StateCondition.ComparisonType.values())
.map(StateCondition.ComparisonType::symbol)
// We want to match the longest operator first, e.g. `<=` before `<`
.sorted(Comparator.comparingInt(String::length).reversed()) //
.collect(Collectors.joining("|", "(?:", ")"));
private final static Pattern EXPRESSION_PATTERN = Pattern.compile(
private static final Pattern EXPRESSION_PATTERN = Pattern.compile(
// - Without the non-greedy operator in the first capture group,
// it will match `Item<` when encountering `Item<>X` condition
// - Symbols may be more prevalently used, so check them first
@@ -47,8 +47,18 @@ import org.openhab.core.items.GenericItem;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemNotFoundException;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.library.items.*;
import org.openhab.core.library.types.*;
import org.openhab.core.library.items.ContactItem;
import org.openhab.core.library.items.DimmerItem;
import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.items.RollershutterItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.items.SwitchItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.profiles.ProfileCallback;
@@ -178,14 +188,16 @@ public class StateFilterProfileTest {
return item;
}
private Item numberItemWithState(String itemType, String itemName, State value) {
NumberItem item = new NumberItem(itemType, itemName, null);
item.setState(value);
return item;
}
/*
* private Item numberItemWithState(String itemType, String itemName, State value) {
* NumberItem item = new NumberItem(itemType, itemName, null);
* item.setState(value);
* return item;
* }
*/
@Test
public void testMultipleCondition_AllMatch() throws ItemNotFoundException {
public void testMultipleConditionAllMatch() throws ItemNotFoundException {
when(mockContext.getConfiguration())
.thenReturn(new Configuration(Map.of("conditions", "ItemName eq 'Value', ItemName2 eq 'Value2'")));
when(mockItemRegistry.getItem("ItemName")).thenReturn(stringItemWithState("ItemName", "Value"));
@@ -199,7 +211,7 @@ public class StateFilterProfileTest {
}
@Test
public void testMultipleCondition_SingleMatch() throws ItemNotFoundException {
public void testMultipleConditionSingleMatch() throws ItemNotFoundException {
when(mockContext.getConfiguration())
.thenReturn(new Configuration(Map.of("conditions", "ItemName eq Value, ItemName2 eq Value2")));
when(mockItemRegistry.getItem("ItemName")).thenReturn(stringItemWithState("ItemName", "Value"));
@@ -266,7 +278,7 @@ public class StateFilterProfileTest {
StringType s_foo = StringType.valueOf("foo");
StringType s_NULL = StringType.valueOf("NULL");
StringType s_UNDEF = StringType.valueOf("UNDEF");
StringType s_OPEN = StringType.valueOf("OPEN");
// StringType s_OPEN = StringType.valueOf("OPEN");
return Stream.of( //
// We should be able to check item state is/isn't UNDEF/NULL
@@ -595,7 +607,6 @@ public class StateFilterProfileTest {
@MethodSource
public void testComparingInputStateWithValue(GenericItem linkedItem, State inputState, String operator,
String value, boolean expected) throws ItemNotFoundException {
String linkedItemName = linkedItem.getName();
when(mockContext.getConfiguration()).thenReturn(new Configuration(Map.of("conditions", operator + value)));