Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup (IntelliJ inspections) #1017

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/org/kiwiproject/base/KiwiEnums.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public static <E extends Enum<E>> boolean notEqualsIgnoreCase(Enum<E> enumValue,
}

/**
* Checks whether the given value matches the {@link Enum#name() name} of any of the given enums.
* Checks whether the given value matches the {@link Enum#name() name} of the given enums.
*
* @param <E> the enum type
* @param value the value to use for the comparison, may be null
* @param enumValues the enums to use for the comparison
* @return true if the value equals the name of any of the enums, false otherwise
* @return true if the value equals the name of the enums, false otherwise
*/
@SafeVarargs
public static <E extends Enum<E>> boolean equalsAny(@Nullable CharSequence value, Enum<E>... enumValues) {
Expand All @@ -135,13 +135,13 @@ public static <E extends Enum<E>> boolean equalsAny(@Nullable CharSequence value
}

/**
* Checks whether the given value matches the {@link Enum#name() name} of any of the given
* Checks whether the given value matches the {@link Enum#name() name} of the given
* enums, ignoring case.
*
* @param <E> the enum type
* @param value the value to use for the comparison, may be null
* @param enumValues the enums to use for the comparison
* @return true if the value equals the name of any of the enums in case-insensitive manner, false otherwise
* @return true if the value equals the name of the enums in case-insensitive manner, false otherwise
*/
@SafeVarargs
public static <E extends Enum<E>> boolean equalsAnyIgnoreCase(@Nullable CharSequence value,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/base/KiwiObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static <T> T firstNonNullOrNull(T first, T second, T... rest) {
}

/**
* Return the first supplied non-null object, or {@code null} if all all suppliers return null.
* Return the first supplied non-null object, or {@code null} if all suppliers return null.
*
* @param first the first object supplier
* @param second the second object supplier
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kiwiproject/base/KiwiPrimitives.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static OptionalInt tryParseInt(CharSequence cs) {
* Attempt to parse the given {@link CharSequence} to an {@code int}.
*
* @param cs the value to parse
* @return the parsed {@code int} value if successful; if it cannot be parsed this method always throws an exception
* @return the parsed {@code int} value if successful; otherwise if it cannot be parsed, this method always throws an exception
* @throws IllegalStateException if the value cannot be parsed
*/
public static int tryParseIntOrThrow(CharSequence cs) {
Expand Down Expand Up @@ -121,7 +121,7 @@ public static OptionalLong tryParseLong(CharSequence cs) {
* Attempt to parse the given {@link CharSequence} to an {@code long}.
*
* @param cs the value to parse
* @return the parsed {@code long} value if successful; if it cannot be parsed this method always throws an exception
* @return the parsed {@code long} value if successful; otherwise if it cannot be parsed this method always throws an exception
* @throws IllegalStateException if the value cannot be parsed
*/
public static long tryParseLongOrThrow(CharSequence cs) {
Expand Down Expand Up @@ -164,7 +164,7 @@ public static OptionalDouble tryParseDouble(CharSequence cs) {
* Attempt to parse the given {@link CharSequence} to an {@code double}.
*
* @param cs the value to parse
* @return the parsed {@code double} value if successful; if it cannot be parsed this method always throws an exception
* @return the parsed {@code double} value if successful; otherwise if it cannot be parsed this method always throws an exception
* @throws IllegalStateException if the value cannot be parsed
*/
public static double tryParseDoubleOrThrow(CharSequence cs) {
Expand Down
38 changes: 14 additions & 24 deletions src/main/java/org/kiwiproject/base/KiwiStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,13 @@ public static Iterable<String> nullSafeSplitWithTrimAndOmitEmpty(@Nullable CharS
* @return an Iterable over the split strings
*/
public static Iterable<String> splitWithTrimAndOmitEmpty(CharSequence sequence, char separator) {
switch (separator) {
case COMMA:
return TRIMMING_AND_EMPTY_OMITTING_COMMA_SPLITTER.split(sequence);
case SPACE:
return TRIMMING_AND_EMPTY_OMITTING_SPACE_SPLITTER.split(sequence);
case TAB:
return TRIMMING_AND_EMPTY_OMITTING_TAB_SPLITTER.split(sequence);
case NEWLINE:
return TRIMMING_AND_EMPTY_OMITTING_NEWLINE_SPLITTER.split(sequence);
default:
return Splitter.on(separator).omitEmptyStrings().trimResults().split(sequence);
}
return switch (separator) {
case COMMA -> TRIMMING_AND_EMPTY_OMITTING_COMMA_SPLITTER.split(sequence);
case SPACE -> TRIMMING_AND_EMPTY_OMITTING_SPACE_SPLITTER.split(sequence);
case TAB -> TRIMMING_AND_EMPTY_OMITTING_TAB_SPLITTER.split(sequence);
case NEWLINE -> TRIMMING_AND_EMPTY_OMITTING_NEWLINE_SPLITTER.split(sequence);
default -> Splitter.on(separator).omitEmptyStrings().trimResults().split(sequence);
};
}

/**
Expand Down Expand Up @@ -204,18 +199,13 @@ public static List<String> nullSafeSplitToList(@Nullable CharSequence sequence)
* @see #splitWithTrimAndOmitEmpty(CharSequence, char)
*/
public static List<String> splitToList(CharSequence sequence, char separator) {
switch (separator) {
case COMMA:
return TRIMMING_AND_EMPTY_OMITTING_COMMA_SPLITTER.splitToList(sequence);
case SPACE:
return TRIMMING_AND_EMPTY_OMITTING_SPACE_SPLITTER.splitToList(sequence);
case TAB:
return TRIMMING_AND_EMPTY_OMITTING_TAB_SPLITTER.splitToList(sequence);
case NEWLINE:
return TRIMMING_AND_EMPTY_OMITTING_NEWLINE_SPLITTER.splitToList(sequence);
default:
return Splitter.on(separator).omitEmptyStrings().trimResults().splitToList(sequence);
}
return switch (separator) {
case COMMA -> TRIMMING_AND_EMPTY_OMITTING_COMMA_SPLITTER.splitToList(sequence);
case SPACE -> TRIMMING_AND_EMPTY_OMITTING_SPACE_SPLITTER.splitToList(sequence);
case TAB -> TRIMMING_AND_EMPTY_OMITTING_TAB_SPLITTER.splitToList(sequence);
case NEWLINE -> TRIMMING_AND_EMPTY_OMITTING_NEWLINE_SPLITTER.splitToList(sequence);
default -> Splitter.on(separator).omitEmptyStrings().trimResults().splitToList(sequence);
};
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kiwiproject/base/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Versions {
*
* @param left the first version to compare
* @param right the second version to compare
* @return the higher of the given versions
* @return the highest of the given versions
*/
public static String higherVersion(String left, String right) {
return versionCompare(left, right) >= 0 ? left : right;
Expand Down Expand Up @@ -100,9 +100,9 @@ public static boolean isSameVersion(String left, String right) {
* such as 1.0.0 vs 1.0.0.42 (the latter is higher). It also handles most normal cases when the last segments are
* different and are non-numeric, e.g. 1.0.0 should be considered a higher version than 1.0.0-SNAPSHOT or
* 1.0.0-alpha. There are various edge cases that might report results that might not be what you expect; for
* example, should 2.0.0-beta.1 be a higher or lower version than 2.0.0-beta? Currently 2.0.0-beta is reported as
* example, should 2.0.0-beta.1 be a higher or lower version than 2.0.0-beta? Currently, 2.0.0-beta is reported as
* the higher version due to the simple implementation. However, note that 2.0.0-beta1 would be reported as higher
* than 2.0.0-beta (because the String "beta" is "greater than" the String "beta" using (Java) string comparison.
* than 2.0.0-beta (because the String "beta" is "greater than" the String "beta" using (Java) string comparison).
* @see Integer#signum(int)
*/
public static int versionCompare(String left, String right) {
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/org/kiwiproject/base/process/Processes.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,21 +652,18 @@ private static int doTimeoutAction(KillTimeoutAction action, Process killProcess
throws InterruptedException {

switch (action) {
case FORCE_KILL:
case FORCE_KILL -> {
boolean killedBeforeWaitTimeout = killForcibly(killProcess, 1L, TimeUnit.SECONDS);
validateKilledBeforeTimeout(processId, killedBeforeWaitTimeout);
return killProcess.exitValue();

case THROW_EXCEPTION:
throw new IllegalStateException(
format("Process %s did not end before timeout (and exception was requested)", processId));

case NO_OP:
}
case THROW_EXCEPTION -> throw new IllegalStateException(
format("Process %s did not end before timeout (and exception was requested)", processId));
case NO_OP -> {
LOG.warn("Process {} did not end before timeout and no-op action requested, so doing nothing", processId);
return -1;

default:
throw new IllegalStateException("Unaccounted for action: " + action);
}
default -> throw new IllegalStateException("Unaccounted for action: " + action);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/kiwiproject/beans/BeanConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

/**
* Simple way to convert one bean to another. This utility uses spring-beans to attempt the conversion at first.
* If attempting to maps, it will attempt to do simple copies of the key-value pairs.
* If attempting to convert maps, it will attempt to do simple copies of the key-value pairs.
* <p>
* Exclusion lists can be provided to ignore specific fields.
* <p>
* Also custom mappers can be provided per field for more control over how the fields are converted.
* Also, custom mappers can be provided per field for more control over how the fields are converted.
* <p>
* NOTE: This class requires spring-beans as a dependency.
*/
Expand Down Expand Up @@ -55,7 +55,7 @@ public class BeanConverter<T> {
private boolean failOnError;

/**
* This conversion method taks a single parameter and modifies the object in place.
* This conversion method takes a single parameter and modifies the object in place.
*
* @param input the object to perform the conversion on
* @return the same object that was passed in
Expand Down Expand Up @@ -137,7 +137,7 @@ public boolean hasPropertyMapper(String propertyName) {
* {@link ClassCastException} will be thrown at runtime.
*
* @param propertyName the property name
* @param <R> the result type of the the mapper for the given property
* @param <R> the result type of the mapper for the given property
* @return the Function that will be triggered
*/
@SuppressWarnings("unchecked")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kiwiproject/collect/KiwiArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static <T> T nth(T[] items, int number) {
}

/**
* Returns a array of the collection elements with duplicates stripped out.
* Returns an array of the collection elements with duplicates stripped out.
*
* @param collection the collection of values
* @param arrayType the type of the items in the array. Needed to ensure the new array is not {@code Object[]}
Expand All @@ -248,7 +248,7 @@ public static <T> T[] distinct(T[] collection, Class<T> arrayType) {
}

/**
* Returns a array of the collection elements with duplicates stripped out or `null` if a null value is passed in.
* Returns an array of the collection elements with duplicates stripped out or `null` if a null value is passed in.
*
* @param collection the collection of values
* @param arrayType the type of the items in the array. Needed to ensure the new array is not {@code Object[]}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/collect/KiwiCollectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static <E extends Enum<E>> Collector<E, EnumSet<E>, EnumSet<E>> toEnumSet
/**
* Returns a {@link Collector} that collects into an {@link java.util.EnumMap}.
* <p>
* If the mapped keys contain duplicates (according to {@link Object#equals(Object)}, an
* If the mapped keys contain duplicates (according to {@link Object#equals(Object)}), an
* {@code IllegalStateException} is thrown when the collection operation is performed.
*
* @param enumClass the key type for the returned map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/**
* Utility methods for working with Guava {@link EvictingQueue} instances.
*/
@SuppressWarnings("UnstableApiUsage")
@UtilityClass
public class KiwiEvictingQueues {

Expand Down
15 changes: 4 additions & 11 deletions src/main/java/org/kiwiproject/collect/KiwiStreams.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kiwiproject.collect;

import static org.kiwiproject.base.KiwiPreconditions.checkArgumentNotNull;
import static org.kiwiproject.base.KiwiStrings.f;

import lombok.experimental.UtilityClass;

Expand Down Expand Up @@ -65,16 +64,10 @@ public static <T> Stream<T> stream(Collection<T> collection, StreamMode mode) {
checkArgumentNotNull(collection);
checkArgumentNotNull(mode);

switch (mode) {
case SEQUENTIAL:
return collection.stream();

case PARALLEL:
return collection.parallelStream();

default:
throw new IllegalStateException(f("unexpected StreamMode: {}", mode));
}
return switch (mode) {
case SEQUENTIAL -> collection.stream();
case PARALLEL -> collection.parallelStream();
};
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/kiwiproject/concurrent/StripedLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* @see Striped
* @see ReadWriteLock
*/
@SuppressWarnings("UnstableApiUsage") // Guava's Striped is marked @Beta (but has been in Guava since 13, a long time)
@Slf4j
public class StripedLock {

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/kiwiproject/concurrent/TryLocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Duration getLockWaitDuration() {
}

/**
* Run {@code withLockAction} if the lock is obtained within the lock timeout period. Otherwise
* Run {@code withLockAction} if the lock is obtained within the lock timeout period. Otherwise,
* run {@code orElseAction}.
*
* @param withLockAction action to run if lock is obtained
Expand Down Expand Up @@ -121,7 +121,7 @@ private static Runnable selectAction(boolean gotLock, Runnable withLockAction, R

/**
* Execute the given {@code withLockSupplier} if the lock is obtained within the lock timeout period and return
* its value. Otherwise return null.
* its value. Otherwise, return null.
*
* @param withLockSupplier supplier to execute if lock is obtained
* @param <T> type of object returned
Expand All @@ -133,7 +133,7 @@ public <T> T withLockSupplyOrNull(Supplier<T> withLockSupplier) {

/**
* Execute the given {@code withLockSupplier} if the lock is obtained within the lock timeout period and return
* its value. Otherwise return the {@code fallbackValue}.
* its value. Otherwise, return the {@code fallbackValue}.
*
* @param withLockSupplier supplier to execute if lock is obtained
* @param fallbackValue the value to use if the lock is not obtained
Expand All @@ -148,7 +148,7 @@ public <T> T withLockSupplyOrFallback(Supplier<T> withLockSupplier, T fallbackVa

/**
* Execute the given {@code withLockSupplier} if the lock is obtained within the lock timeout period and return
* its value. Otherwise return the valued supplied by {@code fallbackSupplier}.
* its value. Otherwise, return the valued supplied by {@code fallbackSupplier}.
*
* @param withLockSupplier supplier to execute if lock is obtained
* @param fallbackSupplier the supplier to execute if the lock is not obtained
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public List<String> getDomains() {
* round-robin among the domains returned by {@link #getDomains()}.
*
* @return the URI as a {@link String}
* @implNote This currently builds URIs using simple string substitution, any any leading or trailing slashes
* @implNote This currently builds URIs using simple string substitution, any leading or trailing slashes
* on the domain are stripped.
*/
public String getURI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class SSLContextConfiguration implements KeyAndTrustStoreConfigProvider {
* A builder class for {@link SSLContextConfiguration}.
*
* @implNote This was implemented well before we started using Lombok, so is manual builder code, though
* we have added both the Lombok-style xxx() as well as keeping the original setXxx() methods.
* Subject to change in future.
* we have added both the Lombok-style xxx() and keeping the original setXxx() methods.
* Subject to change in the future.
*/
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class TlsContextConfiguration implements KeyAndTrustStoreConfigProvider {

/**
* The name of the JCE (Java Cryptography Extension) provider to use on client side for cryptographic
* support (for example, SunJCE, Conscrypt, BC, etc).
* support (for example, SunJCE, Conscrypt, BC, etc.).
* <p>
* For more details, see the Java Cryptography Architecture (JCA) Reference Guide" section of the Java
* For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java
* <a href="https://docs.oracle.com/en/java/javase/20/security/java-security-overview1.html">Security Developer’s Guide</a>.
*/
private String provider;
Expand Down Expand Up @@ -78,7 +78,7 @@ public class TlsContextConfiguration implements KeyAndTrustStoreConfigProvider {
* The name of the provider for the key store, i.e. the value of {@code provider} to use when getting the
* {@link java.security.KeyStore} instance for the key store.
* <p>
* For more details, see the Java Cryptography Architecture (JCA) Reference Guide" section of the Java
* For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java
* <a href="https://docs.oracle.com/en/java/javase/20/security/java-security-overview1.html">Security Developer’s Guide</a>.
*
* @see java.security.KeyStore#getInstance(String, String)
Expand Down Expand Up @@ -110,7 +110,7 @@ public class TlsContextConfiguration implements KeyAndTrustStoreConfigProvider {
* The name of the provider for the trust store, i.e. the value of {@code provider} to use when getting the
* {@link java.security.KeyStore} instance for the trust store.
* <p>
* For more details, see the Java Cryptography Architecture (JCA) Reference Guide" section of the Java
* For more details, see the "Java Cryptography Architecture (JCA) Reference Guide" section of the Java
* <a href="https://docs.oracle.com/en/java/javase/20/security/java-security-overview1.html">Security Developer’s Guide</a>.
*
* @see java.security.KeyStore#getInstance(String, String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.Setter;

/**
* Specifies URL rewriting configuration used by {@link EndpointConfiguration}. Currently supports only a URL
* Specifies URL rewriting configuration used by {@link EndpointConfiguration}. Currently, supports only a URL
* path prefix.
* <p>
* As this is a configuration class generally intended to be populated from external configuration, it is mutable and
Expand Down
Loading