org.expasy.jpl.commons.base.math
Class MixedRadixNtupleFactory

java.lang.Object
  extended by org.expasy.jpl.commons.base.math.MixedRadixNtupleFactory
All Implemented Interfaces:
org.apache.commons.collections15.Transformer<int[],List<int[]>>

public final class MixedRadixNtupleFactory
extends Object
implements org.apache.commons.collections15.Transformer<int[],List<int[]>>

This class generates generalized n-tuples.

Version:
1.0
Author:
nikitin

Nested Class Summary
static class MixedRadixNtupleFactory.BadRadixException
           
 
Method Summary
static long computeTupleNumber(int[] radices)
          Compute the number of all the t-uples given the radices.
static int[] convertDecimal2Tuple(int code, int radix)
          Convert decimal to t-uple of given radix.
static int[] convertDecimal2Tuple(int radix, int code, int size)
          Convert decimal to t-uple of given radix.
static int[] convertString2Tuple(String tuple)
          Convert string to t-uple.
static int convertTuple2Decimal(int[] tuple, int radix)
          Convert a tuple from radix to radix 10 (decimal).
static MixedRadixNtupleFactory newInstance()
          Generate all tuples considering the given strict limits (excluded).
static MixedRadixNtupleFactory newInstance(int limit)
           
static String toString(List<int[]> ntuples)
          A simple string converter for n-tuples.
 List<int[]> transform(int[] radices)
          This algorithm generate all n-tuples where each ai have different upper limit li.
 List<int[]> transform(int n, int radix)
          This algorithm generate all n-tuples with same radix for any positions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static MixedRadixNtupleFactory newInstance()
Generate all tuples considering the given strict limits (excluded).

Returns:
the list of tuples from [0, ..., 0] to [l0-1, ..., ln-1]

newInstance

public static MixedRadixNtupleFactory newInstance(int limit)

computeTupleNumber

public static long computeTupleNumber(int[] radices)
Compute the number of all the t-uples given the radices.

Parameters:
radices - the radices by position.
Returns:
the total number of t-uples.

convertTuple2Decimal

public static int convertTuple2Decimal(int[] tuple,
                                       int radix)
                                throws MixedRadixNtupleFactory.BadRadixException
Convert a tuple from radix to radix 10 (decimal).

Parameters:
radix - the fixed radix (max Character.MAX_RADIX).
tuple - the tuple to compute the code from.
Returns:
the code for the given tuple.
Throws:
MixedRadixNtupleFactory.BadRadixException - if radix is > Character.MAX_RADIX.

convertDecimal2Tuple

public static int[] convertDecimal2Tuple(int code,
                                         int radix)
                                  throws MixedRadixNtupleFactory.BadRadixException
Convert decimal to t-uple of given radix.

Parameters:
radix - the fixed radix (max 36)
code - the code to compute the tuple from
Returns:
the tuple for the given code
Throws:
MixedRadixNtupleFactory.BadRadixException - if radix > 36

convertDecimal2Tuple

public static int[] convertDecimal2Tuple(int radix,
                                         int code,
                                         int size)
                                  throws MixedRadixNtupleFactory.BadRadixException
Convert decimal to t-uple of given radix.

Parameters:
radix - the fixed radix (max 36)
code - the code to compute the tuple from
size - the size of the returned tuple rq: if size > tuple then add '0' else truncate.
Returns:
the tuple for the given code
Throws:
MixedRadixNtupleFactory.BadRadixException - if radix > 36

convertString2Tuple

public static int[] convertString2Tuple(String tuple)
Convert string to t-uple.

Parameters:
tuple - the string to convert.
Returns:
a t-uple.

transform

public List<int[]> transform(int n,
                             int radix)
This algorithm generate all n-tuples with same radix for any positions.

Parameters:
n - the number of digits.
radix - the radix for each digit.
Returns:
t-uples.

transform

public List<int[]> transform(int[] radices)
This algorithm generate all n-tuples where each ai have different upper limit li. [from knuth the AOCP, section 7.1.1 : Algorithm M]

Specified by:
transform in interface org.apache.commons.collections15.Transformer<int[],List<int[]>>
Parameters:
radices - the limits [l0, ..., ln] such as ai in [0, li[.
Returns:
t-uples.

toString

public static String toString(List<int[]> ntuples)
A simple string converter for n-tuples.

Parameters:
ntuples - the n-tuples to convert.
Returns:
a string representation of n-tuples.


Copyright (c) 2012 Swiss Institute of Bioinformatics. All rights reserved.