[enturno] Remove org.apache.commons (#14406)

* Remove org.apache.commons
* Fix warnings

Also-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-10-27 20:52:54 +02:00 committed by GitHub
parent a357f7f0cb
commit ab5ebbc41b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 120 additions and 34 deletions

View File

@ -26,7 +26,7 @@ import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.enturno.internal.connection.EnturCommunicationException; import org.openhab.binding.enturno.internal.connection.EnturCommunicationException;
import org.openhab.binding.enturno.internal.connection.EnturConfigurationException; import org.openhab.binding.enturno.internal.connection.EnturConfigurationException;
import org.openhab.binding.enturno.internal.connection.EnturNoConnection; import org.openhab.binding.enturno.internal.connection.EnturNoConnection;
import org.openhab.binding.enturno.internal.model.simplified.DisplayData; import org.openhab.binding.enturno.internal.dto.simplified.DisplayData;
import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.StringType; import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.Channel; import org.openhab.core.thing.Channel;

View File

@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
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.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
@ -42,10 +41,11 @@ import org.eclipse.jetty.client.util.StringContentProvider;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;
import org.openhab.binding.enturno.internal.EnturNoConfiguration; import org.openhab.binding.enturno.internal.EnturNoConfiguration;
import org.openhab.binding.enturno.internal.EnturNoHandler; import org.openhab.binding.enturno.internal.EnturNoHandler;
import org.openhab.binding.enturno.internal.model.EnturJsonData; import org.openhab.binding.enturno.internal.dto.EnturJsonData;
import org.openhab.binding.enturno.internal.model.estimated.EstimatedCalls; import org.openhab.binding.enturno.internal.dto.estimated.EstimatedCalls;
import org.openhab.binding.enturno.internal.model.simplified.DisplayData; import org.openhab.binding.enturno.internal.dto.simplified.DisplayData;
import org.openhab.binding.enturno.internal.model.stopplace.StopPlace; import org.openhab.binding.enturno.internal.dto.stopplace.StopPlace;
import org.openhab.binding.enturno.internal.util.DateUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -189,10 +189,8 @@ public class EnturNoConnection {
} }
private List<DisplayData> processData(StopPlace stopPlace, String lineCode) { private List<DisplayData> processData(StopPlace stopPlace, String lineCode) {
Map<String, List<EstimatedCalls>> departures = stopPlace.estimatedCalls.stream() Map<String, List<EstimatedCalls>> departures = stopPlace.estimatedCalls.stream().filter(
.filter(call -> StringUtils.equalsIgnoreCase( call -> call.serviceJourney.journeyPattern.line.publicCode.strip().equalsIgnoreCase(lineCode.strip()))
StringUtils.trimToEmpty(call.serviceJourney.journeyPattern.line.publicCode),
StringUtils.trimToEmpty(lineCode)))
.collect(groupingBy(call -> call.quay.id)); .collect(groupingBy(call -> call.quay.id));
List<DisplayData> processedData = new ArrayList<>(); List<DisplayData> processedData = new ArrayList<>();
@ -214,8 +212,8 @@ public class EnturNoConnection {
List<String> keys = new ArrayList<>(departures.keySet()); List<String> keys = new ArrayList<>(departures.keySet());
DisplayData processedData = new DisplayData(); DisplayData processedData = new DisplayData();
List<EstimatedCalls> quayCalls = departures.get(keys.get(quayIndex)); List<EstimatedCalls> quayCalls = departures.get(keys.get(quayIndex));
List<String> departureTimes = quayCalls.stream().map(eq -> eq.expectedDepartureTime).map(this::getIsoDateTime) List<String> departureTimes = quayCalls.stream().map(eq -> eq.expectedDepartureTime)
.collect(Collectors.toList()); .map(DateUtil::getIsoDateTime).collect(Collectors.toList());
List<String> estimatedFlags = quayCalls.stream().map(es -> es.realtime).collect(Collectors.toList()); List<String> estimatedFlags = quayCalls.stream().map(es -> es.realtime).collect(Collectors.toList());
@ -233,13 +231,4 @@ public class EnturNoConnection {
processedData.transportMode = stopPlace.transportMode; processedData.transportMode = stopPlace.transportMode;
return processedData; return processedData;
} }
private String getIsoDateTime(String dateTimeWithoutColonInZone) {
String dateTime = StringUtils.substringBeforeLast(dateTimeWithoutColonInZone, "+");
String offset = StringUtils.substringAfterLast(dateTimeWithoutColonInZone, "+");
StringBuilder builder = new StringBuilder();
return builder.append(dateTime).append("+").append(StringUtils.substring(offset, 0, 2)).append(":00")
.toString();
}
} }

View File

@ -10,9 +10,9 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model; package org.openhab.binding.enturno.internal.dto;
import org.openhab.binding.enturno.internal.model.stopplace.StopPlace; import org.openhab.binding.enturno.internal.dto.stopplace.StopPlace;
/** /**
* Generated Plain Old Java Objects class for {@link Data} from JSON. * Generated Plain Old Java Objects class for {@link Data} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model; package org.openhab.binding.enturno.internal.dto;
/** /**
* Generated Plain Old Java Objects class for {@link Data} from JSON. * Generated Plain Old Java Objects class for {@link Data} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model; package org.openhab.binding.enturno.internal.dto;
/** /**
* {@link EnturJsonData} is a root level class to holding reference of data generated from JSON. * {@link EnturJsonData} is a root level class to holding reference of data generated from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.estimated; package org.openhab.binding.enturno.internal.dto.estimated;
/** /**
* Generated Plain Old Java Objects class for {@link DestinationDisplay} from JSON. * Generated Plain Old Java Objects class for {@link DestinationDisplay} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.estimated; package org.openhab.binding.enturno.internal.dto.estimated;
/** /**
* Generated Plain Old Java Objects class for {@link EstimatedCalls} from JSON. * Generated Plain Old Java Objects class for {@link EstimatedCalls} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.estimated; package org.openhab.binding.enturno.internal.dto.estimated;
/** /**
* Generated Plain Old Java Objects class for {@link JourneyPattern} from JSON. * Generated Plain Old Java Objects class for {@link JourneyPattern} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.estimated; package org.openhab.binding.enturno.internal.dto.estimated;
/** /**
* Generated Plain Old Java Objects class for {@link Line} from JSON. * Generated Plain Old Java Objects class for {@link Line} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.estimated; package org.openhab.binding.enturno.internal.dto.estimated;
/** /**
* Generated Plain Old Java Objects class for {@link Quay} from JSON. * Generated Plain Old Java Objects class for {@link Quay} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.estimated; package org.openhab.binding.enturno.internal.dto.estimated;
/** /**
* Generated Plain Old Java Objects class for {@link ServiceJourney} from JSON. * Generated Plain Old Java Objects class for {@link ServiceJourney} from JSON.

View File

@ -10,7 +10,7 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.simplified; package org.openhab.binding.enturno.internal.dto.simplified;
import java.util.List; import java.util.List;

View File

@ -10,9 +10,9 @@
* *
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*/ */
package org.openhab.binding.enturno.internal.model.stopplace; package org.openhab.binding.enturno.internal.dto.stopplace;
import org.openhab.binding.enturno.internal.model.estimated.EstimatedCalls; import org.openhab.binding.enturno.internal.dto.estimated.EstimatedCalls;
/** /**
* Generated Plain Old Java Objects class for {@link StopPlace} from JSON. * Generated Plain Old Java Objects class for {@link StopPlace} from JSON.

View File

@ -0,0 +1,51 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enturno.internal.util;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* EnturNo date utility methods.
*
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public class DateUtil {
/**
* Converts a zoned date time string that lacks a colon in the zone to an ISO-8601 formatted string.
*
* @param dateTimeWithoutColonInZone
* @return ISO-8601 formatted string
*/
public static String getIsoDateTime(String dateTimeWithoutColonInZone) {
ZonedDateTime zonedDateTime = null;
try {
zonedDateTime = ZonedDateTime.parse(dateTimeWithoutColonInZone);
} catch (DateTimeParseException e) {
// Skip
}
try {
zonedDateTime = ZonedDateTime.parse(dateTimeWithoutColonInZone.replaceAll("(\\d{2})(\\d{2})$", "$1:$2"));
} catch (DateTimeParseException e) {
// Skip
}
if (zonedDateTime != null) {
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime);
}
return dateTimeWithoutColonInZone;
}
}

View File

@ -0,0 +1,46 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.enturno.internal.util;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
/**
* Tests for {@link DateUtil}.
*
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public class DateUtilTest {
@ParameterizedTest
@MethodSource("provideTestCasesForGetIsoDateTime")
void getIsoDateTime(String value, String expected) {
assertThat(DateUtil.getIsoDateTime(value), is(expected));
}
private static Stream<Arguments> provideTestCasesForGetIsoDateTime() {
return Stream.of( //
Arguments.of("2023-10-25T09:01:00+0200", "2023-10-25T09:01:00+02:00"),
Arguments.of("2023-10-25T09:01:00+02:00", "2023-10-25T09:01:00+02:00"),
Arguments.of("2023-10-25T09:01:00-0300", "2023-10-25T09:01:00-03:00"),
Arguments.of("2023-10-25T09:01:00+02:30", "2023-10-25T09:01:00+02:30"),
Arguments.of("2023-10-25T09:01:00", "2023-10-25T09:01:00"));
}
}