Cleanup code (#3787)

This code cleanup fixes various warnings in Eclipse.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2023-08-30 22:50:17 +02:00 committed by GitHub
parent d7fbb94490
commit c39d15ade6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 33 additions and 59 deletions

View File

@ -12,16 +12,13 @@
*/
package org.openhab.core.automation.module.script.rulesupport.loader;
import static java.nio.file.StandardWatchEventKinds.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.openhab.core.OpenHAB.CONFIG_DIR_PROG_ARGUMENT;
import static org.openhab.core.service.WatchService.Kind.CREATE;
import static org.openhab.core.service.WatchService.Kind.DELETE;
import static org.openhab.core.service.WatchService.Kind.MODIFY;
import static org.openhab.core.service.WatchService.Kind.*;
import java.io.File;
import java.io.IOException;

View File

@ -112,12 +112,10 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler implem
module.getId());
return;
}
} else if (event instanceof ItemRemovedEvent removedEvent) {
if (itemName.equals(removedEvent.getItem().name)) {
logger.warn("Item '{}' needed for rule '{}' removed. Condition '{}' will no longer work.", itemName,
ruleUID, module.getId());
return;
}
} else if ((event instanceof ItemRemovedEvent removedEvent) && itemName.equals(removedEvent.getItem().name)) {
logger.warn("Item '{}' needed for rule '{}' removed. Condition '{}' will no longer work.", itemName,
ruleUID, module.getId());
return;
}
}
@ -155,7 +153,7 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler implem
return false;
}
@SuppressWarnings({ "rawtypes", "unchecked", "null" })
@SuppressWarnings("unchecked")
private boolean lessThanOrEqualsToItemState(String itemName, String state) throws ItemNotFoundException {
Item item = itemRegistry.getItem(itemName);
State compareState = TypeParser.parseState(item.getAcceptedDataTypes(), state);
@ -192,7 +190,7 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler implem
return false;
}
@SuppressWarnings({ "rawtypes", "unchecked", "null" })
@SuppressWarnings("unchecked")
private boolean greaterThanOrEqualsToItemState(String itemName, String state) throws ItemNotFoundException {
Item item = itemRegistry.getItem(itemName);
State compareState = TypeParser.parseState(item.getAcceptedDataTypes(), state);

View File

@ -15,10 +15,7 @@ package org.openhab.core.automation.internal.module.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import java.util.Map;
@ -27,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
@ -56,6 +54,8 @@ public class SystemTriggerHandlerTest {
private @Mock @NonNullByDefault({}) Trigger triggerMock;
private @Captor @NonNullByDefault({}) ArgumentCaptor<Map<String, Object>> captor;
@BeforeEach
public void setup() {
when(triggerMock.getConfiguration())
@ -96,10 +96,9 @@ public class SystemTriggerHandlerTest {
Event event = SystemEventFactory.createStartlevelEvent(100);
triggerHandler.receive(event);
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
verify(callbackMock).triggered(eq(triggerMock), captor.capture());
Map<String, Object> configuration = (Map<String, Object>) captor.getValue();
Map<String, Object> configuration = captor.getValue();
assertThat(configuration.get(SystemTriggerHandler.OUT_STARTLEVEL), is(CFG_STARTLEVEL));
}
@ -113,10 +112,9 @@ public class SystemTriggerHandlerTest {
Event event = SystemEventFactory.createStartlevelEvent(100);
triggerHandler.receive(event);
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
verify(callbackMock).triggered(eq(triggerMock), captor.capture());
Map<String, Object> configuration = (Map<String, Object>) captor.getValue();
Map<String, Object> configuration = captor.getValue();
assertThat(configuration.get(SystemTriggerHandler.OUT_STARTLEVEL), is(CFG_STARTLEVEL));
triggerHandler.receive(event);

View File

@ -93,7 +93,6 @@ public class ConfigDescriptionParameterGroupBuilder {
*
* @return the desired result
*/
@SuppressWarnings("deprecation")
public ConfigDescriptionParameterGroup build() throws IllegalArgumentException {
return new ConfigDescriptionParameterGroup(name, context, advanced != null ? advanced : false, label,
description);

View File

@ -32,7 +32,6 @@ import com.google.gson.JsonSerializer;
*/
public class ConfigurationSerializer implements JsonSerializer<Configuration> {
@SuppressWarnings("unchecked")
@Override
public JsonElement serialize(Configuration src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();

View File

@ -322,7 +322,7 @@ public class BitUtilitiesCommandToRegistersTest {
);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
@ParameterizedTest
@MethodSource("data")
public void testCommandToRegisters(Command command, ValueType type, Object expectedResult) {

View File

@ -354,7 +354,7 @@ public class BitUtilitiesExtractStateFromRegistersTest {
.collect(Collectors.toList()));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
@ParameterizedTest
@MethodSource("data")
public void testextractStateFromRegisters(Object expectedResult, ValueType type, ModbusRegisterArray registers,

View File

@ -103,7 +103,7 @@ public class BitUtilitiesExtractStringTest {
});
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
@ParameterizedTest
@MethodSource("data")
public void testExtractStringFromRegisters(Object expectedResult, ModbusRegisterArray registers, int index,
@ -119,7 +119,7 @@ public class BitUtilitiesExtractStringTest {
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
@ParameterizedTest
@MethodSource("dataWithByteVariations")
public void testExtractStringFromBytes(Object expectedResult, int byteOffset, byte[] bytes, int byteIndex,

View File

@ -32,7 +32,7 @@ public class ItemHistoryDTO {
public List<HistoryDataBean> data = new ArrayList<>();
public ItemHistoryDTO() {
};
}
/**
* Add a new record to the data history.
@ -41,7 +41,6 @@ public class ItemHistoryDTO {
* @param time the time of the record
* @param state the state at this time
*/
@SuppressWarnings("rawtypes")
public void addData(Long time, State state) {
HistoryDataBean newVal = new HistoryDataBean();
newVal.time = time;

View File

@ -35,7 +35,6 @@ import org.openhab.core.common.registry.RegistryChangeListener;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.events.EventSubscriber;
import org.openhab.core.i18n.UnitProvider;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemFactory;
import org.openhab.core.items.ItemRegistry;
@ -73,7 +72,6 @@ import org.openhab.core.thing.profiles.ProfileFactory;
import org.openhab.core.thing.profiles.ProfileTypeUID;
import org.openhab.core.thing.profiles.StateProfile;
import org.openhab.core.thing.profiles.TriggerProfile;
import org.openhab.core.thing.type.ChannelTypeRegistry;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.Type;
@ -123,7 +121,6 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
private final Logger logger = LoggerFactory.getLogger(CommunicationManager.class);
private final AutoUpdateManager autoUpdateManager;
private final ChannelTypeRegistry channelTypeRegistry;
private final SystemProfileFactory defaultProfileFactory;
private final ItemChannelLinkRegistry itemChannelLinkRegistry;
private final ItemRegistry itemRegistry;
@ -131,22 +128,19 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
private final EventPublisher eventPublisher;
private final SafeCaller safeCaller;
private final ThingRegistry thingRegistry;
private final UnitProvider unitProvider;
private final ExpiringCacheMap<Integer, Profile> profileSafeCallCache = new ExpiringCacheMap<>(CACHE_EXPIRATION);
@Activate
public CommunicationManager(final @Reference AutoUpdateManager autoUpdateManager,
final @Reference ChannelTypeRegistry channelTypeRegistry,
final @Reference SystemProfileFactory defaultProfileFactory,
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry,
final @Reference ItemRegistry itemRegistry, //
final @Reference ItemStateConverter itemStateConverter, //
final @Reference EventPublisher eventPublisher, //
final @Reference SafeCaller safeCaller, //
final @Reference ThingRegistry thingRegistry, final @Reference UnitProvider unitProvider) {
final @Reference ThingRegistry thingRegistry) {
this.autoUpdateManager = autoUpdateManager;
this.channelTypeRegistry = channelTypeRegistry;
this.defaultProfileFactory = defaultProfileFactory;
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
this.itemRegistry = itemRegistry;
@ -154,7 +148,6 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
this.eventPublisher = eventPublisher;
this.safeCaller = safeCaller;
this.thingRegistry = thingRegistry;
this.unitProvider = unitProvider;
itemChannelLinkRegistry.addRegistryChangeListener(this);
}

View File

@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
*
* @author Michael Grammling - Initial contribution
*/
@SuppressWarnings({ "serial", "rawtypes" })
@SuppressWarnings("rawtypes")
@NonNullByDefault
public class ThingDescriptionList extends ArrayList {

View File

@ -72,7 +72,7 @@ public class MetadataRegistryImpl extends AbstractRegistry<Metadata, MetadataKey
* @param itemname the name of the item for which the namespaces should be searched.
*/
@Override
public Collection getAllNamespaces(String itemname) {
public Collection<String> getAllNamespaces(String itemname) {
return stream().map(Metadata::getUID).filter(key -> key.getItemName().equals(itemname))
.map(MetadataKey::getNamespace).collect(Collectors.toSet());
}

View File

@ -184,7 +184,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
* @return a new {@link QuantityType}
*/
public static <T extends Quantity<T>> QuantityType<T> valueOf(double value, Unit<T> unit) {
return new QuantityType<T>(value, unit);
return new QuantityType<>(value, unit);
}
@Override
@ -204,7 +204,6 @@ public class QuantityType<T extends Quantity<T>> extends Number
return new QuantityType<>(value);
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
@ -229,7 +228,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
@Override
public int compareTo(QuantityType<T> o) {
return internalCompareTo((QuantityType<?>) o);
return internalCompareTo(o);
}
private int internalCompareTo(QuantityType<?> o) {
@ -269,7 +268,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
UnitConverter uc = getUnit().getConverterToAny(targetUnit);
Quantity<?> result = Quantities.getQuantity(uc.convert(quantity.getValue()), targetUnit);
return new QuantityType<T>(result.getValue(), (Unit<T>) targetUnit);
return new QuantityType<>(result.getValue(), (Unit<T>) targetUnit);
} catch (UnconvertibleException | IncommensurableException e) {
logger.debug("Unable to convert unit from {} to {}", getUnit(), targetUnit);
return null;
@ -306,7 +305,6 @@ public class QuantityType<T extends Quantity<T>> extends Number
return toUnit(targetUnit);
}
@SuppressWarnings("unchecked")
public @Nullable QuantityType<?> toInvertibleUnit(String targetUnit) {
Unit<?> unit = AbstractUnit.parse(targetUnit);
if (unit != null) {
@ -328,7 +326,6 @@ public class QuantityType<T extends Quantity<T>> extends Number
* @param targetUnit the unit to which this {@link QuantityType} will be converted to.
* @return the new {@link QuantityType} in the given {@link Unit} or {@code null} in case of an error.
*/
@SuppressWarnings("unchecked")
public @Nullable QuantityType<T> toUnitRelative(Unit<T> targetUnit) {
if (targetUnit.equals(getUnit())) {
return this;
@ -338,7 +335,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
}
Quantity<?> result = quantity.to(targetUnit);
return new QuantityType<T>(result.getValue(), targetUnit);
return new QuantityType<>(result.getValue(), targetUnit);
}
public BigDecimal toBigDecimal() {
@ -478,7 +475,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
* @return the sum of the given {@link QuantityType} with this QuantityType.
*/
public QuantityType<T> add(QuantityType<T> state) {
return new QuantityType<T>(this.quantity.add(state.quantity));
return new QuantityType<>(this.quantity.add(state.quantity));
}
/**
@ -497,7 +494,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
* @return the difference by subtracting the given {@link QuantityType} from this QuantityType.
*/
public QuantityType<T> subtract(QuantityType<T> state) {
return new QuantityType<T>(this.quantity.subtract(state.quantity));
return new QuantityType<>(this.quantity.subtract(state.quantity));
}
/**
@ -549,7 +546,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
public QuantityType<T> offset(QuantityType<T> offset, Unit<T> unit) {
final Quantity<T> sum = Arrays.asList(quantity, offset.quantity).stream().reduce(QuantityFunctions.sum(unit))
.get();
return new QuantityType<T>(sum);
return new QuantityType<>(sum);
}
/**

View File

@ -12,8 +12,9 @@
*/
package org.openhab.core.library.items;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.util.Objects;
@ -68,7 +69,6 @@ public class NumberItemTest {
private final UnitProvider unitProvider = new TestUnitProvider();
@BeforeEach
@SuppressWarnings("unchecked")
public void setup() {
when(stateDescriptionServiceMock.getStateDescription(ITEM_NAME, null))
.thenReturn(StateDescriptionFragmentBuilder.create().withPattern("%.1f " + UnitUtils.UNIT_PLACEHOLDER)

View File

@ -81,7 +81,6 @@ public class StateDescriptionFragmentBuilderTest {
assertThat(builder.withOptions(options).build().getOptions(), is(options));
}
@SuppressWarnings("deprecation")
@Test
public void builderWithStateDescription() {
StateDescription source = new StateDescription(BigDecimal.ZERO, BigDecimal.TEN, BigDecimal.ONE, "pattern", true,

View File

@ -79,7 +79,6 @@ import org.openhab.core.thing.profiles.StateProfile;
import org.openhab.core.thing.profiles.TriggerProfile;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelType;
import org.openhab.core.thing.type.ChannelTypeRegistry;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
@ -148,7 +147,6 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
ChannelBuilder.create(TRIGGER_CHANNEL_UID_2).withKind(ChannelKind.TRIGGER).build()).build();
private @Mock @NonNullByDefault({}) AutoUpdateManager autoUpdateManagerMock;
private @Mock @NonNullByDefault({}) ChannelTypeRegistry channelTypeRegistryMock;
private @Mock @NonNullByDefault({}) EventPublisher eventPublisherMock;
private @Mock @NonNullByDefault({}) ItemRegistry itemRegistryMock;
private @Mock @NonNullByDefault({}) ItemStateConverter itemStateConverterMock;
@ -177,9 +175,8 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
assertNotNull(profileFactory);
manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry,
itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock,
UNIT_PROVIDER_MOCK);
manager = new CommunicationManager(autoUpdateManagerMock, profileFactory, iclRegistry, itemRegistryMock,
itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock);
doAnswer(invocation -> {
switch (((Channel) invocation.getArguments()[0]).getKind()) {
@ -232,8 +229,6 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
ChannelType channelType4 = mock(ChannelType.class);
when(channelType4.getItemType()).thenReturn("Number:Temperature");
when(channelTypeRegistryMock.getChannelType(CHANNEL_TYPE_UID_4)).thenReturn(channelType4);
THING.setHandler(thingHandlerMock);
when(thingRegistryMock.get(eq(THING_UID))).thenReturn(THING);