[oceanic] Remove org.apache.common (#15332)

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-10-21 22:39:42 +02:00 committed by GitHub
parent 3ed22b40f4
commit 7975afb7a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 17 deletions

View File

@ -18,10 +18,10 @@ import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.oceanic.internal.NetworkOceanicBindingConfiguration; 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.Thing;
import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -62,13 +63,12 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler {
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class); NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
try { try {
socket = new Socket(config.ipAddress, config.portNumber); Socket socket = new Socket(config.ipAddress, config.portNumber);
if (socket != null) { this.socket = socket;
socket.setSoTimeout(REQUEST_TIMEOUT); socket.setSoTimeout(REQUEST_TIMEOUT);
outputStream = socket.getOutputStream(); outputStream = socket.getOutputStream();
inputStream = socket.getInputStream(); inputStream = socket.getInputStream();
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
}
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber, logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber,
e.getMessage()); e.getMessage());
@ -86,7 +86,7 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler {
@Override @Override
public void dispose() { public void dispose() {
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class); NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
Socket socket = this.socket;
if (socket != null) { if (socket != null) {
try { try {
socket.close(); socket.close();
@ -94,7 +94,7 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler {
logger.error("An exception occurred while disconnecting to host {}:{} : '{}'", config.ipAddress, logger.error("An exception occurred while disconnecting to host {}:{} : '{}'", config.ipAddress,
config.portNumber, e.getMessage()); config.portNumber, e.getMessage());
} finally { } finally {
socket = null; this.socket = null;
outputStream = null; outputStream = null;
inputStream = null; inputStream = null;
} }
@ -186,7 +186,7 @@ public class NetworkOceanicThingHandler extends OceanicThingHandler {
if (index > 0) { if (index > 0) {
line = new String(Arrays.copyOf(dataBuffer, index)); line = new String(Arrays.copyOf(dataBuffer, index));
logger.debug("Received response '{}'", line); logger.debug("Received response '{}'", line);
line = StringUtils.chomp(line); line = Objects.requireNonNull(StringUtils.chomp(line));
line = line.replace(",", "."); line = line.replace(",", ".");
line = line.trim(); line = line.trim();
index = 0; index = 0;

View File

@ -103,18 +103,19 @@ public abstract class OceanicThingHandler extends BaseThingHandler {
} else { } else {
bufferSize = ((BigDecimal) getConfig().get(BUFFER_SIZE)).intValue(); bufferSize = ((BigDecimal) getConfig().get(BUFFER_SIZE)).intValue();
} }
ScheduledFuture<?> pollingJob = this.pollingJob;
if (pollingJob == null || pollingJob.isCancelled()) { if (pollingJob == null || pollingJob.isCancelled()) {
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1, this.pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
((BigDecimal) getConfig().get(INTERVAL)).intValue(), TimeUnit.SECONDS); ((BigDecimal) getConfig().get(INTERVAL)).intValue(), TimeUnit.SECONDS);
} }
} }
@Override @Override
public void dispose() { public void dispose() {
if (pollingJob != null && !pollingJob.isCancelled()) { ScheduledFuture<?> pollingJob = this.pollingJob;
if (pollingJob != null) {
pollingJob.cancel(true); pollingJob.cancel(true);
pollingJob = null; this.pollingJob = null;
} }
} }

View File

@ -17,10 +17,10 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.oceanic.internal.SerialOceanicBindingConfiguration; import org.openhab.binding.oceanic.internal.SerialOceanicBindingConfiguration;
import org.openhab.binding.oceanic.internal.Throttler; import org.openhab.binding.oceanic.internal.Throttler;
import org.openhab.core.io.transport.serial.PortInUseException; 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.Thing;
import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -272,7 +273,8 @@ public class SerialOceanicThingHandler extends OceanicThingHandler implements Se
logger.trace("The resulting line is '{}'", logger.trace("The resulting line is '{}'",
new String(Arrays.copyOf(dataBuffer, index))); 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.replace(",", ".");
line = line.trim(); line = line.trim();
index = 0; index = 0;