/** * @throws NullPointerException if the given gene array is {@code null}. */ @Override public CharacterChromosome newInstance(final ISeq<CharacterGene> genes) { return new CharacterChromosome(genes, lengthRange()); }
/** * Create a new chromosome with the {@code validCharacters} char set as * valid characters. * * @since 4.3 * * @param validCharacters the valid characters for this chromosome. * @param lengthRange the allowed length range of the chromosome. * @return a new {@code CharacterChromosome} with the given parameter * @throws NullPointerException if the {@code validCharacters} is * {@code null}. * @throws IllegalArgumentException if the length of the gene sequence is * empty, doesn't match with the allowed length range, the minimum * or maximum of the range is smaller or equal zero or the given * range size is zero. */ public static CharacterChromosome of( final CharSeq validCharacters, final IntRange lengthRange ) { return new CharacterChromosome( CharacterGene.seq(validCharacters, lengthRange), lengthRange ); }
@Override public CharacterChromosome subSequence(final int start, final int end) { return new CharacterChromosome(_genes.subSeq(start, end), lengthRange()); }
/** * Create a new chromosome from the given genes (given as string). * * @param alleles the character genes. * @param validChars the valid characters. * @return a new {@code CharacterChromosome} with the given parameter * @throws IllegalArgumentException if the genes string is empty. */ public static CharacterChromosome of( final String alleles, final CharSeq validChars ) { final IntRef index = new IntRef(); final Supplier<CharacterGene> geneFactory = () -> CharacterGene.of( alleles.charAt(index.value++), validChars ); final ISeq<CharacterGene> genes = MSeq.<CharacterGene>ofLength(alleles.length()) .fill(geneFactory) .toISeq(); return new CharacterChromosome(genes, IntRange.of(alleles.length())); }