Documentatie Team
This commit is contained in:
@@ -22,15 +22,34 @@ public class Team {
|
|||||||
// region changesTeam
|
// region changesTeam
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
public void addWormsToTeam(Worm... worm) {
|
/**
|
||||||
|
* @param worm
|
||||||
|
*
|
||||||
|
* @post ...
|
||||||
|
* |new.team = old.team + Worm... worm
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
*/
|
||||||
|
public void addWormsToTeam(Worm... worm) throws IllegalArgumentException {
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
if (canHaveAsWorm(w)) {
|
if (canHaveAsWorm(w)) {
|
||||||
team.add(w);
|
team.add(w);
|
||||||
sortList(team);
|
sortList(team);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param worm
|
||||||
|
*
|
||||||
|
* @return ...
|
||||||
|
* |for each i in [0,team.size()[
|
||||||
|
* | result == (worm.getMass() > getMinMassTeam()/2 && worm.getMass() < 2 * getMaxMassTeam()
|
||||||
|
* | && worm.isAlive() && (team.get(i)).getName() != worm.getName())
|
||||||
|
*/
|
||||||
public boolean canHaveAsWorm(Worm worm) {
|
public boolean canHaveAsWorm(Worm worm) {
|
||||||
if (worm.getMass() > getMinMassTeam()/2 && worm.getMass() < 2 * getMaxMassTeam()
|
if (worm.getMass() > getMinMassTeam()/2 && worm.getMass() < 2 * getMaxMassTeam()
|
||||||
&& worm.isAlive()) {
|
&& worm.isAlive()) {
|
||||||
@@ -43,17 +62,35 @@ public class Team {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sortList(ArrayList<Worm> list) {
|
/**
|
||||||
Collections.sort(list,
|
* @param team
|
||||||
|
*
|
||||||
|
* @post ...
|
||||||
|
* |
|
||||||
|
*/
|
||||||
|
public void sortList(ArrayList<Worm> team) {
|
||||||
|
Collections.sort(team,
|
||||||
(el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName()));
|
(el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param worm
|
||||||
|
*
|
||||||
|
* @post ...
|
||||||
|
* |(new.team).contains(Worm... worm) == false
|
||||||
|
*/
|
||||||
public void removeWormsFromTeam(Worm... worm) {
|
public void removeWormsFromTeam(Worm... worm) {
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
team.remove(w);
|
team.remove(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param worm
|
||||||
|
*
|
||||||
|
* @return ...
|
||||||
|
* |result == team.contains(worm)
|
||||||
|
*/
|
||||||
public boolean containsWorm(Worm worm) {
|
public boolean containsWorm(Worm worm) {
|
||||||
if (team.contains(worm)) {
|
if (team.contains(worm)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -65,6 +102,15 @@ public class Team {
|
|||||||
return team;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param recevingTeam
|
||||||
|
* @param supplyingTeam
|
||||||
|
*
|
||||||
|
* @post ... (NOG NIET ZEKER VAN)
|
||||||
|
* |recevingTeam == receivingTeam + supplyingTeam
|
||||||
|
* @post ...
|
||||||
|
* |supplyingTeam.isTerminated() == true
|
||||||
|
*/
|
||||||
public void mergeTeams(Team recevingTeam, Team supplyingTeam) {
|
public void mergeTeams(Team recevingTeam, Team supplyingTeam) {
|
||||||
for (int i = 0; i < (supplyingTeam.team).size(); i++) {
|
for (int i = 0; i < (supplyingTeam.team).size(); i++) {
|
||||||
addWormsToTeam((supplyingTeam.team).get(i));
|
addWormsToTeam((supplyingTeam.team).get(i));
|
||||||
@@ -80,32 +126,52 @@ public class Team {
|
|||||||
// region mass
|
// region mass
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ...
|
||||||
|
* |result == this.minMassTeam
|
||||||
|
*/
|
||||||
public double getMinMassTeam() {
|
public double getMinMassTeam() {
|
||||||
return this.minMassTeam;
|
return this.minMassTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @post ...
|
||||||
|
* |for each worm in team
|
||||||
|
* | if (minMassTeam > worm.getMass())
|
||||||
|
* | new.getMinMassTeam() == worm.getMass()
|
||||||
|
*/
|
||||||
public void setMinMassTeam() {
|
public void setMinMassTeam() {
|
||||||
for (int i = 0; i < team.size() - 1; i++) {
|
minMassTeam = (team.get(0)).getMass();
|
||||||
Worm wormA = team.get(i);
|
for (int i = 1; i < team.size() - 1; i++) {
|
||||||
Worm wormB = team.get(i+1);
|
Worm worm = team.get(i);
|
||||||
if (wormA.getMass() < wormB.getMass()) {
|
if (worm.getMass() < minMassTeam) {
|
||||||
minMassTeam = wormA.getMass();
|
minMassTeam = worm.getMass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double minMassTeam;
|
private double minMassTeam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ...
|
||||||
|
* |result == this.maxMassTeam
|
||||||
|
*/
|
||||||
public double getMaxMassTeam() {
|
public double getMaxMassTeam() {
|
||||||
return this.maxMassTeam;
|
return this.maxMassTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @post ...
|
||||||
|
* |for each worm in team
|
||||||
|
* | if (maxMassTeam < worm.getMass())
|
||||||
|
* | new.getMaxMassTeam() == worm.getMass()
|
||||||
|
*/
|
||||||
public void setMaxMassTeam() {
|
public void setMaxMassTeam() {
|
||||||
for (int i = 0; i < team.size() - 1; i++) {
|
maxMassTeam = (team.get(0)).getMass();
|
||||||
Worm wormA = team.get(i);
|
for (int i = 1; i < team.size() - 1; i++) {
|
||||||
Worm wormB = team.get(i+1);
|
Worm worm = team.get(i);
|
||||||
if (wormA.getMass() > wormB.getMass()) {
|
if (worm.getMass() > maxMassTeam) {
|
||||||
maxMassTeam = wormA.getMass();
|
minMassTeam = worm.getMass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,12 +184,24 @@ public class Team {
|
|||||||
// region name
|
// region name
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ...
|
||||||
|
* |result == this.name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return ...
|
||||||
|
* |for (i = 0; i < name.length(); i++)
|
||||||
|
* | result == (name.length() > 2 && Character.isUpperCase(name.charAt(0)
|
||||||
|
* | && Character.isLetter(name.charAt(i)) &&
|
||||||
|
* | allowedCharacters.indexOf(name.charAt(i)))
|
||||||
|
*/
|
||||||
public static int isValidName (String name) {
|
public static int isValidName (String name) {
|
||||||
|
|
||||||
if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) {
|
if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -138,7 +216,15 @@ public class Team {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @post |new.getName() == name
|
||||||
|
*
|
||||||
|
* @throws IllegalNameException
|
||||||
|
* |! isValidName(name)
|
||||||
|
*/
|
||||||
public void setName(String name) throws IllegalNameException {
|
public void setName(String name) throws IllegalNameException {
|
||||||
|
|
||||||
int validTeamName = isValidName(name);
|
int validTeamName = isValidName(name);
|
||||||
@@ -156,16 +242,34 @@ public class Team {
|
|||||||
// region terminate
|
// region terminate
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
//TODO region terminate
|
/**
|
||||||
|
* @param team
|
||||||
|
*
|
||||||
|
* @post ...
|
||||||
|
* |new.terminate == true
|
||||||
|
*/
|
||||||
public void terminate(Team team) {
|
public void terminate(Team team) {
|
||||||
|
terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param team
|
||||||
|
*
|
||||||
|
* @return ...
|
||||||
|
* |if terminate == true
|
||||||
|
* | result == true
|
||||||
|
* |else
|
||||||
|
* | result == false
|
||||||
|
*/
|
||||||
public boolean isTerminated(Team team) {
|
public boolean isTerminated(Team team) {
|
||||||
|
if (terminate == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean terminate = false;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
@@ -345,7 +345,6 @@ public class Worm {
|
|||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
private void setMass(double radius) {
|
private void setMass(double radius) {
|
||||||
|
|
||||||
final double rho = 1062.0;
|
final double rho = 1062.0;
|
||||||
double mass = round(rho * (4.0 / 3.0 * PI * pow(radius, 3)));
|
double mass = round(rho * (4.0 / 3.0 * PI * pow(radius, 3)));
|
||||||
this.mass = mass;
|
this.mass = mass;
|
||||||
@@ -522,7 +521,7 @@ public class Worm {
|
|||||||
* @param name
|
* @param name
|
||||||
* the new name for the worm
|
* the new name for the worm
|
||||||
* @post the new name of the worm is equal to the given name
|
* @post the new name of the worm is equal to the given name
|
||||||
* |new.GetName() == name
|
* |new.getName() == name
|
||||||
* @throws IllegalNameException
|
* @throws IllegalNameException
|
||||||
* the given name is not a valid name for any worm
|
* the given name is not a valid name for any worm
|
||||||
* |! isValidName(name)
|
* |! isValidName(name)
|
||||||
@@ -831,16 +830,22 @@ public class Worm {
|
|||||||
* terminate the worm
|
* terminate the worm
|
||||||
*/
|
*/
|
||||||
public void terminate() {
|
public void terminate() {
|
||||||
|
terminate = true;
|
||||||
|
setLocation(Coordinate.create(Double.NaN, Double.NaN));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAlive() {
|
||||||
|
if (terminate == false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean terminate = false;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
public boolean isAlive() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// region falling
|
// region falling
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user