diff options
author | Pacien TRAN-GIRARD | 2016-05-10 20:31:10 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-05-10 20:31:10 +0200 |
commit | 26458eafb530582b744929e6b03b0042c977f7cd (patch) | |
tree | 45659b8003d4a7773c48092bd9cd17a2306f8394 /src/ch/epfl | |
parent | 7d9c28e25d5b0965171f4b347852a11fdf01482e (diff) | |
download | xblast-26458eafb530582b744929e6b03b0042c977f7cd.tar.gz |
Create entry points structures
Diffstat (limited to 'src/ch/epfl')
-rw-r--r-- | src/ch/epfl/xblast/ArgumentChecker.java | 29 | ||||
-rw-r--r-- | src/ch/epfl/xblast/client/Client.java | 30 | ||||
-rw-r--r-- | src/ch/epfl/xblast/client/Main.java | 23 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Main.java | 24 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Server.java | 30 |
5 files changed, 136 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/ArgumentChecker.java b/src/ch/epfl/xblast/ArgumentChecker.java index 7e77b61..56f8acd 100644 --- a/src/ch/epfl/xblast/ArgumentChecker.java +++ b/src/ch/epfl/xblast/ArgumentChecker.java | |||
@@ -59,4 +59,33 @@ public final class ArgumentChecker { | |||
59 | return s; | 59 | return s; |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | ||
63 | * Returns the element from the array at the requested index, or null if it cannot be retrieved. | ||
64 | * | ||
65 | * @param array the array | ||
66 | * @param index the index | ||
67 | * @param <T> the type of element | ||
68 | * @return the requested element, or null | ||
69 | */ | ||
70 | public static <T> T getOrNull(T[] array, int index) { | ||
71 | if (Objects.isNull(array) || index < 0 || index >= array.length) | ||
72 | return null; | ||
73 | else | ||
74 | return array[index]; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Parses and returns an integer, or return null on error. | ||
79 | * | ||
80 | * @param str the integer to parse | ||
81 | * @return the parsed integer, or null | ||
82 | */ | ||
83 | public static Integer parseIntOrNull(String str) { | ||
84 | try { | ||
85 | return Integer.parseInt(str); | ||
86 | } catch (NumberFormatException | NullPointerException e) { | ||
87 | return null; | ||
88 | } | ||
89 | } | ||
90 | |||
62 | } | 91 | } |
diff --git a/src/ch/epfl/xblast/client/Client.java b/src/ch/epfl/xblast/client/Client.java new file mode 100644 index 0000000..dc08f1b --- /dev/null +++ b/src/ch/epfl/xblast/client/Client.java | |||
@@ -0,0 +1,30 @@ | |||
1 | package ch.epfl.xblast.client; | ||
2 | |||
3 | import ch.epfl.xblast.server.Server; | ||
4 | |||
5 | import java.net.InetSocketAddress; | ||
6 | import java.util.Optional; | ||
7 | |||
8 | /** | ||
9 | * The Client class. | ||
10 | * | ||
11 | * @author Pacien TRAN-GIRARD (261948) | ||
12 | */ | ||
13 | public class Client { | ||
14 | |||
15 | private static final String DEFAULT_SERVER_HOST = "localhost"; | ||
16 | private static final int DEFAULT_SERVER_PORT = Server.DEFAULT_PORT; | ||
17 | |||
18 | private final InetSocketAddress serverAddr; | ||
19 | |||
20 | public Client(String host, Integer port) { | ||
21 | this.serverAddr = new InetSocketAddress( | ||
22 | Optional.ofNullable(host).orElse(DEFAULT_SERVER_HOST), | ||
23 | Optional.ofNullable(port).orElse(DEFAULT_SERVER_PORT)); | ||
24 | } | ||
25 | |||
26 | public void run() { | ||
27 | // TODO | ||
28 | } | ||
29 | |||
30 | } | ||
diff --git a/src/ch/epfl/xblast/client/Main.java b/src/ch/epfl/xblast/client/Main.java new file mode 100644 index 0000000..19145c5 --- /dev/null +++ b/src/ch/epfl/xblast/client/Main.java | |||
@@ -0,0 +1,23 @@ | |||
1 | package ch.epfl.xblast.client; | ||
2 | |||
3 | import ch.epfl.xblast.ArgumentChecker; | ||
4 | |||
5 | /** | ||
6 | * Entry point class of the client. | ||
7 | * | ||
8 | * @author Pacien TRAN-GIRARD (261948) | ||
9 | */ | ||
10 | public final class Main { | ||
11 | |||
12 | private Main() { | ||
13 | // Static class | ||
14 | } | ||
15 | |||
16 | public static void main(String[] args) { | ||
17 | String host = ArgumentChecker.getOrNull(args, 0); | ||
18 | Integer port = ArgumentChecker.parseIntOrNull(ArgumentChecker.getOrNull(args, 1)); | ||
19 | |||
20 | (new Client(host, port)).run(); | ||
21 | } | ||
22 | |||
23 | } | ||
diff --git a/src/ch/epfl/xblast/server/Main.java b/src/ch/epfl/xblast/server/Main.java new file mode 100644 index 0000000..98bbb3d --- /dev/null +++ b/src/ch/epfl/xblast/server/Main.java | |||
@@ -0,0 +1,24 @@ | |||
1 | package ch.epfl.xblast.server; | ||
2 | |||
3 | import ch.epfl.xblast.ArgumentChecker; | ||
4 | |||
5 | /** | ||
6 | * Entry point class of the server. | ||
7 | * | ||
8 | * @author Pacien TRAN-GIRARD (261948) | ||
9 | */ | ||
10 | public final class Main { | ||
11 | |||
12 | private Main() { | ||
13 | // Static class | ||
14 | } | ||
15 | |||
16 | public static void main(String[] args) { | ||
17 | Integer expectedClients = ArgumentChecker.parseIntOrNull(ArgumentChecker.getOrNull(args, 0)); | ||
18 | String iface = ArgumentChecker.getOrNull(args, 1); | ||
19 | Integer port = ArgumentChecker.parseIntOrNull(ArgumentChecker.getOrNull(args, 2)); | ||
20 | |||
21 | (new Server(iface, port, expectedClients)).run(); | ||
22 | } | ||
23 | |||
24 | } | ||
diff --git a/src/ch/epfl/xblast/server/Server.java b/src/ch/epfl/xblast/server/Server.java new file mode 100644 index 0000000..76f332e --- /dev/null +++ b/src/ch/epfl/xblast/server/Server.java | |||
@@ -0,0 +1,30 @@ | |||
1 | package ch.epfl.xblast.server; | ||
2 | |||
3 | import ch.epfl.xblast.PlayerID; | ||
4 | |||
5 | import java.net.InetSocketAddress; | ||
6 | import java.util.Optional; | ||
7 | |||
8 | /** | ||
9 | * The Server class. | ||
10 | * | ||
11 | * @author Pacien TRAN-GIRARD (261948) | ||
12 | */ | ||
13 | public class Server { | ||
14 | |||
15 | public static final int DEFAULT_PORT = 2016; | ||
16 | public static final int DEFAULT_EXPECTED_CLIENTS = PlayerID.values().length; | ||
17 | |||
18 | private final InetSocketAddress iface; | ||
19 | private final int expectedClients; | ||
20 | |||
21 | public Server(String iface, Integer port, Integer expectedClients) { | ||
22 | this.iface = new InetSocketAddress(iface, Optional.ofNullable(port).orElse(DEFAULT_PORT)); | ||
23 | this.expectedClients = Optional.ofNullable(expectedClients).orElse(DEFAULT_EXPECTED_CLIENTS); | ||
24 | } | ||
25 | |||
26 | public void run() { | ||
27 | // TODO | ||
28 | } | ||
29 | |||
30 | } | ||