[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.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;

View File

@ -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;
}
}

View File

@ -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;