git-svn-id: https://samskivert.googlecode.com/svn/trunk@1050 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ArrayUtil.java,v 1.24 2003/02/04 03:12:30 mdb Exp $
|
// $Id: ArrayUtil.java,v 1.25 2003/02/06 18:51:50 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Walter Korman
|
// Copyright (C) 2001 Walter Korman
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -623,6 +625,56 @@ public class ArrayUtil
|
|||||||
return nvalues;
|
return nvalues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new array one larger than the supplied array and with the
|
||||||
|
* specified value inserted into the last slot.
|
||||||
|
*/
|
||||||
|
public static byte[] append (byte[] values, byte value)
|
||||||
|
{
|
||||||
|
byte[] nvalues = new byte[values.length+1];
|
||||||
|
System.arraycopy(values, 0, nvalues, 0, values.length);
|
||||||
|
nvalues[values.length] = value;
|
||||||
|
return nvalues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new array one larger than the supplied array and with the
|
||||||
|
* specified value inserted into the last slot.
|
||||||
|
*/
|
||||||
|
public static short[] append (short[] values, short value)
|
||||||
|
{
|
||||||
|
short[] nvalues = new short[values.length+1];
|
||||||
|
System.arraycopy(values, 0, nvalues, 0, values.length);
|
||||||
|
nvalues[values.length] = value;
|
||||||
|
return nvalues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new array one larger than the supplied array and with the
|
||||||
|
* specified value inserted into the last slot.
|
||||||
|
*/
|
||||||
|
public static int[] append (int[] values, int value)
|
||||||
|
{
|
||||||
|
int[] nvalues = new int[values.length+1];
|
||||||
|
System.arraycopy(values, 0, nvalues, 0, values.length);
|
||||||
|
nvalues[values.length] = value;
|
||||||
|
return nvalues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new array one larger than the supplied array and with the
|
||||||
|
* specified value inserted into the last slot. The type of the values
|
||||||
|
* array will be preserved.
|
||||||
|
*/
|
||||||
|
public static Object[] append (Object[] values, Object value)
|
||||||
|
{
|
||||||
|
Object[] nvalues = (Object[])Array.newInstance(
|
||||||
|
values.getClass().getComponentType(), values.length+1);
|
||||||
|
System.arraycopy(values, 0, nvalues, 0, values.length);
|
||||||
|
nvalues[values.length] = value;
|
||||||
|
return nvalues;
|
||||||
|
}
|
||||||
|
|
||||||
/** The default random object used when shuffling an array. */
|
/** The default random object used when shuffling an array. */
|
||||||
protected static Random _rnd = new Random();
|
protected static Random _rnd = new Random();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IntListUtil.java,v 1.4 2003/02/04 03:12:30 mdb Exp $
|
// $Id: IntListUtil.java,v 1.5 2003/02/06 18:51:50 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
@@ -355,18 +355,6 @@ public class IntListUtil
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new array one larger than the supplied array and with the
|
|
||||||
* specified value inserted into the last slot.
|
|
||||||
*/
|
|
||||||
public static int[] append (int[] values, int value)
|
|
||||||
{
|
|
||||||
int[] nvalues = new int[values.length+1];
|
|
||||||
System.arraycopy(values, 0, nvalues, 0, values.length);
|
|
||||||
nvalues[values.length] = value;
|
|
||||||
return nvalues;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of the indexes in the given array of values that
|
* Returns an array of the indexes in the given array of values that
|
||||||
* have the maximum value in the array, or a zero-length array if the
|
* have the maximum value in the array, or a zero-length array if the
|
||||||
|
|||||||
Reference in New Issue
Block a user