|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.collection.Permuter
public class Permuter
Permutes the items in an ordered collection according to a index reordering. A permutation is an integer array which shows where each item in the new ordering of items should come from, based on the original order. For example, a collection containing the string values
{ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" }
and permuted with the int array
{ 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 }
will result in the collection
{ "I", "J", "K", "L", "E", "F", "G", "H", "A", "B", "C", "D" }
A permutation array must satisfy these constraints:
IndexedSetInterface, i.e. just the methods
Object count();
Object get(int);
void set(int index, Object value)
| Constructor Summary | |
|---|---|
Permuter()
Default constructor. |
|
Permuter(IndexedSetInterface collection)
Construct a Permuter for a collection. |
|
Permuter(IndexedSetInterface collection,
int size)
Construct a Permuter for a collection. |
|
Permuter(IndexedSetInterface collection,
int[] permutation)
Construct a Permuter for a collection and a permutation. |
|
Permuter(int[] permutation)
Construct a Permuter with a permutation array. |
|
| Method Summary | |
|---|---|
protected void |
disableEvents()
If the collection implements the EventGateInterface,
use it to suppress events during a permute operation. |
protected void |
enableEvents()
If the collection implements the EventGateInterface,
use it to allow events after a permute operation. |
IndexedSetInterface |
getCollection()
Return the collection that this Permuter will permute. |
int[] |
getPermutation()
Get the permutation for the collection. |
int[] |
identityPermutation()
Return an identity permutation. |
static int[] |
identityPermutation(int length)
Return an identity permutation. |
static void |
move(IndexedSetInterface collection,
int[] items,
int offset)
Move the items selected by an array of indices by an offset. |
static void |
move(IndexedSetInterface collection,
int index,
int offset)
Move an item in a collection by a specified offset. |
void |
move(int[] items,
int offset)
Move the items selected by an array of indices by an offset. |
void |
move(int index,
int offset)
Move an item in the collection by a specified offset. |
int[] |
newMovePermutation(int[] items,
int offset)
Create a permutation which will move by a specified offset the set of items specified by an array of item indeces. |
int[] |
newMovePermutation(int index,
int offset)
Create a permutation which will move an item in the collection by a specified offset. |
int[] |
newReversePermutation(int start,
int end)
Create a permutation array which reverses the items between start and end |
int[] |
newRotatePermutation(int start,
int end,
int n)
Create a permutation array which rotates the items between start and end by n items. |
void |
permute()
Permute the collection according to the permutation. |
static void |
permute(IndexedSetInterface collection,
int[] permutation)
A static method useful for a one-time permutation of a collection. |
void |
permute(int[] permutation)
Set the permutation, then permutes the collection. |
static void |
reverse(IndexedSetInterface collection,
int start,
int end)
A static method useful for reversing a (subrange) of items in a collection. |
void |
reverse(int start,
int end)
Reverse a (subrange) of the collection. |
static void |
rotate(IndexedSetInterface collection,
int start,
int end,
int n)
A static method useful for rotating a (subrange) of items in a collection. |
void |
rotate(int start,
int end,
int n)
Rotate a (subrange) of items in a collection. |
void |
setCollection(IndexedSetInterface collection)
Set the collection which this Permuter will permute. |
void |
setCollection(IndexedSetInterface collection,
int size)
Set the collection which this Permuter will permute. |
void |
setPermutation(int[] permutation)
Set the permutation array. |
static void |
swap(IndexedSetInterface collection,
int i,
int j)
Convenience method to swap two items in an ordered collection. |
protected void |
validateItems(int[] items,
int offset,
int length)
Validate that all items are in the range [0,length-1]
may be moved by an offset. |
protected void |
validatePermutation(int[] permutation)
Validate a permutation. |
| Constructor Detail |
|---|
public Permuter()
setCollection(com.sas.util.IndexedSetInterface) and setPermutation(int[])
to initialize the Permuter.
public Permuter(IndexedSetInterface collection,
int[] permutation)
Permuter for a collection and a permutation.
collection - the collection to permutepermutation - the purmutation arraypublic Permuter(int[] permutation)
setCollection(com.sas.util.IndexedSetInterface)
to specifiy the collection to permute.
permutation - the purmutation arraypublic Permuter(IndexedSetInterface collection)
setPermutation(int[])
to specifiy the permutation array.
collection - the collection to permute
public Permuter(IndexedSetInterface collection,
int size)
collection - the collection to permutesize - the collection size, used instead of
collection.count().| Method Detail |
|---|
public IndexedSetInterface getCollection()
Permuter will permute.
Permuter will permute.public void setCollection(IndexedSetInterface collection)
Permuter will permute.
collection - a ordered collection
public void setCollection(IndexedSetInterface collection,
int size)
Permuter will permute.
collection - a ordered collectionsize - the collection size, used instead of
collection.count().public int[] getPermutation()
int[] permutation.public void setPermutation(int[] permutation)
an - array of permutation indices.
A permutation array must satisfy the constraints
defined in validatePermutation(int[]):protected void disableEvents()
EventGateInterface,
use it to suppress events during a permute operation.
protected void enableEvents()
EventGateInterface,
use it to allow events after a permute operation.
protected void validatePermutation(int[] permutation)
permutation - an array of indices to validatepublic void permute()
EventGateInterface,
use it to suppress events during the permutation operation.
so that an event is not fired for every item that is moved.
public void permute(int[] permutation)
public static void permute(IndexedSetInterface collection,
int[] permutation)
collection - the collection to permitepermutation - the permutation array
public static void reverse(IndexedSetInterface collection,
int start,
int end)
reverse(collection, 0, collection.count());
collection - the collection to reversestart - the index of the first item in the range of items to reverseend - one past the index of the last item in the range of items to reverse.
public void reverse(int start,
int end)
setPermutation(int[]).
To reverse the entire collection, use
reverse(0, collection.count());
start - the index of the first item in the range of items to reverseend - one past the index of the last item in the range of items to reverse.
public int[] newReversePermutation(int start,
int end)
start - the index of the first item in the range of items to reverseend - one past the index of the last item in the range of items to reverse.
public static void swap(IndexedSetInterface collection,
int i,
int j)
AssociationListInterface;
it swaps the key and item values at i and j
collection - the collection in which to swap itemsi - index of one item to swapj - index of the other item to swap
public static void rotate(IndexedSetInterface collection,
int start,
int end,
int n)
rotate(collection, 0, collection.count(), n);
collection - the collection to rotatestart - the index of the first item in the range of items to rotateend - one past the index of the last item in the range of items to rotaten - the distance you want to rotate items.rotate(int, int, int)
public void rotate(int start,
int end,
int n)
rotate(0, collection.count(), n);
collection - the collection to rotatestart - the index of the first item in the range of items to rotate.end - one past the index of the last item in the range of items to rotate.n - the distance you want to rotate items. If n > 0, items are rotated
right to left n places; if n < 0, items are rotated left to right n places.
For example, the collection
{ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" }
rotated by 2 yields
{ "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "A", "B" }
public int[] newRotatePermutation(int start,
int end,
int n)
start - the index of the first item in the range of items to rotate.end - one past the index of the last item in the range of items to rotate.n - the distance you want to rotate items. If n > 0, items are rotated
right to left n places; if n < 0, items are rotated left to right n places.
public static void move(IndexedSetInterface collection,
int index,
int offset)
collection - the collection to permute.index - the index of the item you want to move.offset - the distance you want to move the item.
Move the item to position index + offset.move(int, int)
public void move(int index,
int offset)
index - the index of the item you want to move.offset - the distance you want to move the item.
Negative numbers move the items closer to the beginning;
positive numbers move the items towards the end. Move
the item to position index + offset. All other
items between index and index+offset are
shifted. This therefore has the same effect as rotating
the affected items left or right 1 item, depending on the
sign of the offset.
public int[] newMovePermutation(int index,
int offset)
index - the index of the item you want to move.offset - the distance you want to move the item.
Negative numbers move the items closer to the beginning;
positive numbers move the items towards the end.
public static void move(IndexedSetInterface collection,
int[] items,
int offset)
collection - the collection to permute.items - an array of item indices. Each element
must be a valid index within the collection.offset - how much to move the items.
negative numbers move the items closer to the beginning;
positive numbers move the items towards the end.move(int[], int)
public void move(int[] items,
int offset)
collection - the collection to permute.items - an array of item indices. Each element
must be a valid index within the collection.
The items must be in ascending order and
each index must be unique.offset - how much to move the items.
negative numbers move the items closer to the beginning;
positive numbers move the items towards the end.
public int[] newMovePermutation(int[] items,
int offset)
items - an array of indices identifying the items item you want to move.
The array need not be contiguous, but the items must be in ascending order and
each index must be unique.offset - the distance you want to move the items.
negative numbers move the items closer to the beginning;
positive numbers move the items towards the end.
protected void validateItems(int[] items,
int offset,
int length)
[0,length-1]
may be moved by an offset.
items - an array of permutation indicesoffset - how much to move the items.length - the permutation length.public int[] identityPermutation()
public static int[] identityPermutation(int length)
length - the size of the permutation array
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||