@CodeReview(reviewer="Kevin R. Dixon", date="2008-02-26", changesNeeded=false, comments="Looks good.") public class Permutation extends java.lang.Object
Permutation
class contains methods for dealing with
permutations of object sets.Constructor and Description |
---|
Permutation()
Creates a new instance of Permutation
|
Modifier and Type | Method and Description |
---|---|
static int[] |
createPartialPermutation(int n,
int k,
java.util.Random random)
Creates a random partial permutation of size k of the numbers 0
(inclusive) through n (exclusive).
|
static int[] |
createPermutation(int n,
java.util.Random random)
Creates a random permutation of the numbers 0 (inclusive) through n
(exclusive).
|
static <DataType> java.util.ArrayList<DataType> |
createReordering(java.util.Collection<? extends DataType> collection,
java.util.Random random)
Takes a collection and returns an array list that contains a permutation
of the elements of that collection.
|
static <DataType> void |
reorder(java.util.ArrayList<DataType> list,
java.util.Random random)
Reorders the elements in a given array list to be a permuted ordering of
elements in the collection.
|
public static <DataType> void reorder(java.util.ArrayList<DataType> list, java.util.Random random)
DataType
- The data type of the list to reorder.list
- The array list to reorder.random
- The random number generator to use.public static <DataType> java.util.ArrayList<DataType> createReordering(java.util.Collection<? extends DataType> collection, java.util.Random random)
DataType
- Data class to reordercollection
- The collection to create a permutation of.random
- The random number generator to use.public static int[] createPermutation(int n, java.util.Random random)
n
- The size of the permutation.random
- The Random generator to use.public static int[] createPartialPermutation(int n, int k, java.util.Random random)
n
- The size of the set of numbers to get values of the partial
permutation from.k
- The size of the partial permutation. Must be less than or equal to
n. Cannot be negative.random
- The Random generator to use.