jenes.chromosome
Class GenericAlleleSet<T>

java.lang.Object
  extended by jenes.chromosome.GenericAlleleSet<T>
Type Parameters:
T -
All Implemented Interfaces:
AlleleSet<T>
Direct Known Subclasses:
DoubleAlleleSet, IntegerAlleleSet

public class GenericAlleleSet<T>
extends java.lang.Object
implements AlleleSet<T>

A GenericAlleleSet represents a concrete allele set implementation. It is usefull to instantiate a new AlleleSet when the allele values are contained by a list, by an array or by a Set. At creation time, the aplhabet objects are not cloned so:

Note that this implementation is not synchronized. If multiple threads access a GenericAlleleSet concurrently, and at least one of the threads modifies the set, it must be synchronized externally or wrapped using the Collections.synchronizedSet(Set) method.

Note that if values are modified externally, the allele set object also change according at that modification.

Some examples of code are provided below.

    Set s = Collections.synchronizedSet(new HashSet(...));
    GenericAlleleSet geneticAlleleSet = new GenericAlleleSet(s);
 
to build a generic allele set with the object value accesses synchronized.

    GenericAlleleSet generic alleleSet = new GenericAlleleSet(true, false),
 
to build a generic allele set with the boolean values as allele object values.

    GenericAlleleSet generic alleleSet = new GenericAlleleSet(AnyJavaEnum.values()) );
 
to build a generic allele set with the enum values.

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin
See Also:
ObjectChromosome

Constructor Summary
GenericAlleleSet(java.util.List<T> list)
          Creates a new AlleleSet instance with the alphabet values contained by the specified list
GenericAlleleSet(java.util.Set<T> set)
          Creates a new AlleleSet instance with the alphabet values contained by the specified set
GenericAlleleSet(T... values)
          Creates a new AlleleSet instance with the alphabet values contained by the specified array
 
Method Summary
 T getElementAt(int pos)
          Returns the allele at a given positition.
 T getRandomValue()
          Returns an allele randomly chosen.
 int size()
          Returns the number of alleles held by the allele set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericAlleleSet

public GenericAlleleSet(java.util.Set<T> set)
Creates a new AlleleSet instance with the alphabet values contained by the specified set

Parameters:
set - the set with the alphabet allele values

GenericAlleleSet

public GenericAlleleSet(T... values)
Creates a new AlleleSet instance with the alphabet values contained by the specified array

Parameters:
values - the alphabet values array

GenericAlleleSet

public GenericAlleleSet(java.util.List<T> list)
Creates a new AlleleSet instance with the alphabet values contained by the specified list

Parameters:
list - the alphabet values list
Method Detail

getElementAt

public final T getElementAt(int pos)
Returns the allele at a given positition.

Specified by:
getElementAt in interface AlleleSet<T>
Parameters:
pos -
Returns:
the element

getRandomValue

public final T getRandomValue()
Returns an allele randomly chosen.

Specified by:
getRandomValue in interface AlleleSet<T>
Returns:
a value

size

public final int size()
Returns the number of alleles held by the allele set.

Specified by:
size in interface AlleleSet<T>
Returns:
the number of alleles