summaryrefslogtreecommitdiff
path: root/graphs/java/test2/src/main
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/java/test2/src/main
add: graphs et rushs
Diffstat (limited to 'graphs/java/test2/src/main')
-rw-r--r--graphs/java/test2/src/main/java/fr/epita/assistants/server/MyServer.java42
-rw-r--r--graphs/java/test2/src/main/java/fr/epita/assistants/test2/Test2.java48
2 files changed, 90 insertions, 0 deletions
diff --git a/graphs/java/test2/src/main/java/fr/epita/assistants/server/MyServer.java b/graphs/java/test2/src/main/java/fr/epita/assistants/server/MyServer.java
new file mode 100644
index 0000000..9a2a213
--- /dev/null
+++ b/graphs/java/test2/src/main/java/fr/epita/assistants/server/MyServer.java
@@ -0,0 +1,42 @@
+package fr.epita.assistants.server;
+
+import com.sun.net.httpserver.HttpServer;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+
+public class MyServer {
+
+ private static HttpServer server = null;
+ private static ExecutorService executor;
+
+
+ public static void launchServer() throws IOException {
+ server = HttpServer.create(new InetSocketAddress("localhost", 8080), 0);
+ executor = Executors.newFixedThreadPool(10);
+ server.setExecutor(executor);
+ var context = server.createContext("/");
+ context.setHandler((arg) -> {
+ try {
+ Thread.sleep(1500);
+ arg.sendResponseHeaders(HTTP_OK, 0);
+ arg.close();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ server.start();
+ }
+
+
+ public static void stopServer() {
+ if (server == null)
+ return;
+ server.stop(0);
+ executor.shutdownNow();
+ }
+}
diff --git a/graphs/java/test2/src/main/java/fr/epita/assistants/test2/Test2.java b/graphs/java/test2/src/main/java/fr/epita/assistants/test2/Test2.java
new file mode 100644
index 0000000..8427b43
--- /dev/null
+++ b/graphs/java/test2/src/main/java/fr/epita/assistants/test2/Test2.java
@@ -0,0 +1,48 @@
+package fr.epita.assistants.test2;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class Test2 {
+ /**
+ * Computes the nth value of the tribonacci suite.
+ * f(0) = 0, f(1) = 1, f(2) = 1, f(n+3) = f(n) + f(n+1) + f(n+2)
+ *
+ * @param n the nth sequence to compute
+ */
+ public static long tribonacci(int n) {
+ if (n < 0)
+ throw new IllegalArgumentException("Error: n must be positive");
+
+ if (n == 0)
+ return 0;
+ if (n < 3)
+ return 1;
+
+ long one = 0;
+ long two = 1;
+ long three = 1;
+ long res = 0;
+
+ for (long i = 3; i <= n; i++) {
+ res = one + two + three;
+ one = two;
+ two = three;
+ three = res;
+ }
+
+ return res;
+ }
+
+ public static long serverGetResponseCode() throws IOException {
+ URL url = new URL("http://localhost:8080/");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.setRequestMethod("GET");
+ return con.getResponseCode();
+ }
+
+ public static int division(int a, int b) {
+ return a / b;
+ }
+}