code cleanup

This commit is contained in:
anhefti 2024-03-13 13:52:55 +01:00
parent 2611f4f464
commit 7f8106e3c3

View file

@ -86,7 +86,7 @@ public final class Utils {
return Collectors.collectingAndThen(
Collectors.toList(),
list -> {
if (list == null || list.size() == 0) {
if (list == null || list.isEmpty()) {
throw new IllegalStateException(
"Expected one elements in the given list but is empty");
}
@ -179,7 +179,7 @@ public final class Utils {
public static <T> List<T> asImmutableList(final T[] array) {
return (array != null)
? Collections.unmodifiableList(Arrays.asList(array))
? List.of(array)
: Collections.emptyList();
}
@ -195,9 +195,9 @@ public final class Utils {
}
public static <T extends Enum<T>> Collection<Tuple<String>> createSelectionResource(final Class<T> enumClass) {
return Collections.unmodifiableList(Arrays.stream(enumClass.getEnumConstants())
.map(e -> new Tuple<>(e.name(), e.name()))
.collect(Collectors.toList()));
return Arrays.stream(enumClass.getEnumConstants())
.map(e -> new Tuple<>(e.name(), e.name())).
toList();
}
public static <T extends Enum<T>> T enumFromString(
@ -344,7 +344,7 @@ public final class Utils {
return new DateTime(timestamp * 1000, DateTimeZone.UTC);
}
public static final long toUnixTimeInSeconds(final DateTime time) {
public static long toUnixTimeInSeconds(final DateTime time) {
return time.getMillis() / 1000;
}
@ -659,7 +659,7 @@ public final class Utils {
if (values == null) {
return sb;
}
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append(Constants.AMPERSAND);
}
if (values.size() == 1) {
@ -685,7 +685,7 @@ public final class Utils {
.reduce(
new StringBuilder(),
(sb, entry) -> {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append(Constants.AMPERSAND);
}
return sb.append(_name).append(Constants.EQUALITY_SIGN).append(entry);
@ -716,7 +716,7 @@ public final class Utils {
* @param urlString the URL string
* @return true if SEB Server was able to ping the address. */
public static boolean pingHost(final String urlString) {
try (Socket socket = new Socket()) {
try (final Socket socket = new Socket()) {
final URL url = new URL(urlString);
final int port = (url.getPort() >= 0) ? url.getPort() : 80;
socket.connect(new InetSocketAddress(url.getHost(), port), (int) Constants.SECOND_IN_MILLIS * 5);
@ -789,7 +789,7 @@ public final class Utils {
try {
return ipToLong(InetAddress.getByName(ipV4Address));
} catch (final UnknownHostException e) {
log.error("Failed to convert IPv4 address: {}, error: ", ipV4Address, e.getMessage());
log.error("Failed to convert IPv4 address: {}, error: {}", ipV4Address, e.getMessage());
return -1L;
}
}
@ -812,11 +812,7 @@ public final class Utils {
}
// check null and empty string
if (StringUtils.isBlank(s1) && StringUtils.isBlank(s2)) {
return true;
}
return false;
return StringUtils.isBlank(s1) && StringUtils.isBlank(s2);
}
public static boolean isEqualsWithEmptyCheckTruncated(final String s1, final String s2) {