From 5e45851e04a74ebe9b7065d127313d99177dc402 Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Sat, 8 Mar 2025 17:53:47 +0100 Subject: [PATCH] chore: Some minor changes --- pom.xml | 6 ------ src/main/java/cz/jzitnik/game/Game.java | 1 - .../cz/jzitnik/game/entities/MyOptional.java | 16 ++-------------- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 2a9bf26..0882215 100644 --- a/pom.xml +++ b/pom.xml @@ -128,12 +128,6 @@ slf4j-simple 2.0.17 - - - com.fasterxml.jackson.datatype - jackson-datatype-jdk8 - 2.15.0 - diff --git a/src/main/java/cz/jzitnik/game/Game.java b/src/main/java/cz/jzitnik/game/Game.java index dc3600c..280e109 100644 --- a/src/main/java/cz/jzitnik/game/Game.java +++ b/src/main/java/cz/jzitnik/game/Game.java @@ -1,6 +1,5 @@ package cz.jzitnik.game; -import com.fasterxml.jackson.annotation.JsonIgnore; import cz.jzitnik.game.entities.Block; import cz.jzitnik.game.entities.GameStates; import cz.jzitnik.game.entities.Player; diff --git a/src/main/java/cz/jzitnik/game/entities/MyOptional.java b/src/main/java/cz/jzitnik/game/entities/MyOptional.java index 3f74c8b..b82e529 100644 --- a/src/main/java/cz/jzitnik/game/entities/MyOptional.java +++ b/src/main/java/cz/jzitnik/game/entities/MyOptional.java @@ -5,11 +5,9 @@ import java.util.NoSuchElementException; import java.util.function.*; public class MyOptional implements Serializable { - private static final long serialVersionUID = 1L; private T value; private boolean isPresent; - // Constructor public MyOptional() { this.isPresent = false; } @@ -19,12 +17,10 @@ public class MyOptional implements Serializable { this.isPresent = true; } - // Check if value is present public boolean isPresent() { return isPresent; } - // Get the value (or throw exception if not present) public T get() { if (!isPresent) { throw new NoSuchElementException("No value present"); @@ -32,12 +28,10 @@ public class MyOptional implements Serializable { return value; } - // Get the value or return default public T orElse(T other) { return isPresent ? value : other; } - // If value is present, apply function, else return another Optional public MyOptional map(Function mapper) { if (!isPresent) { return new MyOptional<>(); @@ -45,7 +39,6 @@ public class MyOptional implements Serializable { return new MyOptional<>(mapper.apply(value)); } - // If value is present, apply function and return a new Optional public MyOptional flatMap(Function> mapper) { if (!isPresent) { return new MyOptional<>(); @@ -53,14 +46,12 @@ public class MyOptional implements Serializable { return mapper.apply(value); } - // Perform an action if value is present public void ifPresent(Consumer action) { if (isPresent) { action.accept(value); } } - // Return the value inside the Optional or default if not present public T orElseGet(Supplier other) { return isPresent ? value : other.get(); } @@ -73,7 +64,7 @@ public class MyOptional implements Serializable { return this; } - // Serialize the value + @Serial private void writeObject(ObjectOutputStream out) throws IOException { out.writeBoolean(isPresent); if (isPresent) { @@ -81,7 +72,7 @@ public class MyOptional implements Serializable { } } - // Deserialize the value + @Serial private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { isPresent = in.readBoolean(); if (isPresent) { @@ -94,17 +85,14 @@ public class MyOptional implements Serializable { return isPresent ? "SerializableOptional[" + value + "]" : "SerializableOptional.empty"; } - // Static factory method for an empty SerializableOptional public static MyOptional empty() { return new MyOptional<>(); } - // Static factory method for a present value public static MyOptional of(T value) { return new MyOptional<>(value); } - // Static factory method for a present value or null public static MyOptional ofNullable(T value) { return value == null ? empty() : new MyOptional<>(value); }