Use diamond operator (#4001)

Often the type can be inferred so the diamond operator can be used to simplify the code.

Signed-off-by: Wouter Born <github@maindrain.net>
pull/4007/head
Wouter Born 2024-01-03 08:22:43 +01:00 committed by GitHub
parent dc5f50db63
commit 58a106d36d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 45 additions and 47 deletions

View File

@ -137,7 +137,7 @@ public class MarketplaceRuleTemplateProvider extends AbstractManagedProvider<Rul
try {
RuleTemplateDTO dto = yamlMapper.readValue(yaml, RuleTemplateDTO.class);
// add a tag with the add-on ID to be able to identify the widget in the registry
dto.tags = new HashSet<@Nullable String>((dto.tags != null) ? dto.tags : new HashSet<String>());
dto.tags = new HashSet<@Nullable String>((dto.tags != null) ? dto.tags : new HashSet<>());
dto.tags.add(uid);
RuleTemplate entry = RuleTemplateDTOMapper.map(dto);
RuleTemplate template = new RuleTemplate(entry.getUID(), entry.getLabel(), entry.getDescription(),

View File

@ -28,6 +28,6 @@ public class ManagedUserLoginConfiguration extends Configuration {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
return new AppConfigurationEntry[] { new AppConfigurationEntry(ManagedUserLoginModule.class.getCanonicalName(),
LoginModuleControlFlag.SUFFICIENT, new HashMap<String, Object>()) };
LoginModuleControlFlag.SUFFICIENT, new HashMap<>()) };
}
}

View File

@ -190,7 +190,7 @@ public class ModbusLibraryWrapper {
*/
public static ModbusTransaction createTransactionForEndpoint(ModbusSlaveEndpoint endpoint,
ModbusSlaveConnection connection) {
ModbusTransaction transaction = endpoint.accept(new ModbusSlaveEndpointVisitor<ModbusTransaction>() {
ModbusTransaction transaction = endpoint.accept(new ModbusSlaveEndpointVisitor<>() {
@Override
public @NonNull ModbusTransaction visit(ModbusTCPSlaveEndpoint modbusIPSlavePoolingKey) {

View File

@ -488,7 +488,7 @@ public class ModbusManagerImpl implements ModbusManager {
try {
logger.trace("Calling error response callback {} for request {}. Error was {} {}", callback, request,
error.getClass().getName(), error.getMessage());
callback.handle(new AsyncModbusFailure<R>(request, error));
callback.handle(new AsyncModbusFailure<>(request, error));
} finally {
logger.trace("Called write response callback {} for request {}. Error was {} {}", callback, request,
error.getClass().getName(), error.getMessage());

View File

@ -952,7 +952,7 @@ public class SmokeTest extends IntegrationTestSupport {
*/
private static class SpyingSocketFactory implements SocketImplFactory {
Queue<SocketImpl> sockets = new ConcurrentLinkedQueue<SocketImpl>();
Queue<SocketImpl> sockets = new ConcurrentLinkedQueue<>();
@Override
public SocketImpl createSocketImpl() {

View File

@ -42,7 +42,7 @@ public class ManagedUserBackingEngine implements BackingEngine {
@Override
public void addUser(String username, String password) {
userRegistry.register(username, password, new HashSet<String>(Set.of(Role.USER)));
userRegistry.register(username, password, new HashSet<>(Set.of(Role.USER)));
}
@Override

View File

@ -28,7 +28,7 @@ public class SitemapConverters extends DefaultTerminalConverters {
@ValueConverter(rule = "Icon")
public IValueConverter<String> Icon() {
return new IValueConverter<String>() {
return new IValueConverter<>() {
@Override
public String toValue(String string, INode node) throws ValueConverterException {
@ -50,7 +50,7 @@ public class SitemapConverters extends DefaultTerminalConverters {
@ValueConverter(rule = "Command")
public IValueConverter<String> Command() {
return new AbstractNullSafeConverter<String>() {
return new AbstractNullSafeConverter<>() {
@Override
protected String internalToValue(String string, INode node) {
if ((string.startsWith("'") && string.endsWith("'"))

View File

@ -106,29 +106,29 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro
} else if (RANGE.equals(profileTypeUID)) {
return new SystemRangeStateProfile(callback, context);
} else if (BUTTON_TOGGLE_SWITCH.equals(profileTypeUID)) {
return new ToggleProfile<OnOffType>(callback, context, BUTTON_TOGGLE_SWITCH,
return new ToggleProfile<>(callback, context, BUTTON_TOGGLE_SWITCH,
DefaultSystemChannelTypeProvider.SYSTEM_BUTTON, OnOffType.ON, OnOffType.OFF,
CommonTriggerEvents.SHORT_PRESSED);
} else if (BUTTON_TOGGLE_PLAYER.equals(profileTypeUID)) {
return new ToggleProfile<PlayPauseType>(callback, context, BUTTON_TOGGLE_PLAYER,
return new ToggleProfile<>(callback, context, BUTTON_TOGGLE_PLAYER,
DefaultSystemChannelTypeProvider.SYSTEM_BUTTON, PlayPauseType.PLAY, PlayPauseType.PAUSE,
CommonTriggerEvents.SHORT_PRESSED);
} else if (BUTTON_TOGGLE_ROLLERSHUTTER.equals(profileTypeUID)) {
return new ToggleProfile<UpDownType>(callback, context, BUTTON_TOGGLE_ROLLERSHUTTER,
return new ToggleProfile<>(callback, context, BUTTON_TOGGLE_ROLLERSHUTTER,
DefaultSystemChannelTypeProvider.SYSTEM_BUTTON, UpDownType.UP, UpDownType.DOWN,
CommonTriggerEvents.SHORT_PRESSED);
} else if (RAWBUTTON_ON_OFF_SWITCH.equals(profileTypeUID)) {
return new RawButtonOnOffSwitchProfile(callback);
} else if (RAWBUTTON_TOGGLE_SWITCH.equals(profileTypeUID)) {
return new ToggleProfile<OnOffType>(callback, context, RAWBUTTON_TOGGLE_SWITCH,
return new ToggleProfile<>(callback, context, RAWBUTTON_TOGGLE_SWITCH,
DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON, OnOffType.ON, OnOffType.OFF,
CommonTriggerEvents.PRESSED);
} else if (RAWBUTTON_TOGGLE_PLAYER.equals(profileTypeUID)) {
return new ToggleProfile<PlayPauseType>(callback, context, RAWBUTTON_TOGGLE_PLAYER,
return new ToggleProfile<>(callback, context, RAWBUTTON_TOGGLE_PLAYER,
DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON, PlayPauseType.PLAY, PlayPauseType.PAUSE,
CommonTriggerEvents.PRESSED);
} else if (RAWBUTTON_TOGGLE_ROLLERSHUTTER.equals(profileTypeUID)) {
return new ToggleProfile<UpDownType>(callback, context, RAWBUTTON_TOGGLE_ROLLERSHUTTER,
return new ToggleProfile<>(callback, context, RAWBUTTON_TOGGLE_ROLLERSHUTTER,
DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON, UpDownType.UP, UpDownType.DOWN,
CommonTriggerEvents.PRESSED);
} else if (RAWROCKER_DIMMER.equals(profileTypeUID)) {

View File

@ -36,7 +36,7 @@ import org.openhab.core.config.core.dto.ConfigDescriptionDTO;
public class RootUIComponent extends UIComponent implements Identifiable<String> {
String uid;
Set<String> tags = new HashSet<String>();
Set<String> tags = new HashSet<>();
ConfigDescriptionDTO props;

View File

@ -52,7 +52,7 @@ public class UIComponent {
public UIComponent(String componentType) {
super();
this.component = componentType;
this.config = new HashMap<String, Object>();
this.config = new HashMap<>();
}
/**
@ -136,9 +136,9 @@ public class UIComponent {
*/
public List<UIComponent> addSlot(String slotName) {
if (slots == null) {
slots = new HashMap<String, List<UIComponent>>();
slots = new HashMap<>();
}
List<UIComponent> newSlot = new ArrayList<UIComponent>();
List<UIComponent> newSlot = new ArrayList<>();
this.slots.put(slotName, newSlot);
return newSlot;

View File

@ -122,7 +122,7 @@ public class TTSLRUCacheImpl implements TTSCache {
fileAndMetadata = lruMediaCacheLocal.get(key, () -> {
try {
AudioStream audioInputStream = tts.synthesizeForCache(text, voice, requestedFormat);
return new LRUMediaCacheEntry<AudioFormatInfo>(key, audioInputStream,
return new LRUMediaCacheEntry<>(key, audioInputStream,
new AudioFormatInfo(audioInputStream.getFormat()));
} catch (TTSException e) {
throw new IllegalStateException(e);

View File

@ -63,7 +63,7 @@ public class SafeCallerImpl implements SafeCaller {
@Override
public <T> SafeCallerBuilder<T> create(T target, Class<T> interfaceType) {
return new SafeCallerBuilderImpl<T>(target, new Class<?>[] { interfaceType }, manager);
return new SafeCallerBuilderImpl<>(target, new Class<?>[] { interfaceType }, manager);
}
protected ExecutorService getScheduler() {

View File

@ -40,8 +40,8 @@ import org.osgi.service.component.annotations.ReferencePolicy;
@Component
public class StateDescriptionServiceImpl implements StateDescriptionService {
private final Set<StateDescriptionFragmentProvider> stateDescriptionFragmentProviders = Collections.synchronizedSet(
new TreeSet<StateDescriptionFragmentProvider>(new Comparator<StateDescriptionFragmentProvider>() {
private final Set<StateDescriptionFragmentProvider> stateDescriptionFragmentProviders = Collections
.synchronizedSet(new TreeSet<>(new Comparator<>() {
@Override
public int compare(StateDescriptionFragmentProvider provider1,
StateDescriptionFragmentProvider provider2) {

View File

@ -92,7 +92,7 @@ public final class ImperialUnits extends CustomUnits {
new TransformedUnit<>("gal", CUBIC_INCH, MultiplyConverter.of(231.0)));
public static final Unit<VolumetricFlowRate> GALLON_PER_MINUTE = addUnit(
new ProductUnit<VolumetricFlowRate>(GALLON_LIQUID_US.divide(tech.units.indriya.unit.Units.MINUTE)));
new ProductUnit<>(GALLON_LIQUID_US.divide(tech.units.indriya.unit.Units.MINUTE)));
/**
* Add unit symbols for imperial units.

View File

@ -95,10 +95,10 @@ public final class Units extends CustomUnits {
public static final Unit<Angle> DEGREE_ANGLE = addUnit(NonSI.DEGREE_ANGLE);
public static final Unit<Angle> RADIAN = addUnit(tech.units.indriya.unit.Units.RADIAN);
public static final Unit<ArealDensity> DOBSON_UNIT = addUnit(
new ProductUnit<ArealDensity>(MetricPrefix.MILLI(tech.units.indriya.unit.Units.MOLE).multiply(0.4462)
new ProductUnit<>(MetricPrefix.MILLI(tech.units.indriya.unit.Units.MOLE).multiply(0.4462)
.divide(tech.units.indriya.unit.Units.SQUARE_METRE)));
public static final Unit<CatalyticActivity> KATAL = addUnit(tech.units.indriya.unit.Units.KATAL);
public static final Unit<Density> KILOGRAM_PER_CUBICMETRE = addUnit(new ProductUnit<Density>(
public static final Unit<Density> KILOGRAM_PER_CUBICMETRE = addUnit(new ProductUnit<>(
tech.units.indriya.unit.Units.KILOGRAM.divide(tech.units.indriya.unit.Units.CUBIC_METRE)));
public static final Unit<Density> MICROGRAM_PER_CUBICMETRE = addUnit(new TransformedUnit<>(KILOGRAM_PER_CUBICMETRE,
MultiplyConverter.ofRational(BigInteger.ONE, BigInteger.valueOf(1000000000))));
@ -117,8 +117,8 @@ public final class Units extends CustomUnits {
tech.units.indriya.unit.Units.COULOMB.multiply(3600));
public static final Unit<ElectricCharge> MILLIAMPERE_HOUR = addUnit(MetricPrefix.MILLI(AMPERE_HOUR));
public static final Unit<ElectricConductance> SIEMENS = addUnit(tech.units.indriya.unit.Units.SIEMENS);
public static final Unit<ElectricConductivity> SIEMENS_PER_METRE = addUnit(new ProductUnit<ElectricConductivity>(
tech.units.indriya.unit.Units.SIEMENS.divide(tech.units.indriya.unit.Units.METRE)));
public static final Unit<ElectricConductivity> SIEMENS_PER_METRE = addUnit(
new ProductUnit<>(tech.units.indriya.unit.Units.SIEMENS.divide(tech.units.indriya.unit.Units.METRE)));
public static final Unit<ElectricInductance> HENRY = addUnit(tech.units.indriya.unit.Units.HENRY);
public static final Unit<ElectricPotential> VOLT = addUnit(tech.units.indriya.unit.Units.VOLT);
public static final Unit<ElectricResistance> OHM = addUnit(tech.units.indriya.unit.Units.OHM);
@ -193,16 +193,16 @@ public final class Units extends CustomUnits {
public static final Unit<Time> WEEK = addUnit(tech.units.indriya.unit.Units.WEEK);
public static final Unit<Time> MONTH = addUnit(tech.units.indriya.unit.Units.MONTH);
public static final Unit<Time> YEAR = addUnit(tech.units.indriya.unit.Units.YEAR);
public static final Unit<VolumetricFlowRate> LITRE_PER_MINUTE = addUnit(new ProductUnit<VolumetricFlowRate>(
tech.units.indriya.unit.Units.LITRE.divide(tech.units.indriya.unit.Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_SECOND = addUnit(new ProductUnit<VolumetricFlowRate>(
tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.SECOND)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_MINUTE = addUnit(new ProductUnit<VolumetricFlowRate>(
tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_HOUR = addUnit(new ProductUnit<VolumetricFlowRate>(
tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.HOUR)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_DAY = addUnit(new ProductUnit<VolumetricFlowRate>(
tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.DAY)));
public static final Unit<VolumetricFlowRate> LITRE_PER_MINUTE = addUnit(
new ProductUnit<>(tech.units.indriya.unit.Units.LITRE.divide(tech.units.indriya.unit.Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_SECOND = addUnit(
new ProductUnit<>(tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.SECOND)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_MINUTE = addUnit(
new ProductUnit<>(tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_HOUR = addUnit(
new ProductUnit<>(tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.HOUR)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_DAY = addUnit(
new ProductUnit<>(tech.units.indriya.unit.Units.CUBIC_METRE.divide(tech.units.indriya.unit.Units.DAY)));
public static final Unit<DataAmount> BIT = addUnit(new BaseUnit<>("bit", UnitDimension.parse('X')));
public static final Unit<DataAmount> KILOBIT = addUnit(MetricPrefix.KILO(BIT));
public static final Unit<DataAmount> MEGABIT = addUnit(MetricPrefix.MEGA(BIT));
@ -227,7 +227,7 @@ public final class Units extends CustomUnits {
public static final Unit<DataAmount> TEBIOCTET = addUnit(BinaryPrefix.TEBI(OCTET));
public static final Unit<DataAmount> PEBIOCTET = addUnit(BinaryPrefix.PEBI(OCTET));
public static final Unit<DataTransferRate> BIT_PER_SECOND = addUnit(
new ProductUnit<DataTransferRate>(BIT.divide(tech.units.indriya.unit.Units.SECOND)));
new ProductUnit<>(BIT.divide(tech.units.indriya.unit.Units.SECOND)));
public static final Unit<DataTransferRate> KILOBIT_PER_SECOND = addUnit(MetricPrefix.KILO(BIT_PER_SECOND));
public static final Unit<DataTransferRate> MEGABIT_PER_SECOND = addUnit(MetricPrefix.MEGA(BIT_PER_SECOND));
public static final Unit<DataTransferRate> GIGABIT_PER_SECOND = addUnit(MetricPrefix.GIGA(BIT_PER_SECOND));

View File

@ -74,8 +74,7 @@ public class LRUMediaCacheEntryTest {
}
private LRUMediaCache<MetadataSample> createCache(long size) throws IOException {
return new LRUMediaCache<MetadataSample>(storageService, size, "lrucachetest.pid",
this.getClass().getClassLoader());
return new LRUMediaCache<>(storageService, size, "lrucachetest.pid", this.getClass().getClassLoader());
}
public static class FakeStream extends InputStream {

View File

@ -75,8 +75,7 @@ public class LRUMediaCacheTest {
}
private LRUMediaCache<MetadataSample> createCache(long size) throws IOException {
return new LRUMediaCache<MetadataSample>(storageService, size, "lrucachetest.pid",
this.getClass().getClassLoader());
return new LRUMediaCache<>(storageService, size, "lrucachetest.pid", this.getClass().getClassLoader());
}
/**

View File

@ -375,10 +375,10 @@ public class QuantityTypeTest {
assertEquals(ImperialUnits.FAHRENHEIT, result.getUnit());
// test associativity of add
QuantityType<Temperature> tempResult = new QuantityType<Temperature>("1 °F")
.add(new QuantityType<Temperature>("2 °F")).add(new QuantityType<Temperature>("3 °F"));
QuantityType<Temperature> tempResult = new QuantityType<Temperature>("1 °F").add(new QuantityType<>("2 °F"))
.add(new QuantityType<>("3 °F"));
assertThat(tempResult, is(new QuantityType<Temperature>("1 °F")
.add(new QuantityType<Temperature>("2 °F").add(new QuantityType<Temperature>("3 °F")))));
.add(new QuantityType<Temperature>("2 °F").add(new QuantityType<>("3 °F")))));
assertThat(tempResult, is(new QuantityType<Temperature>("6 °F")));
assertThat(new QuantityType<>("65 kWh").add(new QuantityType<>("1 kWh")), is(new QuantityType<>("66 kWh")));

View File

@ -115,7 +115,7 @@ public class ManagedThingProviderOSGiTest extends JavaOSGiTest {
AsyncResultWrapper<Provider<Thing>> thingProviderWrapper = new AsyncResultWrapper<>();
AsyncResultWrapper<Thing> thingWrapper = new AsyncResultWrapper<>();
registerThingsChangeListener(new ProviderChangeListener<Thing>() {
registerThingsChangeListener(new ProviderChangeListener<>() {
@Override
public void added(Provider<Thing> provider, Thing thing) {
thingProviderWrapper.set(provider);
@ -150,7 +150,7 @@ public class ManagedThingProviderOSGiTest extends JavaOSGiTest {
Thing thing1 = ThingBuilder.create(THING_TYPE_UID, THING1_ID).build();
managedThingProvider.add(thing1);
registerThingsChangeListener(new ProviderChangeListener<Thing>() {
registerThingsChangeListener(new ProviderChangeListener<>() {
@Override
public void added(Provider<Thing> provider, Thing thing) {
}