Skip to content

Commit 7975afb

Browse files
authored
[oceanic] Remove org.apache.common (openhab#15332)
Signed-off-by: Leo Siepel <[email protected]>
1 parent 3ed22b4 commit 7975afb

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/NetworkOceanicThingHandler.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
import java.net.Socket;
1919
import java.net.UnknownHostException;
2020
import java.util.Arrays;
21+
import java.util.Objects;
2122
import java.util.concurrent.ScheduledFuture;
2223
import java.util.concurrent.TimeUnit;
2324

24-
import org.apache.commons.lang3.StringUtils;
2525
import org.eclipse.jdt.annotation.NonNullByDefault;
2626
import org.eclipse.jdt.annotation.Nullable;
2727
import org.openhab.binding.oceanic.internal.NetworkOceanicBindingConfiguration;
2828
import org.openhab.binding.oceanic.internal.Throttler;
2929
import org.openhab.core.thing.Thing;
3030
import org.openhab.core.thing.ThingStatus;
3131
import org.openhab.core.thing.ThingStatusDetail;
32+
import org.openhab.core.util.StringUtils;
3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
3435

@@ -62,13 +63,12 @@ public void initialize() {
6263
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
6364

6465
try {
65-
socket = new Socket(config.ipAddress, config.portNumber);
66-
if (socket != null) {
67-
socket.setSoTimeout(REQUEST_TIMEOUT);
68-
outputStream = socket.getOutputStream();
69-
inputStream = socket.getInputStream();
70-
updateStatus(ThingStatus.ONLINE);
71-
}
66+
Socket socket = new Socket(config.ipAddress, config.portNumber);
67+
this.socket = socket;
68+
socket.setSoTimeout(REQUEST_TIMEOUT);
69+
outputStream = socket.getOutputStream();
70+
inputStream = socket.getInputStream();
71+
updateStatus(ThingStatus.ONLINE);
7272
} catch (UnknownHostException e) {
7373
logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber,
7474
e.getMessage());
@@ -86,15 +86,15 @@ public void initialize() {
8686
@Override
8787
public void dispose() {
8888
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);
89-
89+
Socket socket = this.socket;
9090
if (socket != null) {
9191
try {
9292
socket.close();
9393
} catch (IOException e) {
9494
logger.error("An exception occurred while disconnecting to host {}:{} : '{}'", config.ipAddress,
9595
config.portNumber, e.getMessage());
9696
} finally {
97-
socket = null;
97+
this.socket = null;
9898
outputStream = null;
9999
inputStream = null;
100100
}
@@ -186,7 +186,7 @@ public void dispose() {
186186
if (index > 0) {
187187
line = new String(Arrays.copyOf(dataBuffer, index));
188188
logger.debug("Received response '{}'", line);
189-
line = StringUtils.chomp(line);
189+
line = Objects.requireNonNull(StringUtils.chomp(line));
190190
line = line.replace(",", ".");
191191
line = line.trim();
192192
index = 0;

bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/OceanicThingHandler.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,19 @@ public void initialize() {
103103
} else {
104104
bufferSize = ((BigDecimal) getConfig().get(BUFFER_SIZE)).intValue();
105105
}
106-
106+
ScheduledFuture<?> pollingJob = this.pollingJob;
107107
if (pollingJob == null || pollingJob.isCancelled()) {
108-
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
108+
this.pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
109109
((BigDecimal) getConfig().get(INTERVAL)).intValue(), TimeUnit.SECONDS);
110110
}
111111
}
112112

113113
@Override
114114
public void dispose() {
115-
if (pollingJob != null && !pollingJob.isCancelled()) {
115+
ScheduledFuture<?> pollingJob = this.pollingJob;
116+
if (pollingJob != null) {
116117
pollingJob.cancel(true);
117-
pollingJob = null;
118+
this.pollingJob = null;
118119
}
119120
}
120121

bundles/org.openhab.binding.oceanic/src/main/java/org/openhab/binding/oceanic/internal/handler/SerialOceanicThingHandler.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import java.io.OutputStream;
1818
import java.text.SimpleDateFormat;
1919
import java.util.Arrays;
20+
import java.util.Objects;
2021
import java.util.TooManyListenersException;
2122
import java.util.stream.Collectors;
2223

23-
import org.apache.commons.lang3.StringUtils;
2424
import org.openhab.binding.oceanic.internal.SerialOceanicBindingConfiguration;
2525
import org.openhab.binding.oceanic.internal.Throttler;
2626
import org.openhab.core.io.transport.serial.PortInUseException;
@@ -33,6 +33,7 @@
3333
import org.openhab.core.thing.Thing;
3434
import org.openhab.core.thing.ThingStatus;
3535
import org.openhab.core.thing.ThingStatusDetail;
36+
import org.openhab.core.util.StringUtils;
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
3839

@@ -272,7 +273,8 @@ public void run() {
272273
logger.trace("The resulting line is '{}'",
273274
new String(Arrays.copyOf(dataBuffer, index)));
274275
}
275-
line = StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index)));
276+
line = Objects.requireNonNull(
277+
StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index))));
276278
line = line.replace(",", ".");
277279
line = line.trim();
278280
index = 0;

0 commit comments

Comments
 (0)