Use generics for Chromosome type, begin unifying code

This commit is contained in:
mezz committed 2016-02-27 00:14:22 -08:00
1 parent a8270ef365
commit 43e41034f6
217 files changed
+3148 -2417

No files matched your search

@@ -5,7 +5,10 @@
******************************************************************************/
package forestry.api.genetics;
import java.util.ArrayList;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -20,7 +23,7 @@ import com.mojang.authlib.GameProfile;
/**
* Describes a class of species (i.e. bees, trees, butterflies), provides helper functions and access to common functionality.
*/
public interface ISpeciesRoot {
public interface ISpeciesRoot<C extends IChromosomeType> {
/**
* @return A unique identifier for the species class. Should consist of "root" + a common name for the species class in camel-case, i.e. "rootBees", "rootTrees", "rootButterflies".
@@ -30,7 +33,7 @@ public interface ISpeciesRoot {
/**
* @return Class of the sub-interface inheriting from {@link IIndividual}.
*/
Class<? extends IIndividual> getMemberClass();
Class<? extends IIndividual<C>> getMemberClass();
/**
* @return Integer denoting the number of (counted) species of this type in the world.
@@ -59,29 +62,38 @@ public interface ISpeciesRoot {
*/
boolean isMember(IIndividual individual);
IIndividual getMember(ItemStack stack);
@Nullable
IIndividual<C> getMember(ItemStack stack);
IIndividual getMember(NBTTagCompound compound);
@Nullable
IIndividual<C> getMember(NBTTagCompound compound);
@Nullable
ISpeciesType getType(ItemStack itemStack);
ItemStack getMemberStack(IIndividual individual, int type);
ItemStack getMemberStack(IIndividual<C> individual, int type);
/* BREEDING TRACKER */
IBreedingTracker getBreedingTracker(World world, GameProfile player);
@Nonnull
IBreedingTracker<C> getBreedingTracker(@Nonnull World world, @Nonnull GameProfile player);
/* GENOME MANIPULATION */
IIndividual templateAsIndividual(IAllele[] template);
@Nonnull
IIndividual<C> templateAsIndividual(ImmutableMap<C, IAllele> template);
IIndividual templateAsIndividual(IAllele[] templateActive, IAllele[] templateInactive);
@Nonnull
IIndividual<C> templateAsIndividual(ImmutableMap<C, IAllele> templateActive, ImmutableMap<C, IAllele> templateInactive);
IChromosome[] templateAsChromosomes(IAllele[] template);
ImmutableMap<C, IChromosome> templateAsChromosomes(ImmutableMap<C, IAllele> template);
IChromosome[] templateAsChromosomes(IAllele[] templateActive, IAllele[] templateInactive);
ImmutableMap<C, IChromosome> templateAsChromosomes(ImmutableMap<C, IAllele> templateActive, ImmutableMap<C, IAllele> templateInactive);
IGenome templateAsGenome(IAllele[] template);
IGenome<C> templateAsGenome(ImmutableMap<C, IAllele> template);
IGenome templateAsGenome(IAllele[] templateActive, IAllele[] templateInactive);
IGenome<C> templateAsGenome(ImmutableMap<C, IAllele> templateActive, ImmutableMap<C, IAllele> templateInactive);
@Nonnull
IGenome<C> chromosomesAsGenome(ImmutableMap<C, IChromosome> chromosomes);
/* TEMPLATES */
@@ -90,37 +102,38 @@ public interface ISpeciesRoot {
*
* @param template
*/
void registerTemplate(IAllele[] template);
void registerTemplate(ImmutableMap<C, IAllele> template);
/**
* Registers a bee template using the passed identifier.
*
* @param template
*/
void registerTemplate(String identifier, IAllele[] template);
void registerTemplate(String identifier, ImmutableMap<C, IAllele> template);
/**
* Retrieves a registered template using the passed identifier.
*
* @param identifier
* @return Array of {@link IAllele} representing a genome.
* @return Map of {@link IAllele} representing a genome.
*/
IAllele[] getTemplate(String identifier);
@Nullable
ImmutableMap<C, IAllele> getTemplate(String identifier);
/**
* @return Default individual template for use when stuff breaks.
*/
IAllele[] getDefaultTemplate();
ImmutableMap<C, IAllele> getDefaultTemplate();
/**
* @param rand Random to use.
* @return A random template from the pool of registered species templates.
*/
IAllele[] getRandomTemplate(Random rand);
ImmutableMap<C, IAllele> getRandomTemplate(Random rand);
Map<String, IAllele[]> getGenomeTemplates();
Map<String, ImmutableMap<C, IAllele>> getGenomeTemplates();
ArrayList<? extends IIndividual> getIndividualTemplates();
List<? extends IIndividual<C>> getIndividualTemplates();
/* MUTATIONS */
@@ -129,26 +142,26 @@ public interface ISpeciesRoot {
*
* @param mutation
*/
void registerMutation(IMutation mutation);
void registerMutation(IMutation<C> mutation);
/**
* @return All registered mutations.
*/
Collection<? extends IMutation> getMutations(boolean shuffle);
Collection<? extends IMutation<C>> getMutations(boolean shuffle);
/**
* @param other Allele to match mutations against.
* @return All registered mutations the given allele is part of.
*/
Collection<? extends IMutation> getCombinations(IAllele other);
List<IMutation<C>> getCombinations(IAllele other);
/**
* @since Forestry 3.7
* @return all possible mutations that result from breeding two species
*/
List<IMutation> getCombinations(IAlleleSpecies parentSpecies0, IAlleleSpecies parentSpecies1, boolean shuffle);
List<IMutation<C>> getCombinations(IAlleleSpecies<C> parentSpecies0, IAlleleSpecies<C> parentSpecies1, boolean shuffle);
Collection<? extends IMutation> getPaths(IAllele result, IChromosomeType chromosomeType);
Collection<? extends IMutation<C>> getPaths(IAllele result, C chromosomeType);
/* RESEARCH */
@@ -167,10 +180,29 @@ public interface ISpeciesRoot {
/**
* @return Array of {@link IChromosomeType} which are in this species genome
*/
IChromosomeType[] getKaryotype();
@Nonnull
C[] getKaryotype();
/**
* @return {@link IChromosomeType} which is the "key" for this species class, usually the species chromosome.
*/
IChromosomeType getKaryotypeKey();
@Nonnull
C getKaryotypeKey();
C getChromosomeTypeForUid(byte uid);
/* GAME MODE */
void resetMode();
@Nonnull
List<? extends ISpeciesMode<C>> getModes();
@Nonnull
ISpeciesMode<C> getMode(@Nonnull World world);
@Nonnull
ISpeciesMode<C> getMode(@Nonnull String name);
void setMode(@Nonnull World world, @Nonnull String name);
}