diff options
Diffstat (limited to 'graphs/java/travel')
| -rw-r--r-- | graphs/java/travel/.gitignore | 38 | ||||
| -rw-r--r-- | graphs/java/travel/pom.xml | 138 | ||||
| -rw-r--r-- | graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java | 44 | ||||
| -rw-r--r-- | graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java | 13 | ||||
| -rw-r--r-- | graphs/java/travel/src/main/resources/travel_times.csv | 29 |
5 files changed, 262 insertions, 0 deletions
diff --git a/graphs/java/travel/.gitignore b/graphs/java/travel/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/graphs/java/travel/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store
\ No newline at end of file diff --git a/graphs/java/travel/pom.xml b/graphs/java/travel/pom.xml new file mode 100644 index 0000000..671d430 --- /dev/null +++ b/graphs/java/travel/pom.xml @@ -0,0 +1,138 @@ +<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>fr.epita.assistants</groupId> + <artifactId>travel</artifactId> + <version>1.0</version> + + <properties> + <versions.java>21</versions.java> + <versions.junit>5.9.1</versions.junit> + <versions.maven-compiler-plugin>3.13.0</versions.maven-compiler-plugin> + <versions.maven-surefire-plugin>3.5.0</versions.maven-surefire-plugin> + <versions.maven-jar-plugin>3.1.1</versions.maven-jar-plugin> + <versions.maven-install-plugin>3.1.0</versions.maven-install-plugin> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + + <surefire.reportsDirectory>${project.build.directory}/surefire-reports</surefire.reportsDirectory> + </properties> + + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>${versions.junit}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit-platform</artifactId> + <version>${versions.maven-surefire-plugin}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + <version>3.9.8</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>3.9.8</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>3.8.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-monitor</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>3.0.24</version> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-filtering</artifactId> + <version>3.3.2</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-interpolation</artifactId> + <version>1.13</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-profile</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact-manager</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-registry</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-repository-metadata</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>classworlds</groupId> + <artifactId>classworlds</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-commons</artifactId> + <version>1.9.3</version> + </dependency> + <dependency> + <groupId>com.opencsv</groupId> + <artifactId>opencsv</artifactId> + <version>4.1</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${versions.maven-compiler-plugin}</version> + <configuration> + <source>${versions.java}</source> + <target>${versions.java}</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <version>${versions.maven-install-plugin}</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${versions.maven-surefire-plugin}</version> + <configuration> + <reportsDirectory>${surefire.reportsDirectory}</reportsDirectory> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java new file mode 100644 index 0000000..e616e64 --- /dev/null +++ b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java @@ -0,0 +1,44 @@ +package fr.epita.assistants.travel; + +import com.opencsv.CSVReader; + +import java.io.FileReader; +import java.time.ZoneId; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class Country { + String countryName; + public Map<String, Integer> travelTimes; + ZoneId countryZone; + String filename; + + public Country(String countryName, String countryZone, String inputFilePath) { + this.countryName = countryName; + this.countryZone = ZoneId.of(countryZone); + this.filename = inputFilePath; + this.travelTimes = initTravelTimes(inputFilePath); + } + + public Map<String, Integer> initTravelTimes(String inputFilePath) { + Map<String, Integer> res = new HashMap<>(); + try { + CSVReader c = new CSVReader(new FileReader(inputFilePath)); + List<String[]> lines = c.readAll(); + lines.removeFirst(); + for (String[] line : lines) { + if (Objects.equals(line[0], this.countryName)) { + res.put(line[1], Integer.parseInt(line[2])); + } + else if (Objects.equals(line[1], this.countryName)) { + res.put(line[0], Integer.parseInt(line[2])); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return res; + } +} diff --git a/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java new file mode 100644 index 0000000..9302e18 --- /dev/null +++ b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java @@ -0,0 +1,13 @@ +package fr.epita.assistants.travel; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class Travel { + public static void travelTo(Country source, Country destination) { + ZonedDateTime t1 = ZonedDateTime.now(source.countryZone); + ZonedDateTime t2 = ZonedDateTime.now(destination.countryZone).plusHours(source.travelTimes.get(destination.countryName)); + System.out.println("Boarding in " + source.countryName + ", local date and time is: " + t1.format(DateTimeFormatter.RFC_1123_DATE_TIME)); + System.out.println("Landing in " + destination.countryName + ", local date and time on arrival will be: " + t2.format(DateTimeFormatter.RFC_1123_DATE_TIME)); + } +} diff --git a/graphs/java/travel/src/main/resources/travel_times.csv b/graphs/java/travel/src/main/resources/travel_times.csv new file mode 100644 index 0000000..a6b720b --- /dev/null +++ b/graphs/java/travel/src/main/resources/travel_times.csv @@ -0,0 +1,29 @@ +source,destination,travel_time +France,Italy,1 +France,England,2 +France,Vietnam,12 +France,Chicago,9 +France,Brazil,12 +France,Egypt,4 +France,Australia,24 +Italy,England,3 +Italy,Vietnam,11 +Italy,Chicago,9 +Italy,Brazil,12 +Italy,Egypt,3 +Italy,Australia,17 +England,Vietnam,12 +England,Chicago,11 +England,Brazil,12 +England,Egypt,5 +England,Australia,21 +Vietnam,Chicago,21 +Vietnam,Brazil,21 +Vietnam,Egypt,17 +Vietnam,Australia,6 +Chicago,Brazil,13 +Chicago,Egypt,13 +Chicago,Australia,21 +Brazil,Egypt,17 +Brazil,Australia,21 +Egypt,Australia,19
\ No newline at end of file |
