From d5529f0c1ba9a88c225b51a23754940702b4f651 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sat, 15 Aug 2020 10:54:41 +0200 Subject: [PATCH] Fix various deprecations (#1595) Signed-off-by: Wouter Born --- .../java/org/openhab/core/audio/AudioFormat.java | 16 ++++++++-------- .../core/audio/internal/AudioFormatTest.java | 6 +++--- .../automation/internal/commands/Printer.java | 4 ++-- .../core/automation/internal/commands/Utils.java | 2 +- .../ConfigDispatcherFileWatcherTest.java | 6 +++--- .../model/lsp/internal/RuntimeServerModule.java | 4 ++-- .../json/internal/JsonStorageService.java | 4 ++-- .../AbstractFileTransformationService.java | 4 ++-- .../ui/icon/internal/CustomIconProvider.java | 5 ++--- .../org/openhab/core/library/types/HSBType.java | 11 +++++------ .../openhab/core/library/types/HSBTypeTest.java | 5 +++-- .../core/library/types/PercentTypeTest.java | 2 +- .../core/library/types/QuantityTypeTest.java | 6 ++++-- .../internal/ConfigDispatcherOSGiTest.java | 12 ++++++------ .../internal/JsonStorageServiceOSGiTest.java | 6 +++--- 15 files changed, 47 insertions(+), 46 deletions(-) diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioFormat.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioFormat.java index 3d7390bcb4..27b2863dac 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioFormat.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioFormat.java @@ -347,8 +347,8 @@ public class AudioFormat { // If required set BigEndian, BitDepth, BitRate, and Frequency to default values if (null == format.isBigEndian()) { - format = new AudioFormat(format.getContainer(), format.getCodec(), new Boolean(true), - format.getBitDepth(), format.getBitRate(), format.getFrequency()); + format = new AudioFormat(format.getContainer(), format.getCodec(), Boolean.TRUE, format.getBitDepth(), + format.getBitRate(), format.getFrequency()); } if (null == format.getBitDepth() || null == format.getBitRate() || null == format.getFrequency()) { // Define default values @@ -363,19 +363,19 @@ public class AudioFormat { // These values must be interdependent (bitRate = bitDepth * frequency) if (null == bitRate) { if (null == bitDepth) { - bitDepth = new Integer(defaultBitDepth); + bitDepth = Integer.valueOf(defaultBitDepth); } if (null == frequency) { - frequency = new Long(defaultFrequency); + frequency = Long.valueOf(defaultFrequency); } - bitRate = new Integer(bitDepth.intValue() * frequency.intValue()); + bitRate = Integer.valueOf(bitDepth.intValue() * frequency.intValue()); } else if (null == bitDepth) { if (null == frequency) { - frequency = new Long(defaultFrequency); + frequency = Long.valueOf(defaultFrequency); } - bitDepth = new Integer(bitRate.intValue() / frequency.intValue()); + bitDepth = Integer.valueOf(bitRate.intValue() / frequency.intValue()); } else if (null == frequency) { - frequency = new Long(bitRate.longValue() / bitDepth.longValue()); + frequency = Long.valueOf(bitRate.longValue() / bitDepth.longValue()); } format = new AudioFormat(format.getContainer(), format.getCodec(), format.isBigEndian(), bitDepth, diff --git a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java index b7a7996f1e..dee1136bf0 100644 --- a/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java +++ b/bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioFormatTest.java @@ -31,9 +31,9 @@ public class AudioFormatTest { private final String testContainer = AudioFormat.CONTAINER_WAVE; private final String testCodec = AudioFormat.CODEC_PCM_SIGNED; private final boolean testBigEndian = true; - private final Integer testBitDepth = new Integer(16); - private final Integer testBitRate = new Integer(1000); - private final Long testFrequency = new Long(1024); + private final Integer testBitDepth = Integer.valueOf(16); + private final Integer testBitRate = Integer.valueOf(1000); + private final Long testFrequency = Long.valueOf(1024); @Test public void thereIsNoBestMatchForAnAudioFormatIfOneOfTheFieldsIsNull() { diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java index d873820b25..9ac3e30692 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java @@ -105,7 +105,7 @@ public class Printer { List rulesRows = new ArrayList<>(); for (int i = 1; i <= ruleUIDs.size(); i++) { - String id = new Integer(i).toString(); + String id = String.valueOf(i); String uid = ruleUIDs.get(id); columnValues.set(0, id); columnValues.set(1, uid); @@ -563,7 +563,7 @@ public class Printer { */ private static void collectListRecords(Map list, List rows, int[] columnWidths) { for (int i = 1; i <= list.size(); i++) { - String id = new Integer(i).toString(); + String id = String.valueOf(i); String uid = list.get(id); List columnValues = new ArrayList<>(); columnValues.add(id); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java index 9409e774fa..4af342c03f 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Utils.java @@ -42,7 +42,7 @@ public class Utils { static Map putInHastable(String[] strings) { Hashtable sorted = new Hashtable<>(); for (int i = 0; i < strings.length; i++) { - sorted.put(new Integer(i + 1).toString(), strings[i]); + sorted.put(String.valueOf(i + 1), strings[i]); } return sorted; } diff --git a/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java b/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java index 75c7904418..d8b5a63e9f 100644 --- a/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java +++ b/bundles/org.openhab.core.config.dispatch/src/test/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherFileWatcherTest.java @@ -65,7 +65,7 @@ public class ConfigDispatcherFileWatcherTest { configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_CREATE, new File(path).toPath()); - verifyZeroInteractions(configDispatcher); + verifyNoInteractions(configDispatcher); } @Test @@ -74,7 +74,7 @@ public class ConfigDispatcherFileWatcherTest { configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_MODIFY, new File(path).toPath()); - verifyZeroInteractions(configDispatcher); + verifyNoInteractions(configDispatcher); } @Test @@ -92,7 +92,7 @@ public class ConfigDispatcherFileWatcherTest { configDispatcherFileWatcher.processWatchEvent(null, StandardWatchEventKinds.ENTRY_DELETE, new File(path).toPath()); - verifyZeroInteractions(configDispatcher); + verifyNoInteractions(configDispatcher); } public class TestConfigDispatcherFileWatcher extends ConfigDispatcherFileWatcher { diff --git a/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/RuntimeServerModule.java b/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/RuntimeServerModule.java index 0d6f878dc4..cab3fa1215 100644 --- a/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/RuntimeServerModule.java +++ b/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/RuntimeServerModule.java @@ -26,7 +26,7 @@ import org.eclipse.xtext.ide.server.UriExtensions; import org.eclipse.xtext.resource.IContainer; import org.eclipse.xtext.resource.IResourceServiceProvider; import org.eclipse.xtext.resource.containers.ProjectDescriptionBasedContainerManager; -import org.openhab.core.config.core.ConfigConstants; +import org.openhab.core.OpenHAB; import org.openhab.core.model.script.ScriptServiceUtil; import org.openhab.core.model.script.engine.ScriptEngine; @@ -51,7 +51,7 @@ public class RuntimeServerModule extends AbstractModule { protected void configure() { binder().bind(ExecutorService.class).toProvider(ExecutorServiceProvider.class); - bind(UriExtensions.class).toInstance(new MappingUriExtensions(ConfigConstants.getConfigFolder())); + bind(UriExtensions.class).toInstance(new MappingUriExtensions(OpenHAB.getConfigFolder())); bind(LanguageServer.class).to(LanguageServerImpl.class); bind(IResourceServiceProvider.Registry.class).toProvider(new RegistryProvider(scriptServiceUtil, scriptEngine)); bind(IWorkspaceConfigFactory.class).to(ProjectWorkspaceConfigFactory.class); diff --git a/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/JsonStorageService.java b/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/JsonStorageService.java index 46320f807a..1d5eb8262c 100644 --- a/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/JsonStorageService.java +++ b/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/JsonStorageService.java @@ -20,7 +20,7 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.config.core.ConfigConstants; +import org.openhab.core.OpenHAB; import org.openhab.core.config.core.ConfigurableService; import org.openhab.core.storage.Storage; import org.openhab.core.storage.StorageService; @@ -64,7 +64,7 @@ public class JsonStorageService implements StorageService { @Activate protected void activate(@Nullable Map properties) { - dbFolderName = ConfigConstants.getUserDataFolder() + File.separator + dbFolderName; + dbFolderName = OpenHAB.getUserDataFolder() + File.separator + dbFolderName; File folder = new File(dbFolderName); if (!folder.exists()) { folder.mkdirs(); diff --git a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java index a8520e150c..452a7f576d 100644 --- a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java +++ b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java @@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.config.core.ConfigConstants; +import org.openhab.core.OpenHAB; import org.openhab.core.i18n.LocaleProvider; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -293,7 +293,7 @@ public abstract class AbstractFileTransformationService implements Transforma * Returns the path to the root of the transformation folder */ protected String getSourcePath() { - return ConfigConstants.getConfigFolder() + File.separator + TransformationService.TRANSFORM_FOLDER_NAME + return OpenHAB.getConfigFolder() + File.separator + TransformationService.TRANSFORM_FOLDER_NAME + File.separator; } } diff --git a/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/CustomIconProvider.java b/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/CustomIconProvider.java index 60cf2615e8..f20904012c 100644 --- a/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/CustomIconProvider.java +++ b/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/CustomIconProvider.java @@ -22,7 +22,7 @@ import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.config.core.ConfigConstants; +import org.openhab.core.OpenHAB; import org.openhab.core.i18n.TranslationProvider; import org.openhab.core.ui.icon.AbstractResourceIconProvider; import org.openhab.core.ui.icon.IconProvider; @@ -47,8 +47,7 @@ public class CustomIconProvider extends AbstractResourceIconProvider { } private @Nullable File getIconFile(String filename, String iconSetId) { - File folder = new File( - ConfigConstants.getConfigFolder() + File.separator + "icons" + File.separator + iconSetId); + File folder = new File(OpenHAB.getConfigFolder() + File.separator + "icons" + File.separator + iconSetId); File file = new File(folder, filename); return file.exists() ? file : null; } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java index 74ddcf262e..d8bd1475dd 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java @@ -275,12 +275,11 @@ public class HSBType extends PercentType implements ComplexType, State, Command PercentType green = null; PercentType blue = null; - BigDecimal h = hue.divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_HALF_UP); + BigDecimal h = hue.divide(BigDecimal.valueOf(100), 10, RoundingMode.HALF_UP); BigDecimal s = saturation.divide(BigDecimal.valueOf(100)); - int hInt = h.multiply(BigDecimal.valueOf(5)).divide(BigDecimal.valueOf(3), 10, BigDecimal.ROUND_HALF_UP) - .intValue(); - BigDecimal f = h.multiply(BigDecimal.valueOf(5)).divide(BigDecimal.valueOf(3), 10, BigDecimal.ROUND_HALF_UP) + int hInt = h.multiply(BigDecimal.valueOf(5)).divide(BigDecimal.valueOf(3), 10, RoundingMode.HALF_UP).intValue(); + BigDecimal f = h.multiply(BigDecimal.valueOf(5)).divide(BigDecimal.valueOf(3), 10, RoundingMode.HALF_UP) .remainder(BigDecimal.ONE); PercentType a = new PercentType(value.multiply(BigDecimal.ONE.subtract(s))); PercentType b = new PercentType(value.multiply(BigDecimal.ONE.subtract(s.multiply(f)))); @@ -377,8 +376,8 @@ public class HSBType extends PercentType implements ComplexType, State, Command } private int convertPercentToByte(PercentType percent) { - return percent.value.multiply(BigDecimal.valueOf(255)) - .divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).intValue(); + return percent.value.multiply(BigDecimal.valueOf(255)).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP) + .intValue(); } @Override diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java index c200557021..5be8ddc18d 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/HSBTypeTest.java @@ -17,6 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; +import java.math.RoundingMode; import org.junit.jupiter.api.Test; @@ -52,8 +53,8 @@ public class HSBTypeTest { } private int convertPercentToByte(PercentType percent) { - return percent.value.multiply(BigDecimal.valueOf(255)) - .divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).intValue(); + return percent.value.multiply(BigDecimal.valueOf(255)).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP) + .intValue(); } private void compareHsbToRgbValues(String hsbValues, int red, int green, int blue) { diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java index 2ab76feee9..4267d54b4d 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/PercentTypeTest.java @@ -46,7 +46,7 @@ public class PercentTypeTest { @Test public void testEquals() { - PercentType pt1 = new PercentType(new Integer(100)); + PercentType pt1 = new PercentType(Integer.valueOf(100)); PercentType pt2 = new PercentType("100.0"); PercentType pt3 = new PercentType(0); PercentType pt4 = new PercentType(0); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java index 695a8131d0..7eff45085b 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java @@ -17,6 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.openhab.core.library.unit.MetricPrefix.CENTI; +import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.text.DecimalFormatSymbols; @@ -83,8 +84,9 @@ public class QuantityTypeTest { } @Test - public void testReflectiveInstantiation() throws InstantiationException, IllegalAccessException { - QuantityType.class.newInstance(); + public void testReflectiveInstantiation() throws InstantiationException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + QuantityType.class.getDeclaredConstructor().newInstance(); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java index ab1f91ded6..dc55cf4fd9 100644 --- a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java +++ b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java @@ -40,7 +40,7 @@ import org.junit.jupiter.api.MethodOrderer.Alphanumeric; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.io.TempDir; -import org.openhab.core.config.core.ConfigConstants; +import org.openhab.core.OpenHAB; import org.openhab.core.test.java.JavaOSGiTest; import org.osgi.framework.InvalidSyntaxException; import org.osgi.service.cm.Configuration; @@ -934,16 +934,16 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest { private Configuration getConfigurationWithContext(String pidWithContext) { String pid = null; String configContext = null; - if (pidWithContext.contains(ConfigConstants.SERVICE_CONTEXT_MARKER)) { - pid = pidWithContext.split(ConfigConstants.SERVICE_CONTEXT_MARKER)[0]; - configContext = pidWithContext.split(ConfigConstants.SERVICE_CONTEXT_MARKER)[1]; + if (pidWithContext.contains(OpenHAB.SERVICE_CONTEXT_MARKER)) { + pid = pidWithContext.split(OpenHAB.SERVICE_CONTEXT_MARKER)[0]; + configContext = pidWithContext.split(OpenHAB.SERVICE_CONTEXT_MARKER)[1]; } else { throw new IllegalArgumentException("PID does not have a context"); } Configuration[] configs = null; try { - configs = configAdmin.listConfigurations("(&(service.factoryPid=" + pid + ")(" - + ConfigConstants.SERVICE_CONTEXT + "=" + configContext + "))"); + configs = configAdmin.listConfigurations( + "(&(service.factoryPid=" + pid + ")(" + OpenHAB.SERVICE_CONTEXT + "=" + configContext + "))"); } catch (IOException e) { throw new IllegalArgumentException( "IOException occured while retrieving configuration for pid " + pidWithContext, e); diff --git a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java index f78e850d27..c82dcd1bcf 100644 --- a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java +++ b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java @@ -32,7 +32,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.openhab.core.config.core.ConfigConstants; +import org.openhab.core.OpenHAB; import org.openhab.core.config.core.Configuration; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.storage.Storage; @@ -64,13 +64,13 @@ public class JsonStorageServiceOSGiTest extends JavaOSGiTest { @AfterAll public static void afterClass() throws IOException { // clean up database files ... - final Path userData = Paths.get(ConfigConstants.getUserDataFolder()); + final Path userData = Paths.get(OpenHAB.getUserDataFolder()); if (Files.exists(userData)) { try (Stream walk = Files.walk(userData)) { walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); } } - final Path config = Paths.get(ConfigConstants.getConfigFolder()); + final Path config = Paths.get(OpenHAB.getConfigFolder()); if (Files.exists(config)) { try (Stream walk = Files.walk(config)) { walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);