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