From 702fb399c38b3d9c0f044bca61fb85718461f7bb Mon Sep 17 00:00:00 2001 From: flavien Date: Tue, 24 Mar 2020 12:11:06 +0100 Subject: [PATCH] return testport in method --- src/tools/TestPort.java | 11 +++++++---- src/tracker/Tracker.java | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/tools/TestPort.java b/src/tools/TestPort.java index 9f5e351..8a31892 100644 --- a/src/tools/TestPort.java +++ b/src/tools/TestPort.java @@ -1,5 +1,7 @@ package tools; +import javafx.util.Pair; + /** Test ports. * @author Louis Royer * @author Flavien Haas @@ -8,18 +10,19 @@ package tools; */ public class TestPort { - public boolean testPortServer(int port) { + public boolean testPortServer(int port, String message) { if((port > 7000) && (port < 7999)){ return true; } + message = message + "Wrong port (7000 -> 7999), using default port 7070"; return false; } - public boolean testPortTracker(int port) { + public Pair testPortTracker(int port) { if((port > 6000) && (port < 6999)){ - return true; + return new Pair<>(0,""); } - return false; + return new Pair<>(1, "Wrong port (6000 -> 6999), using default port 6969"); } diff --git a/src/tracker/Tracker.java b/src/tracker/Tracker.java index b81a671..53658e1 100644 --- a/src/tracker/Tracker.java +++ b/src/tracker/Tracker.java @@ -1,6 +1,7 @@ package tracker; import java.util.Scanner; +import javafx.util.Pair; import tracker.TrackerManagementTCP; import tracker.TrackerManagementUDP; import tools.Directories; @@ -42,7 +43,7 @@ public class Tracker { final String defaultPort = "6969"; final String defaultHostname = "localhost"; Scanner scanner = new Scanner(System.in); - TestPort testPortTracker = new TestPort(); + TestPort testPort = new TestPort(); String hostname; String port; Tracker t; @@ -73,14 +74,15 @@ public class Tracker { } System.out.println("using hostname : " + hostname); - if(testPortTracker.testPortTracker(Integer.parseInt(port))){ + Pair PtestPortTracker = testPort.testPortTracker(Integer.parseInt(port)); + if(PtestPortTracker.getKey() == 0){ System.out.println("using port : " + port); t = new Tracker(port); } else { - System.out.println("Wrong port (6000 -> 6999), using default port 6969"); + System.out.println(PtestPortTracker.getValue()); t = new Tracker(defaultPort); - t.logger.write("Wrong port (6000 -> 6999), using default port 6969", LogLevel.Warning); + t.logger.write(PtestPortTracker.getValue(), LogLevel.Warning); } TrackerManagementUDP tmudp = new TrackerManagementUDP(hostname, t.port, t.logger);