From 7975afb7a6107271926edc9a9782af3fa7f36a6b Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sat, 21 Oct 2023 22:39:42 +0200 Subject: [PATCH] [oceanic] Remove org.apache.common (#15332) Signed-off-by: Leo Siepel --- .../handler/NetworkOceanicThingHandler.java | 22 +++++++++---------- .../internal/handler/OceanicThingHandler.java | 9 ++++---- .../handler/SerialOceanicThingHandler.java | 6 +++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java index 79e7cbd6a..0721245d7 100644 --- a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java +++ b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java @@ -18,10 +18,10 @@ import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException; import java.util.Arrays; +import java.util.Objects; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.oceanic.internal.NetworkOceanicBindingConfiguration; @@ -29,6 +29,7 @@ import org.openhab.binding.oceanic.internal.Throttler; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; +import org.openhab.core.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,13 +63,12 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler { NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class); try { - socket = new Socket(config.ipAddress, config.portNumber); - if (socket != null) { - socket.setSoTimeout(REQUEST_TIMEOUT); - outputStream = socket.getOutputStream(); - inputStream = socket.getInputStream(); - updateStatus(ThingStatus.ONLINE); - } + Socket socket = new Socket(config.ipAddress, config.portNumber); + this.socket = socket; + socket.setSoTimeout(REQUEST_TIMEOUT); + outputStream = socket.getOutputStream(); + inputStream = socket.getInputStream(); + updateStatus(ThingStatus.ONLINE); } catch (UnknownHostException e) { logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber, e.getMessage()); @@ -86,7 +86,7 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler { @Override public void dispose() { NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class); - + Socket socket = this.socket; if (socket != null) { try { socket.close(); @@ -94,7 +94,7 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler { logger.error("An exception occurred while disconnecting to host {}:{} : '{}'", config.ipAddress, config.portNumber, e.getMessage()); } finally { - socket = null; + this.socket = null; outputStream = null; inputStream = null; } @@ -186,7 +186,7 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler { if (index > 0) { line = new String(Arrays.copyOf(dataBuffer, index)); logger.debug("Received response '{}'", line); - line = StringUtils.chomp(line); + line = Objects.requireNonNull(StringUtils.chomp(line)); line = line.replace(",", "."); line = line.trim(); index = 0; diff --git a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/OceanicThingHandler.java b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/OceanicThingHandler.java index dff62a41c..a1874bf42 100644 --- a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/OceanicThingHandler.java +++ b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/OceanicThingHandler.java @@ -103,18 +103,19 @@ public abstract class OceanicThingHandler extends BaseThingHandler { } else { bufferSize = ((BigDecimal) getConfig().get(BUFFER_SIZE)).intValue(); } - + ScheduledFuture pollingJob = this.pollingJob; if (pollingJob == null || pollingJob.isCancelled()) { - pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, + this.pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, ((BigDecimal) getConfig().get(INTERVAL)).intValue(), TimeUnit.SECONDS); } } @Override public void dispose() { - if (pollingJob != null && !pollingJob.isCancelled()) { + ScheduledFuture pollingJob = this.pollingJob; + if (pollingJob != null) { pollingJob.cancel(true); - pollingJob = null; + this.pollingJob = null; } } diff --git a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java index 16280a828..38bbe0061 100644 --- a/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java +++ b/bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java @@ -17,10 +17,10 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Objects; import java.util.TooManyListenersException; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.openhab.binding.oceanic.internal.SerialOceanicBindingConfiguration; import org.openhab.binding.oceanic.internal.Throttler; import org.openhab.core.io.transport.serial.PortInUseException; @@ -33,6 +33,7 @@ import org.openhab.core.io.transport.serial.UnsupportedCommOperationException; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; +import org.openhab.core.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -272,7 +273,8 @@ public class SerialOceanicThingHandler extends OceanicThingHandler implements Se logger.trace("The resulting line is '{}'", new String(Arrays.copyOf(dataBuffer, index))); } - line = StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index))); + line = Objects.requireNonNull( + StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index)))); line = line.replace(",", "."); line = line.trim(); index = 0;