Moved reverseArray method from a private method in StringUtils into ArrayUtils.
This method exists in Jakarta Collection, so is a duplicate, but it belongs in ArrayUtils. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1a3ba6816d
commit
ae7c590d59
|
@ -69,7 +69,7 @@ import org.apache.commons.lang.builder.ToStringStyle;
|
||||||
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
|
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
|
||||||
* @author Nikolay Metchev
|
* @author Nikolay Metchev
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
* @version $Id: ArrayUtils.java,v 1.8 2003/02/04 22:06:24 scolebourne Exp $
|
* @version $Id: ArrayUtils.java,v 1.9 2003/03/23 04:58:47 bayard Exp $
|
||||||
*/
|
*/
|
||||||
public class ArrayUtils {
|
public class ArrayUtils {
|
||||||
|
|
||||||
|
@ -1012,4 +1012,25 @@ public class ArrayUtils {
|
||||||
return (indexOf(array, objectToFind) != -1);
|
return (indexOf(array, objectToFind) != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Reverses an array.</p>
|
||||||
|
*
|
||||||
|
* <p>TAKEN FROM CollectionsUtils.</p>
|
||||||
|
*
|
||||||
|
* @param array the array to reverse
|
||||||
|
*/
|
||||||
|
public static void reverseArray(Object[] array) {
|
||||||
|
int i = 0;
|
||||||
|
int j = array.length - 1;
|
||||||
|
Object tmp;
|
||||||
|
|
||||||
|
while (j > i) {
|
||||||
|
tmp = array[j];
|
||||||
|
array[j] = array[i];
|
||||||
|
array[i] = tmp;
|
||||||
|
j--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,9 @@ import org.apache.commons.lang.exception.NestableRuntimeException;
|
||||||
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
|
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
|
||||||
* @author Holger Krauth
|
* @author Holger Krauth
|
||||||
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
|
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
|
||||||
|
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @version $Id: StringUtils.java,v 1.33 2003/03/17 05:28:36 alex Exp $
|
* @version $Id: StringUtils.java,v 1.34 2003/03/23 04:58:47 bayard Exp $
|
||||||
*/
|
*/
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
|
@ -1722,31 +1723,10 @@ public class StringUtils {
|
||||||
// could implement manually, but simple way is to reuse other,
|
// could implement manually, but simple way is to reuse other,
|
||||||
// probably slower, methods.
|
// probably slower, methods.
|
||||||
String[] strs = split(str, delimiter);
|
String[] strs = split(str, delimiter);
|
||||||
reverseArray(strs);
|
ArrayUtils.reverseArray(strs);
|
||||||
return join(strs, delimiter);
|
return join(strs, delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Reverses an array.</p>
|
|
||||||
*
|
|
||||||
* <p>TAKEN FROM CollectionsUtils.</p>
|
|
||||||
*
|
|
||||||
* @param array the array to reverse
|
|
||||||
*/
|
|
||||||
private static void reverseArray(Object[] array) {
|
|
||||||
int i = 0;
|
|
||||||
int j = array.length - 1;
|
|
||||||
Object tmp;
|
|
||||||
|
|
||||||
while (j > i) {
|
|
||||||
tmp = array[j];
|
|
||||||
array[j] = array[i];
|
|
||||||
array[i] = tmp;
|
|
||||||
j--;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Abbreviating
|
// Abbreviating
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue