/** * Create a new character gene from the given character. If the character * is not within the {@link #DEFAULT_CHARACTERS}, an invalid gene will be * created. * * @param character the character value of the created gene. * @return a new character gene. */ public static CharacterGene of(final char character) { return new CharacterGene(character, DEFAULT_CHARACTERS); }
/** * Create a new CharacterGene from the give character. * * @param character The allele. * @param validCharacters the valid characters fo the new gene * @return a new {@code CharacterGene} with the given parameter * @throws NullPointerException if one of the arguments is {@code null}. * @throws IllegalArgumentException if the {@code validCharacters} are empty. */ public static CharacterGene of( final char character, final CharSeq validCharacters ) { return new CharacterGene(character, validCharacters); }
/** * Create a new character gene from the given character. If the character * is not within the {@link #DEFAULT_CHARACTERS}, an invalid gene will be * created. * * @param character the character value of the created gene. * @return a new character gene. * @throws NullPointerException if the given {@code character} is * {@code null}. * * @deprecated Use {@link #of(char)} instead */ @Deprecated public static CharacterGene of(final Character character) { return new CharacterGene(character, DEFAULT_CHARACTERS); }
/** * Create a new random character gene, chosen from the * {@link #DEFAULT_CHARACTERS}. * * @return a new random character gene. */ public static CharacterGene of() { return new CharacterGene( DEFAULT_CHARACTERS, RandomRegistry.getRandom().nextInt(DEFAULT_CHARACTERS.length()) ); }
/** * Create a new CharacterGene with a randomly chosen character from the * set of valid characters. * * @param validCharacters the valid characters for this gene. * @return a new valid, <em>random</em> gene, * @throws NullPointerException if the {@code validCharacters} are * {@code null}. */ public static CharacterGene of(final CharSeq validCharacters) { return new CharacterGene( validCharacters, RandomRegistry.getRandom().nextInt(validCharacters.length()) ); }
static ISeq<CharacterGene> seq( final CharSeq chars, final IntRange lengthRange ) { final Random r = RandomRegistry.getRandom(); return MSeq.<CharacterGene>ofLength(random.nextInt(lengthRange, r)) .fill(() -> new CharacterGene(chars, r.nextInt(chars.length()))) .toISeq(); }