Skip to content

Commit 19adcd7

Browse files
committed
Sort members
1 parent 8edc751 commit 19adcd7

File tree

4 files changed

+124
-124
lines changed

4 files changed

+124
-124
lines changed

src/main/java/org/apache/commons/lang3/ClassUtils.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@
4848
*/
4949
public class ClassUtils {
5050

51+
/**
52+
* Inclusivity literals for {@link #hierarchy(Class, Interfaces)}.
53+
*
54+
* @since 3.2
55+
*/
56+
public enum Interfaces {
57+
58+
/** Includes interfaces. */
59+
INCLUDE,
60+
61+
/** Excludes interfaces. */
62+
EXCLUDE
63+
}
64+
5165
/**
5266
* The JLS-specified maximum class name length {@value}.
5367
*
@@ -68,20 +82,6 @@ public class ClassUtils {
6882
*/
6983
private static final int MAX_JVM_ARRAY_DIMENSION = 255;
7084

71-
/**
72-
* Inclusivity literals for {@link #hierarchy(Class, Interfaces)}.
73-
*
74-
* @since 3.2
75-
*/
76-
public enum Interfaces {
77-
78-
/** Includes interfaces. */
79-
INCLUDE,
80-
81-
/** Excludes interfaces. */
82-
EXCLUDE
83-
}
84-
8585
/**
8686
* The maximum number of array dimensions.
8787
*/
@@ -1535,6 +1535,28 @@ public static Class<?> primitiveToWrapper(final Class<?> cls) {
15351535
return cls != null && cls.isPrimitive() ? PRIMITIVE_WRAPPER_MAP.get(cls) : cls;
15361536
}
15371537

1538+
/**
1539+
* 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
1540+
* array.
1541+
*
1542+
* <p>
1543+
* This method returns {@code null} for a {@code null} input array.
1544+
* </p>
1545+
*
1546+
* @param array an {@link Object} array.
1547+
* @return a {@link Class} array, {@code null} if null array input.
1548+
* @since 2.4
1549+
*/
1550+
public static Class<?>[] toClass(final Object... array) {
1551+
if (array == null) {
1552+
return null;
1553+
}
1554+
if (array.length == 0) {
1555+
return ArrayUtils.EMPTY_CLASS_ARRAY;
1556+
}
1557+
return ArrayUtils.setAll(new Class[array.length], i -> array[i] == null ? null : array[i].getClass());
1558+
}
1559+
15381560
/**
15391561
* Converts and cleans up a class name to a JLS style class name.
15401562
*
@@ -1596,28 +1618,6 @@ private static String toCleanName(final String className) {
15961618
return canonicalName;
15971619
}
15981620

1599-
/**
1600-
* 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
1601-
* array.
1602-
*
1603-
* <p>
1604-
* This method returns {@code null} for a {@code null} input array.
1605-
* </p>
1606-
*
1607-
* @param array an {@link Object} array.
1608-
* @return a {@link Class} array, {@code null} if null array input.
1609-
* @since 2.4
1610-
*/
1611-
public static Class<?>[] toClass(final Object... array) {
1612-
if (array == null) {
1613-
return null;
1614-
}
1615-
if (array.length == 0) {
1616-
return ArrayUtils.EMPTY_CLASS_ARRAY;
1617-
}
1618-
return ArrayUtils.setAll(new Class[array.length], i -> array[i] == null ? null : array[i].getClass());
1619-
}
1620-
16211621
/**
16221622
* Decides if the part that was just copied to its destination location in the work array can be kept as it was copied
16231623
* 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

src/main/java/org/apache/commons/lang3/time/StopWatch.java

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,52 @@
7373
*/
7474
public class StopWatch {
7575

76+
/**
77+
* Stores a split as a label and duration.
78+
*
79+
* @since 3.20.0
80+
*/
81+
public static final class Split extends ImmutablePair<String, Duration> {
82+
83+
/**
84+
* Constructs a Split object with label and duration.
85+
*
86+
* @param label Label for this split.
87+
* @param duration Duration for this split.
88+
*/
89+
public Split(String label, Duration duration) {
90+
super(label, duration);
91+
}
92+
93+
/**
94+
* Gets the duration of this split.
95+
*
96+
* @return The duration of this split..
97+
*/
98+
public Duration getDuration() {
99+
return getRight();
100+
}
101+
102+
/**
103+
* Gets the label of this split.
104+
*
105+
* @return The label of this split.
106+
*/
107+
public String getLabel() {
108+
return getLeft();
109+
}
110+
111+
/**
112+
* Converts this instance to a string.
113+
*
114+
* @return this instance to a string.
115+
*/
116+
@Override
117+
public String toString() {
118+
return String.format("Split [%s, %s])", getLabel(), getDuration());
119+
}
120+
}
121+
76122
/**
77123
* Enumeration type which indicates the split status of a StopWatch.
78124
*/
@@ -335,16 +381,6 @@ public String getMessage() {
335381
return message;
336382
}
337383

338-
/**
339-
* Gets the split list.
340-
*
341-
* @return the list of splits.
342-
* @since 3.20.0
343-
*/
344-
public List<Split> getSplits() {
345-
return Collections.unmodifiableList(splits);
346-
}
347-
348384
/**
349385
* Gets the <em>elapsed</em> time in nanoseconds.
350386
*
@@ -404,6 +440,16 @@ public long getSplitNanoTime() {
404440
return splits.get(splits.size() - 1).getRight().toNanos();
405441
}
406442

443+
/**
444+
* Gets the split list.
445+
*
446+
* @return the list of splits.
447+
* @since 3.20.0
448+
*/
449+
public List<Split> getSplits() {
450+
return Collections.unmodifiableList(splits);
451+
}
452+
407453
/**
408454
* Gets the split time on this StopWatch.
409455
*
@@ -790,50 +836,4 @@ public void unsplit() {
790836
splits.remove(splits.size() - 1);
791837
}
792838

793-
/**
794-
* Stores a split as a label and duration.
795-
*
796-
* @since 3.20.0
797-
*/
798-
public static final class Split extends ImmutablePair<String, Duration> {
799-
800-
/**
801-
* Constructs a Split object with label and duration.
802-
*
803-
* @param label Label for this split.
804-
* @param duration Duration for this split.
805-
*/
806-
public Split(String label, Duration duration) {
807-
super(label, duration);
808-
}
809-
810-
/**
811-
* Gets the label of this split.
812-
*
813-
* @return The label of this split.
814-
*/
815-
public String getLabel() {
816-
return getLeft();
817-
}
818-
819-
/**
820-
* Gets the duration of this split.
821-
*
822-
* @return The duration of this split..
823-
*/
824-
public Duration getDuration() {
825-
return getRight();
826-
}
827-
828-
/**
829-
* Converts this instance to a string.
830-
*
831-
* @return this instance to a string.
832-
*/
833-
@Override
834-
public String toString() {
835-
return String.format("Split [%s, %s])", getLabel(), getDuration());
836-
}
837-
}
838-
839839
}

src/test/java/org/apache/commons/lang3/ClassUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
@SuppressWarnings("boxing") // JUnit4 does not support primitive equality testing apart from long
6060
class ClassUtilsTest extends AbstractLangTest {
6161

62-
private static final int MAX_ARRAY_DIMENSIONS = 255;
63-
6462
private static class CX implements IB, IA, IE {
6563
// empty
6664
}
@@ -100,6 +98,8 @@ private static final class DeeplyNested {
10098
}
10199
}
102100

101+
private static final int MAX_ARRAY_DIMENSIONS = 255;
102+
103103
private static final String OBJECT_CANONICAL_NAME = "java.lang.Object";
104104

105105
private void assertGetClassReturnsClass(final Class<?> c) throws Exception {

src/test/java/org/apache/commons/lang3/time/StopWatchTest.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,36 @@ void testSplit() throws InterruptedException {
392392
assertTrue(totalDuration.toMillis() >= sleepMillisX3);
393393
}
394394

395+
@Test
396+
void testSplitsWithStringLabels() {
397+
final StopWatch watch = new StopWatch();
398+
final String firstLabel = "one";
399+
final String secondLabel = "two";
400+
final String thirdLabel = "three";
401+
watch.start();
402+
// starting splits
403+
watch.split(firstLabel);
404+
watch.split(secondLabel);
405+
watch.split(thirdLabel);
406+
watch.stop();
407+
// getting splits
408+
final List<StopWatch.Split> splits = watch.getSplits();
409+
// check size
410+
assertEquals(3, splits.size());
411+
// check labels
412+
assertEquals(firstLabel, splits.get(0).getLabel());
413+
assertEquals(secondLabel, splits.get(1).getLabel());
414+
assertEquals(thirdLabel, splits.get(2).getLabel());
415+
// check time in nanos
416+
assertTrue(splits.get(0).getDuration().toNanos() > 0);
417+
assertTrue(splits.get(1).getDuration().toNanos() > 0);
418+
assertTrue(splits.get(2).getDuration().toNanos() > 0);
419+
// We can only unsplit once
420+
watch.unsplit();
421+
assertEquals(2, watch.getSplits().size());
422+
assertThrows(IllegalStateException.class, watch::unsplit);
423+
}
424+
395425
@Test
396426
void testStatic() {
397427
final StopWatch watch = StopWatch.createStarted();
@@ -522,36 +552,6 @@ void testToStringWithMessage() throws InterruptedException {
522552
assertEquals(SPLIT_CLOCK_STR_LEN + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length");
523553
}
524554

525-
@Test
526-
void testSplitsWithStringLabels() {
527-
final StopWatch watch = new StopWatch();
528-
final String firstLabel = "one";
529-
final String secondLabel = "two";
530-
final String thirdLabel = "three";
531-
watch.start();
532-
// starting splits
533-
watch.split(firstLabel);
534-
watch.split(secondLabel);
535-
watch.split(thirdLabel);
536-
watch.stop();
537-
// getting splits
538-
final List<StopWatch.Split> splits = watch.getSplits();
539-
// check size
540-
assertEquals(3, splits.size());
541-
// check labels
542-
assertEquals(firstLabel, splits.get(0).getLabel());
543-
assertEquals(secondLabel, splits.get(1).getLabel());
544-
assertEquals(thirdLabel, splits.get(2).getLabel());
545-
// check time in nanos
546-
assertTrue(splits.get(0).getDuration().toNanos() > 0);
547-
assertTrue(splits.get(1).getDuration().toNanos() > 0);
548-
assertTrue(splits.get(2).getDuration().toNanos() > 0);
549-
// We can only unsplit once
550-
watch.unsplit();
551-
assertEquals(2, watch.getSplits().size());
552-
assertThrows(IllegalStateException.class, watch::unsplit);
553-
}
554-
555555
private int throwIOException() throws IOException {
556556
throw new IOException("A");
557557
}

0 commit comments

Comments
 (0)