Skip to content
Snippets Groups Projects
Commit 30051c40 authored by Carl Gützkow's avatar Carl Gützkow :computer: Committed by Eilert Werner Hansen
Browse files

enhance(main...k1g4): added exception throwing

parent 4dede1f2
No related branches found
No related tags found
No related merge requests found
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
##############################
## IntelliJ
##############################
out/
.idea/*
*.iml
*.ipr
*.iws
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
##############################
## IntelliJ
##############################
out/
.idea/*
*.iml
*.ipr
*.iws
image: maven:eclipse-temurin
build:
stage: build
script:
- mvn compile
test:
stage: test
script:
- mvn clean test
image: maven:eclipse-temurin
build:
stage: build
script:
- mvn compile
test:
stage: test
script:
- mvn clean test
## What are the key features of this change
### Size of change: (small/medium/big)
## List changes with class/type-of-changes
Ex: (delete this)
- class1/method-field
- class2/field-test-coupling
## Checklist
- [ ] Javadoc
- [ ] Tests
- [ ] Build tool test passed
## What are the key features of this change
### Size of change: (small/medium/big)
## List changes with class/type-of-changes
Ex: (delete this)
- class1/method-field
- class2/field-test-coupling
## Checklist
- [ ] Javadoc
- [ ] Tests
- [ ] Build tool test passed
MIT License
Copyright (c) 2022 Brage Halvorsen Kvamme, Carl Johan Gützkow, Callum Gran, Eilert Werner Hansen, Nicolai Hollup Brand, Runar Indahl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2022 Brage Halvorsen Kvamme, Carl Johan Gützkow, Callum Gran, Eilert Werner Hansen, Nicolai Hollup Brand, Runar Indahl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.ntnu.idatt1002.k1g4</groupId>
<artifactId>tournament-service</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.8.1</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.demo/com.example.demo.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.ntnu.idatt1002.k1g4</groupId>
<artifactId>tournament-service</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.8.1</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.demo/com.example.demo.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package edu.ntnu.idatt1002.k1g4;
import edu.ntnu.idatt1002.k1g4.enums.MatchType;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
......@@ -34,12 +33,16 @@ class Match {
* @param isWalkover Defines if the match is a walkover.
* @param matchType Defines what type of match is being played.
*/
public Match(Team team1, Team team2, List referees, LocalDateTime startTime, LocalDateTime endTime, int fieldNumber, boolean isWalkover, MatchType matchType) {
this.teams = new Team[]{team1, team2};
public Match(Team team1, Team team2, List referees, int fieldNumber, boolean isWalkover, MatchType matchType) {
this.teams = new Team[2];
this.teams[0] = team1;
this.teams[1] = team2;
this.referees = referees;
this.score = new int[]{0, 0};
this.startTime = startTime;
this.endTime = endTime;
this.score = new int[2];
this.score[0] = 0;
this.score[1] = 0;
this.startTime = LocalDateTime.now();
this.endTime = startTime.plusMinutes(30); //Vet ikke hvor lang kampene skal være
this.fieldNumber = fieldNumber;
this.isFinished = false;
this.isWalkover = isWalkover;
......
......@@ -9,6 +9,7 @@ import java.util.Objects;
* @Author Callum Gran
*/
public class Team {
private final int id;
private final String name;
private final List members;
......@@ -23,6 +24,8 @@ public class Team {
* @param isCompeting status of if the team is competing
*/
public Team(int id, String name, List members, boolean isCompeting) {
if (name.isBlank()) throw new IllegalArgumentException("Team needs a name");
if (id < 0) throw new IllegalArgumentException("Id should be positive");
this.id = id;
this.name = name;
this.members = members;
......@@ -76,12 +79,19 @@ public class Team {
@Override
public String toString() {
return "Team{" +
"id=" + id +
", name='" + name + '\'' +
", members=" + members +
", isCompeting=" + isCompeting +
'}';
return (
"Team{" +
"id=" +
id +
", name='" +
name +
'\'' +
", members=" +
members +
", isCompeting=" +
isCompeting +
'}'
);
}
@Override
......@@ -89,7 +99,12 @@ public class Team {
if (this == o) return true;
if (!(o instanceof Team)) return false;
Team team = (Team) o;
return id == team.id && isCompeting == team.isCompeting && Objects.equals(name, team.name) && Objects.equals(members, team.members);
return (
id == team.id &&
isCompeting == team.isCompeting &&
Objects.equals(name, team.name) &&
Objects.equals(members, team.members)
);
}
@Override
......
......@@ -5,6 +5,7 @@ package edu.ntnu.idatt1002.k1g4.people;
* @author Nicolai Brand
*/
public class Admin extends Person {
boolean hasAdminRights;
/**
......
package edu.ntnu.idatt1002.k1g4.people;
import edu.ntnu.idatt1002.k1g4.enums.Sex;
import java.time.LocalDate;
import java.util.Objects;
......@@ -11,6 +10,7 @@ import java.util.Objects;
* @Author Callum Gran
*/
public class Competitor extends Person {
private final LocalDate birthDate;
private final Sex sex;
private int competingNumber;
......@@ -28,9 +28,18 @@ public class Competitor extends Person {
* @param isPenalized if the competitor is penalized
* @throws IllegalArgumentException the illegal argument exception
*/
public Competitor(String name, LocalDate birthDate, Sex sex, int competingNumber, boolean hasLicense, boolean isPenalized) throws IllegalArgumentException {
public Competitor(
String name,
LocalDate birthDate,
Sex sex,
int competingNumber,
boolean hasLicense,
boolean isPenalized
) throws IllegalArgumentException {
super(name);
if (birthDate.isAfter(LocalDate.now())) throw new IllegalArgumentException("The birthday of a player must be before now.");
if (birthDate.isAfter(LocalDate.now())) throw new IllegalArgumentException(
"The birthday of a player must be before now."
);
this.birthDate = birthDate;
this.sex = sex;
this.competingNumber = competingNumber;
......@@ -115,7 +124,13 @@ public class Competitor extends Person {
if (this == o) return true;
if (!(o instanceof Competitor)) return false;
Competitor that = (Competitor) o;
return competingNumber == that.competingNumber && hasLicense == that.hasLicense && isPenalized == that.isPenalized && Objects.equals(birthDate, that.birthDate) && sex == that.sex;
return (
competingNumber == that.competingNumber &&
hasLicense == that.hasLicense &&
isPenalized == that.isPenalized &&
Objects.equals(birthDate, that.birthDate) &&
sex == that.sex
);
}
@Override
......
......@@ -7,7 +7,8 @@ package edu.ntnu.idatt1002.k1g4.people;
* @Author Callum Gran
* @Version 1.0-SNAPSHOT
*/
abstract public class Person {
public abstract class Person {
private final int id;
private final String name;
private static int totalIds = 0;
......
......@@ -5,6 +5,7 @@ package edu.ntnu.idatt1002.k1g4.people;
* @author Nicolai Brand
*/
public class Referee extends Person {
boolean hasLicense;
/**
......
......@@ -2,16 +2,15 @@ package edu.ntnu.idatt1002.k1g4.test;
import static org.junit.jupiter.api.Assertions.*;
import edu.ntnu.idatt1002.k1g4.enums.Sex;
import edu.ntnu.idatt1002.k1g4.people.Competitor;
import edu.ntnu.idatt1002.k1g4.people.Person;
import edu.ntnu.idatt1002.k1g4.enums.Sex;
import java.time.LocalDate;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
public class PersonTest {
@Nested
class PersonConstructorThrowsException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment