Documentatie Team (niet klaar)
This commit is contained in:
@@ -63,11 +63,17 @@ public class Team {
|
|||||||
*
|
*
|
||||||
* @param worms The worms to add.
|
* @param worms The worms to add.
|
||||||
*
|
*
|
||||||
* @post
|
* @post The team of each worm is set to the right team. Each worm is add to the wormCollection.
|
||||||
|
* |Collection<Worm> wormCollection = getAllWormsOfTeam()
|
||||||
|
* |Arrays.stream(worms).forEach(w -> {
|
||||||
|
* | w.setTeam(this);
|
||||||
|
* | wormCollection.add(w);
|
||||||
|
* |});
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException Given worm is null
|
* @throws IllegalArgumentException Given worms are null.
|
||||||
* |worms == null
|
* |worms == null
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException The worms aren't valid worms.
|
||||||
|
* |! canHaveAsWorm(worms)
|
||||||
*/
|
*/
|
||||||
public void addWorm(Worm... worms) throws IllegalArgumentException {
|
public void addWorm(Worm... worms) throws IllegalArgumentException {
|
||||||
if (worms == null) throw new IllegalArgumentException();
|
if (worms == null) throw new IllegalArgumentException();
|
||||||
@@ -81,27 +87,38 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Checks the correctness of the given worms.
|
||||||
* @param worm
|
*
|
||||||
*
|
* @param worms The worms to check.
|
||||||
* @return ...
|
*
|
||||||
* |if (worm.getMass() >= getMinMassTeam() / 2 && worm.getMass() <= 2 * getMinMassTeam() && !worm.isTerminated())
|
* @return Returns true if the given worm is a valid worm. The worm can not be null, the team of the worm can
|
||||||
* | for (Worm elWorm : worms)
|
* not be null, the name of the worm can not already be in the team, the team can not already contains the
|
||||||
* | if (! elWorm.getName().equals(worm.getName()))
|
* worm. If the size of the collection of all worms of a team is equal to 0 and the worm is not terminated,
|
||||||
* | result == true
|
* then continue with the next worm. Other conditions for the worm are: the mass can not be lower then the
|
||||||
* @throws IllegalArgumentException
|
* minimum mass of the team divided by 2 and can not be higher then 2 times the minimum mass of the team.
|
||||||
* ...
|
* the worm can als not be terminated.
|
||||||
* |worm == null
|
* |HashSet<String> names = new HashSet<>()
|
||||||
|
* |Collection<Worm> wormsOfTeam = getAllWormsOfTeam()
|
||||||
|
* |for (Worm w: worms)
|
||||||
|
* | if (w == null || w.getTeam() != null || !names.add(w.getName()))
|
||||||
|
* | result == false
|
||||||
|
* | if (wormsofTeam.contains(w))
|
||||||
|
* | result == false
|
||||||
|
* | if (wormsOfTeam.size() == 0 && !w.isTerminated())
|
||||||
|
* | continue
|
||||||
|
* | if (w.getMass() < getMinMassTeam() / 2 || w.getMass() > 2 * getMinMassTeam() || w.isTerminated())
|
||||||
|
* | result == false
|
||||||
|
* |result == true
|
||||||
*/
|
*/
|
||||||
private boolean canHaveAsWorm(Worm... worm) {
|
private boolean canHaveAsWorm(Worm... worms) {
|
||||||
|
|
||||||
HashSet<String> names = new HashSet<>();
|
HashSet<String> names = new HashSet<>();
|
||||||
Collection<Worm> worms = getAllWormsOfTeam();
|
Collection<Worm> wormsOfTeam = getAllWormsOfTeam();
|
||||||
|
|
||||||
for (Worm w : worm) {
|
for (Worm w : worms) {
|
||||||
if (w == null || w.getTeam() != null || !names.add(w.getName())) return false;
|
if (w == null || w.getTeam() != null || !names.add(w.getName())) return false;
|
||||||
if (worms.contains(w)) return false;
|
if (wormsOfTeam.contains(w)) return false;
|
||||||
if (worms.size() == 0 && !w.isTerminated()) continue;
|
if (wormsOfTeam.size() == 0 && !w.isTerminated()) continue;
|
||||||
if (w.getMass() < getMinMassTeam() / 2 || w.getMass() > 2 * getMinMassTeam()
|
if (w.getMass() < getMinMassTeam() / 2 || w.getMass() > 2 * getMinMassTeam()
|
||||||
|| w.isTerminated()) {
|
|| w.isTerminated()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -111,21 +128,21 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Removes given worms from a team.
|
||||||
|
*
|
||||||
|
* @param worm The worms who should be removed.
|
||||||
*
|
*
|
||||||
* @param worm
|
* @post All given worms are removed from the team and the team of the worm is set to null.
|
||||||
|
* |for (Worm w: worm)
|
||||||
|
* | getAllWormsOfTeam().remove(w)
|
||||||
|
* | w.setTeam(null)
|
||||||
*
|
*
|
||||||
* @post ...
|
* @throws IllegalArgumentException If the given worms are null or a worm is null or a worm is already in the team.
|
||||||
* |getAllwormsOfTeam().remove(worm)
|
* |worm == null || Arrays.stream(worm).anyMatch(w -> Objects.isNull(w) ||
|
||||||
* @post ...
|
* | !getAllWormsOfTeam().contains(w))
|
||||||
* |worm.setTeam(null)
|
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* ...
|
|
||||||
* |worm == null
|
|
||||||
*/
|
*/
|
||||||
public void removeWormsFromTeam(Worm... worm) throws IllegalArgumentException {
|
public void removeWormsFromTeam(Worm... worm) throws IllegalArgumentException {
|
||||||
|
|
||||||
|
|
||||||
if (worm == null || Arrays.stream(worm).anyMatch(w -> Objects.isNull(w) || !getAllWormsOfTeam().contains(w))) throw new IllegalArgumentException();
|
if (worm == null || Arrays.stream(worm).anyMatch(w -> Objects.isNull(w) || !getAllWormsOfTeam().contains(w))) throw new IllegalArgumentException();
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
getAllWormsOfTeam().remove(w);
|
getAllWormsOfTeam().remove(w);
|
||||||
@@ -134,15 +151,15 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Checks of the team contains the given worm.
|
||||||
|
*
|
||||||
|
* @param worm The worm to check.
|
||||||
*
|
*
|
||||||
* @param worm
|
* @return Returns true if the worm is in the team.
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
* |result == getAllWormsOfTeam().contains(worm)
|
* |result == getAllWormsOfTeam().contains(worm)
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException If the worm is equal to null.
|
||||||
* ...
|
* |worm == null
|
||||||
* |worm == null
|
|
||||||
*/
|
*/
|
||||||
public boolean containsWorm(Worm worm) throws IllegalArgumentException {
|
public boolean containsWorm(Worm worm) throws IllegalArgumentException {
|
||||||
if (worm == null) throw new IllegalArgumentException();
|
if (worm == null) throw new IllegalArgumentException();
|
||||||
@@ -150,38 +167,53 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Gives all the worms of the team.
|
||||||
* @return ...
|
*
|
||||||
* |wormCollection
|
* @return All the worms of the team in a Collection.
|
||||||
|
* |result == wormCollection
|
||||||
*/
|
*/
|
||||||
public Collection<Worm> getAllWormsOfTeam() {
|
public Collection<Worm> getAllWormsOfTeam() {
|
||||||
return wormCollection;
|
return wormCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives all the worms of the team.
|
||||||
|
*
|
||||||
|
* @return All the worms of the team in a List.
|
||||||
|
* |result == ArrayList<>(this.wormCollection)
|
||||||
|
*/
|
||||||
public List<Worm> getAllWormsList() {
|
public List<Worm> getAllWormsList() {
|
||||||
return new ArrayList<>(this.wormCollection);
|
return new ArrayList<>(this.wormCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Gives the number of worms in the team
|
||||||
* @return ...
|
*
|
||||||
* |getAllWormsOfTeam().size()
|
* @return The number of worms in the team.
|
||||||
|
* |result == getAllWormsOfTeam().size()
|
||||||
*/
|
*/
|
||||||
public int getNbWorms() {
|
public int getNbWorms() {
|
||||||
return getAllWormsOfTeam().size();
|
return getAllWormsOfTeam().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Puts two teams together.
|
||||||
|
*
|
||||||
|
* @param receivingTeam The team that gets the worms of another team.
|
||||||
|
* @param supplyingTeam The team that gives his worms to another team.
|
||||||
*
|
*
|
||||||
* @param receivingTeam
|
* @post the receivingTeam has his worms and the worms of the supplyingTeam.
|
||||||
* @param supplyingTeam
|
* |new.receivingTeam == old.receivingTeam.getAllWormsOfTeam() + supplyingTeam.getAllWormsOfTeam()
|
||||||
|
* @post the worms of supplyingTeam are removed from that team.
|
||||||
|
* |Worm[] supWorms = supplyingTeam.getAllWormsOfTeam().toArray(new Worm[0])
|
||||||
|
* |supplyingTeam.removeWormsFromTeam(supWorms)
|
||||||
*
|
*
|
||||||
* @post ...
|
* @throws IllegalArgumentException If the receivingTeam or the supplyingTeam is equal to null or the receivingTeam
|
||||||
* |receivingTeam.addWorm(supplyingTeam)
|
* equals the supplyingTeam or a worm of the supplyingTeam is also in the recei-
|
||||||
*
|
* vingTeam.
|
||||||
* @throws IllegalArgumentException
|
* |receivingTeam == null || supplyingTeam == null || receivingTeam.equals(supplyingTeam)
|
||||||
* ...
|
* | || supplyingTeam.getAllWormsOfTeam().stream().anyMatch(s ->
|
||||||
* |receivingTeam == null || supplyingTeam == null || receivingTeam.equals(supplyingTeam)
|
* |receivingTeam.getAllWormsOfTeam().contains(s))
|
||||||
*/
|
*/
|
||||||
public static void mergeTeams(Team receivingTeam, Team supplyingTeam) throws IllegalArgumentException {
|
public static void mergeTeams(Team receivingTeam, Team supplyingTeam) throws IllegalArgumentException {
|
||||||
|
|
||||||
@@ -195,9 +227,6 @@ public class Team {
|
|||||||
receivingTeam.addWorm(supWorms);
|
receivingTeam.addWorm(supWorms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private Collection<Worm> wormCollection;
|
private Collection<Worm> wormCollection;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
Reference in New Issue
Block a user