package be.shoktan.BeeBreedingManager.model;

import java.util.Collection;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

/**
 * Model class to represent a collection of bees
 * @author Wisthy
 *
 */
public class BeeCollection extends ANamedEntity{
	@ManyToOne
	private User owner;
	
	@ManyToOne
	private Modpack modpack;
	
	@ManyToMany
	private SortedSet<Specie> ownedSpecies;
	
	
	
	// ********** getters & setters ********** //
	
	/**
	 * @return the owner
	 */
	public User getOwner() {
		return owner;
	}

	/**
	 * @param owner the owner to set
	 */
	public void setOwner(User owner) {
		this.owner = owner;
	}

	/**
	 * @return the modpack
	 */
	public Modpack getModpack() {
		return modpack;
	}

	/**
	 * @param modpack the modpack to set
	 */
	public void setModpack(Modpack modpack) {
		this.modpack = modpack;
	}

	/**
	 * @return the ownedSpecies
	 */
	public Collection<Specie> getOwnedSpecies() {
		return ownedSpecies;
	}

	/**
	 * @param ownedSpecies the ownedSpecies to set
	 */
	public void setOwnedSpecies(SortedSet<Specie> ownedSpecies) {
		this.ownedSpecies = ownedSpecies;
	}
	
	
	// ********** others ********** //
	
	/**
	 * do the initialization of the ownedSpecies set if necessary
	 */
	private void initOwnedSpecies(){
		if(this.ownedSpecies == null){
			this.ownedSpecies = new TreeSet<>();
		}
	}
	
	/**
	 * add the specie to the set of owned species
	 * @param specie the specie to add
	 * @return true if the specie has been added, false elsewhere
	 */
	public boolean addSpecie(Specie specie){
		initOwnedSpecies();
		return this.ownedSpecies.add(specie);
	}
}

@@ -1,12 +1,24 @@
+/**%0A * %0A */%0A
 package be.s
@@ -1679,10 +1679,542 @@
 ie);%0A%09%7D%0A
+%09%0A%09%0A%09public Collection%3CSpecie%3E available()%7B%0A%09%09Collection%3CSpecie%3E result = new TreeSet%3C%3E();%0A%09%09initOwnedSpecies();%0A%09%09%0A%09%09for(Specie first : this.ownedSpecies)%7B%0A%09%09%09result.add(first);%0A%09%09%09for(Specie second : this.ownedSpecies)%7B%0A%09%09%09%09if(second == null %7C%7C second.compareTo(first) %3C 0)%7B%0A%09%09%09%09%09continue;%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09if(second.compareTo(first) %3E 0)%7B%0A%09%09%09%09%09result.add(second);%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09Collection%3CSpecie%3E childs = first.mutationResultWith(second);%0A%09%09%09%09if(childs != null)%7B%0A%09%09%09%09%09result.addAll(childs);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09return result;%0A%09%7D%0A
 %7D%0A

Update BeeCollection.java