This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 19adcd792fb514e741cabdeda87e41f405fed268 Author: Gary Gregory <[email protected]> AuthorDate: Wed Nov 19 10:09:26 2025 -0500 Sort members --- .../java/org/apache/commons/lang3/ClassUtils.java | 72 ++++++------- .../org/apache/commons/lang3/time/StopWatch.java | 112 ++++++++++----------- .../org/apache/commons/lang3/ClassUtilsTest.java | 4 +- .../apache/commons/lang3/time/StopWatchTest.java | 60 +++++------ 4 files changed, 124 insertions(+), 124 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index f6185e9d9..6e8af9d9c 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -48,6 +48,20 @@ */ public class ClassUtils { + /** + * Inclusivity literals for {@link #hierarchy(Class, Interfaces)}. + * + * @since 3.2 + */ + public enum Interfaces { + + /** Includes interfaces. */ + INCLUDE, + + /** Excludes interfaces. */ + EXCLUDE + } + /** * The JLS-specified maximum class name length {@value}. * @@ -68,20 +82,6 @@ public class ClassUtils { */ private static final int MAX_JVM_ARRAY_DIMENSION = 255; - /** - * Inclusivity literals for {@link #hierarchy(Class, Interfaces)}. - * - * @since 3.2 - */ - public enum Interfaces { - - /** Includes interfaces. */ - INCLUDE, - - /** Excludes interfaces. */ - EXCLUDE - } - /** * The maximum number of array dimensions. */ @@ -1535,6 +1535,28 @@ public static Class<?> primitiveToWrapper(final Class<?> cls) { return cls != null && cls.isPrimitive() ? PRIMITIVE_WRAPPER_MAP.get(cls) : cls; } + /** + * Converts an array of {@link Object} in to an array of {@link Class} objects. If any of these objects is null, a null element will be inserted into the + * array. + * + * <p> + * This method returns {@code null} for a {@code null} input array. + * </p> + * + * @param array an {@link Object} array. + * @return a {@link Class} array, {@code null} if null array input. + * @since 2.4 + */ + public static Class<?>[] toClass(final Object... array) { + if (array == null) { + return null; + } + if (array.length == 0) { + return ArrayUtils.EMPTY_CLASS_ARRAY; + } + return ArrayUtils.setAll(new Class[array.length], i -> array[i] == null ? null : array[i].getClass()); + } + /** * Converts and cleans up a class name to a JLS style class name. * @@ -1596,28 +1618,6 @@ private static String toCleanName(final String className) { return canonicalName; } - /** - * Converts an array of {@link Object} in to an array of {@link Class} objects. If any of these objects is null, a null element will be inserted into the - * array. - * - * <p> - * This method returns {@code null} for a {@code null} input array. - * </p> - * - * @param array an {@link Object} array. - * @return a {@link Class} array, {@code null} if null array input. - * @since 2.4 - */ - public static Class<?>[] toClass(final Object... array) { - if (array == null) { - return null; - } - if (array.length == 0) { - return ArrayUtils.EMPTY_CLASS_ARRAY; - } - return ArrayUtils.setAll(new Class[array.length], i -> array[i] == null ? null : array[i].getClass()); - } - /** * Decides if the part that was just copied to its destination location in the work array can be kept as it was copied * or must be abbreviated. It must be kept when the part is the last one, which is the simple name of the class. In this diff --git a/src/main/java/org/apache/commons/lang3/time/StopWatch.java b/src/main/java/org/apache/commons/lang3/time/StopWatch.java index 4a8823f4f..72b072069 100644 --- a/src/main/java/org/apache/commons/lang3/time/StopWatch.java +++ b/src/main/java/org/apache/commons/lang3/time/StopWatch.java @@ -73,6 +73,52 @@ */ public class StopWatch { + /** + * Stores a split as a label and duration. + * + * @since 3.20.0 + */ + public static final class Split extends ImmutablePair<String, Duration> { + + /** + * Constructs a Split object with label and duration. + * + * @param label Label for this split. + * @param duration Duration for this split. + */ + public Split(String label, Duration duration) { + super(label, duration); + } + + /** + * Gets the duration of this split. + * + * @return The duration of this split.. + */ + public Duration getDuration() { + return getRight(); + } + + /** + * Gets the label of this split. + * + * @return The label of this split. + */ + public String getLabel() { + return getLeft(); + } + + /** + * Converts this instance to a string. + * + * @return this instance to a string. + */ + @Override + public String toString() { + return String.format("Split [%s, %s])", getLabel(), getDuration()); + } + } + /** * Enumeration type which indicates the split status of a StopWatch. */ @@ -335,16 +381,6 @@ public String getMessage() { return message; } - /** - * Gets the split list. - * - * @return the list of splits. - * @since 3.20.0 - */ - public List<Split> getSplits() { - return Collections.unmodifiableList(splits); - } - /** * Gets the <em>elapsed</em> time in nanoseconds. * @@ -404,6 +440,16 @@ public long getSplitNanoTime() { return splits.get(splits.size() - 1).getRight().toNanos(); } + /** + * Gets the split list. + * + * @return the list of splits. + * @since 3.20.0 + */ + public List<Split> getSplits() { + return Collections.unmodifiableList(splits); + } + /** * Gets the split time on this StopWatch. * @@ -790,50 +836,4 @@ public void unsplit() { splits.remove(splits.size() - 1); } - /** - * Stores a split as a label and duration. - * - * @since 3.20.0 - */ - public static final class Split extends ImmutablePair<String, Duration> { - - /** - * Constructs a Split object with label and duration. - * - * @param label Label for this split. - * @param duration Duration for this split. - */ - public Split(String label, Duration duration) { - super(label, duration); - } - - /** - * Gets the label of this split. - * - * @return The label of this split. - */ - public String getLabel() { - return getLeft(); - } - - /** - * Gets the duration of this split. - * - * @return The duration of this split.. - */ - public Duration getDuration() { - return getRight(); - } - - /** - * Converts this instance to a string. - * - * @return this instance to a string. - */ - @Override - public String toString() { - return String.format("Split [%s, %s])", getLabel(), getDuration()); - } - } - } diff --git a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java index 96ce5cdad..f4cdc9c47 100644 --- a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java @@ -59,8 +59,6 @@ @SuppressWarnings("boxing") // JUnit4 does not support primitive equality testing apart from long class ClassUtilsTest extends AbstractLangTest { - private static final int MAX_ARRAY_DIMENSIONS = 255; - private static class CX implements IB, IA, IE { // empty } @@ -100,6 +98,8 @@ private static final class DeeplyNested { } } + private static final int MAX_ARRAY_DIMENSIONS = 255; + private static final String OBJECT_CANONICAL_NAME = "java.lang.Object"; private void assertGetClassReturnsClass(final Class<?> c) throws Exception { diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java index d365dceac..bffb29acb 100644 --- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java +++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java @@ -392,6 +392,36 @@ void testSplit() throws InterruptedException { assertTrue(totalDuration.toMillis() >= sleepMillisX3); } + @Test + void testSplitsWithStringLabels() { + final StopWatch watch = new StopWatch(); + final String firstLabel = "one"; + final String secondLabel = "two"; + final String thirdLabel = "three"; + watch.start(); + // starting splits + watch.split(firstLabel); + watch.split(secondLabel); + watch.split(thirdLabel); + watch.stop(); + // getting splits + final List<StopWatch.Split> splits = watch.getSplits(); + // check size + assertEquals(3, splits.size()); + // check labels + assertEquals(firstLabel, splits.get(0).getLabel()); + assertEquals(secondLabel, splits.get(1).getLabel()); + assertEquals(thirdLabel, splits.get(2).getLabel()); + // check time in nanos + assertTrue(splits.get(0).getDuration().toNanos() > 0); + assertTrue(splits.get(1).getDuration().toNanos() > 0); + assertTrue(splits.get(2).getDuration().toNanos() > 0); + // We can only unsplit once + watch.unsplit(); + assertEquals(2, watch.getSplits().size()); + assertThrows(IllegalStateException.class, watch::unsplit); + } + @Test void testStatic() { final StopWatch watch = StopWatch.createStarted(); @@ -522,36 +552,6 @@ void testToStringWithMessage() throws InterruptedException { assertEquals(SPLIT_CLOCK_STR_LEN + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length"); } - @Test - void testSplitsWithStringLabels() { - final StopWatch watch = new StopWatch(); - final String firstLabel = "one"; - final String secondLabel = "two"; - final String thirdLabel = "three"; - watch.start(); - // starting splits - watch.split(firstLabel); - watch.split(secondLabel); - watch.split(thirdLabel); - watch.stop(); - // getting splits - final List<StopWatch.Split> splits = watch.getSplits(); - // check size - assertEquals(3, splits.size()); - // check labels - assertEquals(firstLabel, splits.get(0).getLabel()); - assertEquals(secondLabel, splits.get(1).getLabel()); - assertEquals(thirdLabel, splits.get(2).getLabel()); - // check time in nanos - assertTrue(splits.get(0).getDuration().toNanos() > 0); - assertTrue(splits.get(1).getDuration().toNanos() > 0); - assertTrue(splits.get(2).getDuration().toNanos() > 0); - // We can only unsplit once - watch.unsplit(); - assertEquals(2, watch.getSplits().size()); - assertThrows(IllegalStateException.class, watch::unsplit); - } - private int throwIOException() throws IOException { throw new IOException("A"); }
