Skip to content

Commit

Permalink
Fix Java and Jetty deprecations (openhab#10349)
Browse files Browse the repository at this point in the history
Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn authored and thinkingstone committed Nov 7, 2021
1 parent 8bd86c8 commit 5fce855
Show file tree
Hide file tree
Showing 43 changed files with 98 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
properties.put("host", url.getHost());
properties.put("user", "admin");
properties.put("password", "admin");
properties.put("port", new Integer(port));
properties.put("port", Integer.valueOf(port));

DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package org.openhab.binding.autelis.internal.handler;

import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -30,8 +32,6 @@
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.openhab.binding.autelis.internal.AutelisBindingConstants;
import org.openhab.binding.autelis.internal.config.AutelisConfiguration;
import org.openhab.core.library.types.DecimalType;
Expand Down Expand Up @@ -313,7 +313,8 @@ private void configure() {
}

baseURL = "http://" + host + ":" + port;
basicAuthentication = "Basic " + B64Code.encode(username + ":" + password, StringUtil.__ISO_8859_1);
basicAuthentication = "Basic "
+ Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
logger.debug("Autelius binding configured with base url {} and refresh period of {}", baseURL, refresh);

initPolling(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.openhab.binding.bticinosmarther.internal.api.dto.Notification;
import org.openhab.binding.bticinosmarther.internal.api.dto.Sender;
import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherGatewayException;
Expand Down Expand Up @@ -61,7 +61,7 @@ public class SmartherAccountService {

private final Logger logger = LoggerFactory.getLogger(SmartherAccountService.class);

private final Set<SmartherAccountHandler> handlers = new ConcurrentHashSet<>();
private final Set<SmartherAccountHandler> handlers = ConcurrentHashMap.newKeySet();

private @Nullable HttpService httpService;
private @Nullable BundleContext bundleContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public boolean sendFunction(String address, int function, int dims) throws Inval
*/
public static boolean validateAddress(String address) {
return (!(address.length() < 2 || address.length() > 3
|| !HOUSE_CODES.containsKey(new Character(address.charAt(0)))
|| !HOUSE_CODES.containsKey(Character.valueOf(address.charAt(0)))
|| !DEVICE_CODES.containsKey(Integer.parseInt(address.substring(1)))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void handleCommand(final ChannelUID channelUID, final Command command) {
if (command instanceof RefreshType) {
final String currentTemp = query(controller, "a");
if (currentTemp != null) {
final Integer temp = new Integer(currentTemp);
final Integer temp = Integer.parseInt(currentTemp);
final QuantityType<?> value = new QuantityType<>(temp, controller.getUnit());
updateState(CURRENT_TEMP, value);
}
Expand All @@ -157,7 +157,7 @@ public void handleCommand(final ChannelUID channelUID, final Command command) {
if (command instanceof RefreshType) {
final String setTemp = query(controller, "t");
if (setTemp != null) {
final Integer temp = new Integer(setTemp);
final Integer temp = Integer.parseInt(setTemp);
final QuantityType<?> value = new QuantityType<>(temp, controller.getUnit());
updateState(SET_TEMP, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void deactivate() {

private synchronized void initialize() {
if (httpClient == null) {
httpClient = new HttpClient(new SslContextFactory(true));
httpClient = new HttpClient(new SslContextFactory.Client(true));
try {
httpClient.start();
logger.debug("Daikin http client started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -410,7 +411,7 @@ private int fromValueToPercent(int value, int max) {
if (value <= 0 || max <= 0) {
return 0;
}
int percentValue = new BigDecimal(value * ((float) 100 / max)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
int percentValue = new BigDecimal(value * ((float) 100 / max)).setScale(0, RoundingMode.HALF_UP).intValue();
return percentValue < 0 ? 0 : percentValue > 100 ? 100 : percentValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public int compareTo(BaseDmxChannel otherDmxChannel) {
if (otherDmxChannel == null) {
return -1;
}
int universeCompare = new Integer(getUniverseId()).compareTo(new Integer(otherDmxChannel.getUniverseId()));
int universeCompare = Integer.valueOf(getUniverseId())
.compareTo(Integer.valueOf(otherDmxChannel.getUniverseId()));
if (universeCompare == 0) {
return new Integer(getChannelId()).compareTo(new Integer(otherDmxChannel.getChannelId()));
return Integer.valueOf(getChannelId()).compareTo(Integer.valueOf(otherDmxChannel.getChannelId()));
} else {
return universeCompare;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.feican.internal;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.library.types.HSBType;
Expand Down Expand Up @@ -82,7 +83,7 @@ public byte[] color(HSBType color) {
*/
private byte convertColorPercentToByte(PercentType percent) {
return percent.toBigDecimal().multiply(BigDecimal.valueOf(255))
.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).byteValue();
.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).byteValue();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.DatagramSocket;
import java.time.Instant;
import java.util.List;
Expand Down Expand Up @@ -567,7 +568,7 @@ private String logInfo(String msgKey, Object... arg) {

public static QuantityType<?> toQuantityType(Number value, int digits, Unit<?> unit) {
BigDecimal bd = new BigDecimal(value.doubleValue());
return new QuantityType<>(bd.setScale(digits, BigDecimal.ROUND_HALF_EVEN), unit);
return new QuantityType<>(bd.setScale(digits, RoundingMode.HALF_EVEN), unit);
}

private void stopRefreshTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.binding.http.internal;

import static org.openhab.binding.http.internal.HttpBindingConstants.*;
import static org.openhab.binding.http.internal.HttpBindingConstants.THING_TYPE_URL;

import java.util.Set;

Expand Down Expand Up @@ -59,8 +59,8 @@ public class HttpHandlerFactory extends BaseThingHandlerFactory
@Activate
public HttpHandlerFactory(@Reference HttpClientFactory httpClientFactory,
@Reference HttpDynamicStateDescriptionProvider httpDynamicStateDescriptionProvider) {
this.secureClient = new HttpClient(new SslContextFactory());
this.insecureClient = new HttpClient(new SslContextFactory(true));
this.secureClient = new HttpClient(new SslContextFactory.Client());
this.insecureClient = new HttpClient(new SslContextFactory.Client(true));
try {
this.secureClient.start();
this.insecureClient.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private static void addChannelsFromProjectFile(Thing thing, NodeList nodes, Stri
ChannelUID channelUID = new ChannelUID(thing.getUID(), group + resourceId);
ChannelTypeUID type = new ChannelTypeUID(BINDING_ID, channelType);
Configuration configuration = new Configuration();
configuration.put(PARAM_RESOURCE_ID, new Integer(resourceId));
configuration.put(PARAM_RESOURCE_ID, Integer.valueOf(resourceId));

Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withConfiguration(configuration)
.withLabel(description).withType(type).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void onMessage(String msg) {
}

WebSocketClient startWebSocketClient() throws Exception {
WebSocketClient client = new WebSocketClient(new SslContextFactory());
WebSocketClient client = new WebSocketClient(new SslContextFactory.Client());
client.setMaxIdleTimeout(this.maxIdleTimeout);
client.start();
return client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public boolean getConnected() {
* Starts the server
*
*/
@Override
public void run() {
this.startRetries = 0;
while (!this.isInterrupted()) {
Expand Down Expand Up @@ -132,7 +133,7 @@ public void addDataPoint(int id, String knxType, String description) {

IDataPoint dp = DataPointFactory.createDataPoint(id, knxType, description);
if (dp != null) {
this.dataPoints.put(new Integer(id), dp);
this.dataPoints.put(Integer.valueOf(id), dp);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.knx.internal.dpt;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
Expand Down Expand Up @@ -1017,6 +1018,6 @@ private int getMainNumber(String dptID) {
*/
private int convertPercentToByte(PercentType percent) {
return percent.toBigDecimal().multiply(BigDecimal.valueOf(255))
.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).intValue();
.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).intValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public String getLogId(@Nullable MACAddress macAddress, @Nullable InetSocketAddr

Configuration configuration = channel.getConfiguration();
Object speed = configuration.get(parameter);
return speed == null ? null : new Double(speed.toString());
return speed == null ? null : Double.valueOf(speed.toString());
}

private LifxProduct getProduct() {
Expand All @@ -414,7 +414,7 @@ private LifxProduct getProduct() {
// Without first conversion to double, on a very first thing creation from discovery inbox,
// the product type is incorrectly parsed, as framework passed it as a floating point number
// (e.g. 50.0 instead of 50)
Double d = Double.parseDouble((String) propertyValue);
Double d = Double.valueOf((String) propertyValue);
long productID = d.longValue();
return LifxProduct.getProductFromProductID(productID);
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void resetCache() {
* @see https://developers.nest.com/documentation/cloud/how-to-handle-redirects
*/
private String resolveRedirectUrl() throws FailedResolvingNestUrlException {
HttpClient httpClient = new HttpClient(new SslContextFactory());
HttpClient httpClient = new HttpClient(new SslContextFactory.Client());
httpClient.setFollowRedirects(false);

Request request = httpClient.newRequest(NestBindingConstants.NEST_URL).method(HttpMethod.GET).timeout(30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.netatmo.internal;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -83,7 +84,7 @@ public static State toDecimalType(double value) {
}

public static State toDecimalType(@Nullable BigDecimal decimal) {
return decimal == null ? UnDefType.NULL : new DecimalType(decimal.setScale(2, BigDecimal.ROUND_HALF_UP));
return decimal == null ? UnDefType.NULL : new DecimalType(decimal.setScale(2, RoundingMode.HALF_UP));
}

public static State toDecimalType(@Nullable String textualDecimal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static void readArguments(String[] args) {
ipAddress = parser.getIpAddress();
logger.info("IP150 IP Address: {}", ipAddress);

port = new Integer(parser.getPort());
port = Integer.parseInt(parser.getPort());
logger.info("IP150 port: {}", port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting2Message.Commands.*;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
Expand Down Expand Up @@ -155,7 +156,7 @@ public String getDeviceId() {
*/
public static int getDimLevelFromPercentType(PercentType pt) {
return pt.toBigDecimal().multiply(BigDecimal.valueOf(15))
.divide(PercentType.HUNDRED.toBigDecimal(), 0, BigDecimal.ROUND_UP).intValue();
.divide(PercentType.HUNDRED.toBigDecimal(), 0, RoundingMode.UP).intValue();
}

/**
Expand All @@ -168,7 +169,7 @@ public static PercentType getPercentTypeFromDimLevel(int value) {
value = Math.min(value, 15);

return new PercentType(BigDecimal.valueOf(value).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(15), 0, BigDecimal.ROUND_UP).intValue());
.divide(BigDecimal.valueOf(15), 0, RoundingMode.UP).intValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -216,7 +217,7 @@ public String getDeviceId() {
*/
public static int getDimLevelFromPercentType(PercentType pt) {
return pt.toBigDecimal().multiply(BigDecimal.valueOf(31))
.divide(PercentType.HUNDRED.toBigDecimal(), 0, BigDecimal.ROUND_UP).intValue();
.divide(PercentType.HUNDRED.toBigDecimal(), 0, RoundingMode.UP).intValue();
}

/**
Expand All @@ -229,7 +230,7 @@ public static PercentType getPercentTypeFromDimLevel(int value) {
value = Math.min(value, 31);

return new PercentType(BigDecimal.valueOf(value).multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(31), 0, BigDecimal.ROUND_UP).intValue());
.divide(BigDecimal.valueOf(31), 0, RoundingMode.UP).intValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
*/
package org.openhab.binding.rfxcom.internal.messages;

import static java.math.BigDecimal.*;
import static java.math.RoundingMode.HALF_DOWN;
import static java.math.RoundingMode.*;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;

Expand Down Expand Up @@ -257,12 +256,12 @@ private State handleHumidity(DeviceState deviceState) {
BigDecimal supplyVoltage = ((DecimalType) referenceVoltageState).toBigDecimal();

// RH = (((A/D voltage / supply voltage) - 0.16) / 0.0062) / (1.0546 - 0.00216 * temperature)
BigDecimal belowTheDivider = adVoltage.divide(supplyVoltage, 4, ROUND_HALF_DOWN)
.subtract(HUMIDITY_VOLTAGE_SUBTRACTION).divide(HUMIDITY_VOLTAGE_DIVIDER, 4, ROUND_HALF_DOWN);
BigDecimal belowTheDivider = adVoltage.divide(supplyVoltage, 4, HALF_DOWN)
.subtract(HUMIDITY_VOLTAGE_SUBTRACTION).divide(HUMIDITY_VOLTAGE_DIVIDER, 4, HALF_DOWN);
BigDecimal underTheDivider = HUMIDITY_TEMPERATURE_CORRECTION
.subtract(HUMIDITY_TEMPERATURE_MULTIPLIER.multiply(temperature));

return new DecimalType(belowTheDivider.divide(underTheDivider, 4, ROUND_HALF_DOWN));
return new DecimalType(belowTheDivider.divide(underTheDivider, 4, HALF_DOWN));
}

private State handlePressure(DeviceState deviceState) {
Expand All @@ -277,14 +276,14 @@ private State handlePressure(DeviceState deviceState) {

// hPa = ((A/D voltage / supply voltage) + 0.095) / 0.0009
return new DecimalType((adVoltage.divide(supplyVoltage, 4, HALF_DOWN).add(PRESSURE_ADDITION))
.divide(PRESSURE_DIVIDER, 4, ROUND_HALF_DOWN));
.divide(PRESSURE_DIVIDER, 4, HALF_DOWN));
}

private BigDecimal getVoltage() {
if (miliVoltageTimesTen == null) {
return null;
}
return miliVoltageTimesTen.divide(ONE_HUNDRED, 100, ROUND_CEILING);
return miliVoltageTimesTen.divide(ONE_HUNDRED, 100, CEILING);
}

@Override
Expand Down
Loading

0 comments on commit 5fce855

Please sign in to comment.