helix.graph.util
Class IPermutation

java.lang.Object
  extended by helix.graph.util.IPermutation
All Implemented Interfaces:
Iterable<Integer>

public class IPermutation
extends Object
implements Iterable<Integer>

a class implementing an index permutation in range [from, to] TODO ISelector instead


Constructor Summary
IPermutation(int range)
          identity in [0, range-1]
IPermutation(int from, int to)
          identity in [from, to]
IPermutation(Iterable<Integer> values)
          new IPermutation from values.
IPermutation(String s)
          new IPermutation from parsed String.
 
Method Summary
<T> List<T>
apply(List<T> l)
          apply permutation on list of objects.
 boolean containsAll(Iterable<Integer> set)
          check if permutation contains the set of integers given as argument
 boolean equals(Object o)
          override equals
 int from()
          get permutation starting value (from)
 int get(int indx)
          return value at given index
 int hashCode()
          override hashCode
 IPermutation inverse()
          returns a new IPermutation, inverse of this permutation
 boolean isIdentity()
          check if permutation is identity in [0-n]
 Iterator<Integer> iterator()
           
 int lookup(int value)
          get index of value return -1 if value is not found
 IPermutation shift()
          same as permutation.shift(-permutation.from()) i.e.
 IPermutation shift(int offset)
          returns a new permutation with values shifted the specified offset.
 int size()
          size of permutation
 int to()
          get permutation ending value (to)
 String toString()
          override
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IPermutation

public IPermutation(Iterable<Integer> values)
new IPermutation from values. integer values should be contiguous and positive or null


IPermutation

public IPermutation(String s)
             throws NumberFormatException
new IPermutation from parsed String.

Throws:
NumberFormatException

IPermutation

public IPermutation(int from,
                    int to)
identity in [from, to]


IPermutation

public IPermutation(int range)
identity in [0, range-1]

Method Detail

iterator

public Iterator<Integer> iterator()
Specified by:
iterator in interface Iterable<Integer>

equals

public boolean equals(Object o)
override equals

Overrides:
equals in class Object

hashCode

public int hashCode()
override hashCode

Overrides:
hashCode in class Object

get

public int get(int indx)
return value at given index


lookup

public int lookup(int value)
get index of value return -1 if value is not found


size

public int size()
size of permutation


isIdentity

public boolean isIdentity()
check if permutation is identity in [0-n]


containsAll

public boolean containsAll(Iterable<Integer> set)
check if permutation contains the set of integers given as argument


from

public int from()
get permutation starting value (from)


to

public int to()
get permutation ending value (to)


shift

public IPermutation shift(int offset)
returns a new permutation with values shifted the specified offset. 'offset' may be negative but the starting value (from) of the resulting IPermutation should be >= 0


shift

public IPermutation shift()
same as permutation.shift(-permutation.from()) i.e. return a new IPermutation starting at 0. this function is usually used with apply when the initial IPermutation is not in the proper range [0, size-1]. permutation.shift().apply(List)


inverse

public IPermutation inverse()
returns a new IPermutation, inverse of this permutation


apply

public <T> List<T> apply(List<T> l)
apply permutation on list of objects. return a new list of same type retaining the elements of 'l' indexed by the current permutation [from, to]. the size of 'l' should therefore be strictly greater than 'to'. example: if permutation is p=[1,3,2] (i.e in range [1,3]) and l=(a, b, c, d, e) then p.apply(l)=(b, d, c)

Throws:
IllegalArgumentException - if l.size() < permutation.to()

toString

public String toString()
override

Overrides:
toString in class Object