removed ArrayUtils.get

This commit is contained in:
MarkDacek 2018-07-14 15:42:14 -04:00
parent ec2ec77492
commit 2cad60b6c2
2 changed files with 0 additions and 49 deletions

View File

@ -8673,39 +8673,6 @@ public static void shuffle(final double[] array, final Random random) {
}
}
/**
* Gets an element from the array if the array is non-null and appropriately long, otherwise returns null
* @param <T> the component type of the array, may be null
* @param array the array holding the desired element
* @param index the index of the element in the array
* @return The element in the array at the index, or null if the array is not sufficiently long for the index. May return null if the array contains null
* @since 3.8
*/
public static <T> T get(T[] array, int index){
return get(array, index, null);
}
/**
* Gets an element from the array if the array is non-null and appropriately long, otherwise returns the specified value
* @param <T> the component type of the array
* @param array the array holding the desired element, may be null
* @param index the index of the element in the array
* @param defaultReturn the object to be returned if the array is null or shorter than the index
* @return The element in the array at the specified index, or the given argument if it the array is not sufficiently long for the index. May return null if the array contains null
* @since 3.8
*/
public static <T> T get(T[] array, int index, T defaultReturn){
if(getLength(array) == 0 || array.length <= index){
return defaultReturn;
}
if(index < 0 ){
return defaultReturn;
}
return array[index];
}
/**
* Returns whether a given array can safely be accessed at the given index.
* @param <T> the component type of the array

View File

@ -5112,22 +5112,6 @@ public void testShuffleDouble() {
}
}
@Test
public void testGet(){
assertNull(ArrayUtils.get(null, 0));
String[] array = new String[1];
assertNull(ArrayUtils.get(array, 1));
array[0] = "Hello World";
//test with happy path
assertNotNull(ArrayUtils.get(array, 0));
//test with default getter
assertEquals("Test", ArrayUtils.get(array, 10, "Test"));
//negative index
assertEquals("Default", ArrayUtils.get(array, -1, "Default"));
}
@Test
public void testIsArrayIndexValid(){
assertFalse(ArrayUtils.isArrayIndexValid(null, 0));