Skip to content

Commit e48eb42

Browse files
authored
Merge pull request #39 from OpenHFT/gen/javadoc
Gen/javadoc
2 parents 219862c + e47f090 commit e48eb42

45 files changed

Lines changed: 1102 additions & 500 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/net/openhft/chronicle/testframework/CloseableUtil.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6+
/**
7+
* Utility class to handle closing of {@link java.io.Closeable} or {@link AutoCloseable} resources.
8+
* This class provides a method to close a resource without throwing any exceptions, logging them instead.
9+
* Since this class is defined as an enum without instances, it cannot be instantiated and is essentially a utility class.
10+
*/
611
public enum CloseableUtil {
7-
;
12+
; // This enum has no instances, acting as a utility class
813

14+
// Logger to log warning messages if any exceptions occur while closing the resource
915
private static final Logger LOGGER = LoggerFactory.getLogger(CloseableUtil.class);
1016

1117
/**
12-
* Close a {@link java.io.Closeable}, logging any exceptions thrown
18+
* Closes the provided {@link AutoCloseable} resource quietly, without throwing any exceptions.
19+
* If an exception does occur while closing the resource, it is logged as a warning and not propagated.
1320
*
14-
* @param closeable the closeable to close
21+
* @param closeable the closeable resource to close, may be any object implementing {@link AutoCloseable}
1522
*/
1623
public static void closeQuietly(AutoCloseable closeable) {
1724
try {
18-
closeable.close();
25+
if (closeable != null) { // Ensuring the closeable is not null to avoid NullPointerException
26+
closeable.close();
27+
}
1928
} catch (Exception e) {
20-
LOGGER.warn("Error closing", e);
29+
LOGGER.warn("Error closing", e); // Logging any exceptions that occur during closing
2130
}
2231
}
2332
}

src/main/java/net/openhft/chronicle/testframework/Combination.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,33 @@
2121

2222
import java.util.Collection;
2323
import java.util.Set;
24-
import java.util.stream.Collectors;
2524
import java.util.stream.Stream;
2625

2726
import static java.util.Objects.requireNonNull;
2827

2928
/**
30-
* General Combination support. The class eagerly calculates all combinations.
29+
* Utility class that provides functionality to generate all possible combinations
30+
* of a given set of elements. The class eagerly calculates the combinations.
31+
* <p>
32+
* This class cannot be instantiated.
3133
*
3234
* @author Per Minborg
3335
*/
3436
public final class Combination {
3537

3638
// Suppresses default constructor, ensuring non-instantiability.
37-
private Combination() {}
39+
private Combination() {
40+
}
3841

3942
/**
40-
* Creates and returns all possible combinations of the given elements.
43+
* Creates and returns a stream of all possible combinations of the given elements.
4144
* <p>
4245
* The order of the combinations in the stream is unspecified.
4346
*
44-
* @param <T> element type
45-
* @param items to combine
46-
* @return all possible combinations of the given elements
47-
* @throws NullPointerException if the provided {@code items} list is {@code null}.
47+
* @param <T> element type
48+
* @param items the array of items to combine
49+
* @return a stream of sets containing all possible combinations of the given elements
50+
* @throws NullPointerException if the provided {@code items} array is {@code null}.
4851
*/
4952
@SafeVarargs
5053
@SuppressWarnings("varargs") // Creating a Set from an array is safe
@@ -54,36 +57,35 @@ public static <T> Stream<Set<T>> of(@NotNull final T... items) {
5457
}
5558

5659
/**
57-
* Creates and returns all possible combinations of the given elements.
60+
* Creates and returns a stream of all possible combinations of the given elements.
5861
* <p>
5962
* The order of the combinations in the stream is unspecified.
6063
*
61-
* @param <T> element type
62-
* @param items to combine
63-
* @return all possible combinations of the given elements
64-
* @throws NullPointerException if the provided {@code items} list is {@code null}.
64+
* @param <T> element type
65+
* @param items a collection of items to combine
66+
* @return a stream of sets containing all possible combinations of the given elements
67+
* @throws NullPointerException if the provided {@code items} collection is {@code null}.
6568
*/
6669
public static <T> Stream<Set<T>> of(@NotNull final Collection<T> items) {
6770
requireNonNull(items);
6871
return CombinationUtil.of(items);
6972
}
7073

7174
/**
72-
* Creates and returns all possible combinations of the given elements.
75+
* Creates and returns a stream of all possible combinations of the given elements.
7376
* <p>
7477
* The order of the combinations in the stream is unspecified.
7578
* <p>
76-
* It is unspecified if the method lazily consume the provided stream before providing
79+
* It is unspecified if the method lazily consumes the provided stream before providing
7780
* the result or not.
7881
*
79-
* @param <T> element type
80-
* @param items to combine
81-
* @return all possible combinations of the given elements
82+
* @param <T> element type
83+
* @param items a stream of items to combine
84+
* @return a stream of sets containing all possible combinations of the given elements
8285
* @throws NullPointerException if the provided {@code items} stream is {@code null}.
8386
*/
8487
public static <T> Stream<Set<T>> of(@NotNull final Stream<T> items) {
8588
requireNonNull(items);
8689
return CombinationUtil.of(items);
8790
}
88-
89-
}
91+
}

src/main/java/net/openhft/chronicle/testframework/Delegation.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,37 @@
77

88
import static java.util.Objects.requireNonNull;
99

10+
/**
11+
* Utility class to build delegator instances that forward method invocations
12+
* to a specified delegate object. This class facilitates a fluent API for customizing
13+
* the behavior of the delegator.
14+
* <p>
15+
* This class cannot be instantiated.
16+
*/
1017
public final class Delegation {
1118

1219
// Suppresses default constructor, ensuring non-instantiability.
1320
private Delegation() {
1421
}
1522

1623
/**
17-
* Creates and returns a new builder for a delegator instance that is using the provided
18-
* {@code delegate} as a delegate. I.e. methods invoked on a built instance will be delegated to the
24+
* Creates and returns a new builder for a delegator instance that will use the provided
25+
* {@code delegate} as the delegate. Method invocations on the built instance will be delegated to the
1926
* provided delegate.
2027
*
21-
* @param delegate to delegate invocations to
22-
* @param <D> provided delegate type
23-
* @return new delegator builder
24-
* @throws NullPointerException if any provided parameter is {@code null}.
28+
* @param delegate The object to delegate invocations to
29+
* @param <D> Provided delegate type
30+
* @return New delegator builder
31+
* @throws NullPointerException if the provided delegate is {@code null}.
2532
*/
2633
public static <D> Builder<Object, D> of(@NotNull final D delegate) {
2734
requireNonNull(delegate);
2835
return new DelegationBuilder<>(delegate);
2936
}
3037

3138
/**
32-
* The new instance will default it's {@link Object#toString()} method to the one of the
33-
* provided delegate.
39+
* Interface for building a delegation object. Allows customization of the type view
40+
* and the {@code toString()} method of the delegate.
3441
*
3542
* @param <T> Target type
3643
* @param <D> Delegation type
@@ -44,28 +51,29 @@ public interface Builder<T, D> {
4451
* <p>
4552
* The default view is {@link Object }.
4653
*
47-
* @param type to view the delegate as (non-null)
48-
* @param <N> the new type of how the delegate should be viewed
49-
* @return this builder
54+
* @param type The class to view the delegate as (non-null)
55+
* @param <N> The new type of how the delegate should be viewed
56+
* @return This builder, for chaining
5057
*/
5158
<N extends D> Builder<N, D> as(Class<N> type);
5259

5360
/**
54-
* Specifies the {@code tostring()) the view should use.
61+
* Specifies the {@code toString()} function the view should use.
5562
* <p>
56-
* The default view is {@link Object#toString()} }.
63+
* The default view is {@link Object#toString()}.
5764
*
58-
* @param toStringFunction to be applied to the delegate (non-null)
59-
* @return this builder
65+
* @param toStringFunction The function to be applied to the delegate (non-null)
66+
* @return This builder, for chaining
6067
*/
6168
Builder<T, D> toStringFunction(Function<? super D, String> toStringFunction);
6269

6370
/**
64-
* Creates and returns a new view of type T of the underlying delegate of type D
71+
* Creates and returns a new view of type T of the underlying delegate of type D.
72+
* <p>
73+
* This method finalizes the builder and returns the configured delegator.
6574
*
66-
* @return a new view
75+
* @return A new view of the delegate
6776
*/
6877
T build();
6978
}
70-
71-
}
79+
}

src/main/java/net/openhft/chronicle/testframework/ExecutorServiceUtil.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,73 @@
33
import java.util.concurrent.ExecutorService;
44
import java.util.concurrent.TimeUnit;
55

6+
/**
7+
* Utility class providing methods to shut down an {@link ExecutorService}
8+
* and wait for its termination, with or without forcibly interrupting running tasks.
9+
* <p>
10+
* This is an enum with no instances, serving solely for namespace control.
11+
*/
612
public enum ExecutorServiceUtil {
713
;
814

915
private static final int DEFAULT_TIME_TO_WAIT_SECONDS = 5;
1016

1117
/**
12-
* Shut down an executor service, waiting for it to terminate
18+
* Shut down an executor service and wait for it to terminate within the given timeout.
1319
*
1420
* @param executorService The executor service
15-
* @param timeout The timeout
21+
* @param timeout The maximum time to wait
1622
* @param unit The unit of the timeout argument
17-
* @throws IllegalStateException if it didn't terminate
23+
* @throws IllegalStateException If the executor service didn't terminate within the timeout
1824
*/
1925
public static void shutdownAndWaitForTermination(ExecutorService executorService, long timeout, TimeUnit unit) {
2026
executorService.shutdown();
2127
waitForTermination(executorService, timeout, unit);
2228
}
2329

2430
/**
25-
* Shut down an executor service, wait 5 seconds for it to terminate
31+
* Shut down an executor service and wait 5 seconds for it to terminate.
2632
*
2733
* @param executorService The executor service
28-
* @throws IllegalStateException if it didn't terminate in time
34+
* @throws IllegalStateException If it didn't terminate within the default time of 5 seconds
2935
*/
3036
public static void shutdownAndWaitForTermination(ExecutorService executorService) {
3137
executorService.shutdown();
3238
waitForTermination(executorService, DEFAULT_TIME_TO_WAIT_SECONDS, TimeUnit.SECONDS);
3339
}
3440

3541
/**
36-
* Shut down an executor service, interrupting all threads, wait 5 seconds for it to terminate
42+
* Shut down an executor service, interrupting all threads, and wait 5 seconds for it to terminate.
3743
*
3844
* @param executorService The executor service
39-
* @throws IllegalStateException if it didn't terminate in time
45+
* @throws IllegalStateException If it didn't terminate within the default time of 5 seconds
4046
*/
4147
public static void shutdownForciblyAndWaitForTermination(ExecutorService executorService) {
4248
shutdownForciblyAndWaitForTermination(executorService, DEFAULT_TIME_TO_WAIT_SECONDS, TimeUnit.SECONDS);
4349
}
4450

4551
/**
46-
* Shut down an executor service, interrupting all threads, wait for it to terminate
52+
* Shut down an executor service, interrupting all threads, and wait for it to terminate within the given timeout.
4753
*
4854
* @param executorService The executor service
49-
* @param timeout The timeout
55+
* @param timeout The maximum time to wait
5056
* @param unit The unit of the timeout argument
51-
* @throws IllegalStateException if it didn't terminate in time
57+
* @throws IllegalStateException If it didn't terminate within the specified timeout
5258
*/
5359
public static void shutdownForciblyAndWaitForTermination(ExecutorService executorService, long timeout, TimeUnit unit) {
54-
executorService.shutdownNow();
60+
executorService.shutdownNow(); // Interrupt all running tasks
5561
waitForTermination(executorService, timeout, unit);
5662
}
5763

64+
// Waits for the ExecutorService to terminate within the specified time
5865
private static void waitForTermination(ExecutorService executorService, long timeToWait, TimeUnit units) {
5966
try {
6067
if (!executorService.awaitTermination(timeToWait, units)) {
6168
throw new IllegalStateException("ExecutorService didn't shut down");
6269
}
6370
} catch (InterruptedException e) {
64-
Thread.currentThread().interrupt();
65-
throw new IllegalStateException("Interrupted waiting for executor service to shut down");
71+
Thread.currentThread().interrupt(); // Restore interrupted status
72+
throw new IllegalStateException("Interrupted waiting for executor service to shut down", e);
6673
}
6774
}
6875
}

0 commit comments

Comments
 (0)