edu.umd.cfar.lamp.viper.util
Class Permuter

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.util.Permuter

public class Permuter
extends java.lang.Object

This class takes in an array of Objects and runs through all possible permutations.

Author:
David Mihalcik
See Also:
Combinator

Constructor Summary
Permuter(java.lang.Object[] stringToPermute)
          Constructs a new Permuter to iterate over all permutations of the given string.
 
Method Summary
static int factorial(int x)
          Gets the factorial of an integer.
 java.lang.Object[] getNextPermutation()
          Based on Dijkstra's method for doing this sort of thing.
 java.lang.String toString()
          Gets a string representation of the current permutation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Permuter

public Permuter(java.lang.Object[] stringToPermute)
Constructs a new Permuter to iterate over all permutations of the given string.

Parameters:
stringToPermute - The Objects to rearrange.
Method Detail

factorial

public static int factorial(int x)
Gets the factorial of an integer.

Parameters:
x - The integer.
Returns:
x!

getNextPermutation

public java.lang.Object[] getNextPermutation()
Based on Dijkstra's method for doing this sort of thing.
    private void getNext()
    {
        int i = N - 1;
        while (Value[i-1] >= Value[i])
            i = i-1;

        int j = N;
        while (Value[j-1] <= Value[i-1])
            j = j-1;

        swap(i-1, j-1);
        i++; j = N;
        while (i < j) {
            swap(i-1, j-1);
            i++;
            j--;
        }
    }
 

Returns:
The next arrangement.

toString

public java.lang.String toString()
Gets a string representation of the current permutation.

Returns:
The current permutation bracketed and with spaces.