mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-27 21:39:11 +00:00
Javadoc & format
Clean up new test
This commit is contained in:
parent
7663a113b4
commit
10cf18310e
@ -22,9 +22,8 @@ package org.apache.commons.collections4;
|
||||
* Operations on arrays, primitive arrays (like {@code int[]}) and primitive wrapper arrays (like {@code Integer[]}).
|
||||
* </p>
|
||||
* <p>
|
||||
* This class tries to handle {@code null} input gracefully. An exception will not be thrown for a {@code null} array
|
||||
* input. However, an Object array that contains a {@code null} element may throw an exception. Each method documents
|
||||
* its behavior.
|
||||
* This class tries to handle {@code null} input gracefully. An exception will not be thrown for a {@code null} array input. However, an Object array that
|
||||
* contains a {@code null} element may throw an exception. Each method documents its behavior.
|
||||
* </p>
|
||||
* <p>
|
||||
* Package private, might move to an internal package if this needs to be public.
|
||||
@ -40,20 +39,19 @@ final class ArrayUtils {
|
||||
/**
|
||||
* Don't allow instances.
|
||||
*/
|
||||
private ArrayUtils() {}
|
||||
private ArrayUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Checks if the object is in the given array.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The method returns {@code false} if a {@code null} array is passed in.
|
||||
* </p>
|
||||
*
|
||||
* @param array
|
||||
* the array to search through
|
||||
* @param objectToFind
|
||||
* the object to find
|
||||
* @param array the array to search through
|
||||
* @param objectToFind the object to find
|
||||
* @return {@code true} if the array contains the object
|
||||
*/
|
||||
static boolean contains(final Object[] array, final Object objectToFind) {
|
||||
@ -64,17 +62,13 @@ final class ArrayUtils {
|
||||
* <p>
|
||||
* Finds the index of the given object in the array.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This method returns {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
|
||||
* </p>
|
||||
*
|
||||
* @param array
|
||||
* the array to search through for the object, may be {@code null}
|
||||
* @param objectToFind
|
||||
* the object to find, may be {@code null}
|
||||
* @return the index of the object within the array, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if not found or
|
||||
* {@code null} array input
|
||||
* @param array the array to search through for the object, may be {@code null}
|
||||
* @param objectToFind the object to find, may be {@code null}
|
||||
* @return the index of the object within the array, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
|
||||
*/
|
||||
static <T> int indexOf(final T[] array, final Object objectToFind) {
|
||||
return indexOf(array, objectToFind, 0);
|
||||
@ -84,24 +78,18 @@ final class ArrayUtils {
|
||||
* <p>
|
||||
* Finds the index of the given object in the array starting at the given index.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This method returns {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A negative startIndex is treated as zero. A startIndex larger than the array length will return
|
||||
* {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}).
|
||||
* A negative startIndex is treated as zero. A startIndex larger than the array length will return {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}).
|
||||
* </p>
|
||||
*
|
||||
* @param array
|
||||
* the array to search through for the object, may be {@code null}
|
||||
* @param objectToFind
|
||||
* the object to find, may be {@code null}
|
||||
* @param startIndex
|
||||
* the index to start searching at
|
||||
* @return the index of the object within the array starting at the index, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if
|
||||
* not found or {@code null} array input
|
||||
* @param array the array to search through for the object, may be {@code null}
|
||||
* @param objectToFind the object to find, may be {@code null}
|
||||
* @param startIndex the index to start searching at
|
||||
* @return the index of the object within the array starting at the index, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null}
|
||||
* array input
|
||||
*/
|
||||
static int indexOf(final Object[] array, final Object objectToFind, int startIndex) {
|
||||
if (array == null) {
|
||||
|
@ -24,23 +24,9 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ArrayUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testIndexOf() {
|
||||
final Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
|
||||
assertEquals(-1, ArrayUtils.indexOf(null, null));
|
||||
assertEquals(-1, ArrayUtils.indexOf(null, "0"));
|
||||
assertEquals(-1, ArrayUtils.indexOf(new Object[0], "0"));
|
||||
assertEquals(0, ArrayUtils.indexOf(array, "0"));
|
||||
assertEquals(1, ArrayUtils.indexOf(array, "1"));
|
||||
assertEquals(2, ArrayUtils.indexOf(array, "2"));
|
||||
assertEquals(3, ArrayUtils.indexOf(array, "3"));
|
||||
assertEquals(4, ArrayUtils.indexOf(array, null));
|
||||
assertEquals(-1, ArrayUtils.indexOf(array, "notInArray"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
final Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
|
||||
final Object[] array = { "0", "1", "2", "3", null, "0" };
|
||||
assertFalse(ArrayUtils.contains(null, null));
|
||||
assertFalse(ArrayUtils.contains(null, "1"));
|
||||
assertTrue(ArrayUtils.contains(array, "0"));
|
||||
@ -64,4 +50,18 @@ public class ArrayUtilsTest {
|
||||
final Object[] array = new LANG1261ChildObject[] { new LANG1261ChildObject() };
|
||||
assertTrue(ArrayUtils.contains(array, new LANG1261ParentObject()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexOf() {
|
||||
final Object[] array = { "0", "1", "2", "3", null, "0" };
|
||||
assertEquals(-1, ArrayUtils.indexOf(null, null));
|
||||
assertEquals(-1, ArrayUtils.indexOf(null, "0"));
|
||||
assertEquals(-1, ArrayUtils.indexOf(new Object[0], "0"));
|
||||
assertEquals(0, ArrayUtils.indexOf(array, "0"));
|
||||
assertEquals(1, ArrayUtils.indexOf(array, "1"));
|
||||
assertEquals(2, ArrayUtils.indexOf(array, "2"));
|
||||
assertEquals(3, ArrayUtils.indexOf(array, "3"));
|
||||
assertEquals(4, ArrayUtils.indexOf(array, null));
|
||||
assertEquals(-1, ArrayUtils.indexOf(array, "notInArray"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user