gov.sandia.cognition.math
Class Permutation

java.lang.Object
  extended by gov.sandia.cognition.math.Permutation

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-02-26",
            changesNeeded=false,
            comments="Looks good.")
public class Permutation
extends Object

The Permutation class contains methods for dealing with permutations of object sets.

Since:
1.0
Author:
Justin Basilico

Constructor Summary
Permutation()
          Creates a new instance of Permutation
 
Method Summary
static int[] createPermutation(int n, Random random)
          Creates a random permutation of the numbers 0 (inclusive) through n (exclusive).
static
<DataType> ArrayList<DataType>
createReordering(Collection<? extends DataType> collection, Random random)
          Takes a collection and returns an array list that contains a permutation of the elements of that collection.
static
<DataType> void
reorder(ArrayList<DataType> list, Random random)
          Reorders the elements in a given array list to be a permuted ordering of elements in the collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Permutation

public Permutation()
Creates a new instance of Permutation

Method Detail

reorder

public static <DataType> void reorder(ArrayList<DataType> list,
                                      Random random)
Reorders the elements in a given array list to be a permuted ordering of elements in the collection.

Type Parameters:
DataType - The data type of the list to reorder.
Parameters:
list - The array list to reorder.
random - The random number generator to use.

createReordering

public static <DataType> ArrayList<DataType> createReordering(Collection<? extends DataType> collection,
                                                              Random random)
Takes a collection and returns an array list that contains a permutation of the elements of that collection.

Type Parameters:
DataType - Data class to reorder
Parameters:
collection - The collection to create a permutation of.
random - The random number generator to use.
Returns:
A permutation of the given collection.

createPermutation

public static int[] createPermutation(int n,
                                      Random random)
Creates a random permutation of the numbers 0 (inclusive) through n (exclusive). The permutation contains the all the numbers 0 through n in a random order. There are no duplicates.

Parameters:
n - The size of the permutation.
random - The Random generator to use.
Returns:
A random permutation of the numbers 0 through n.