From b0dfdaba160fb85bca0b11fcd7af4bb5065abc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Mon, 30 Sep 2024 18:51:55 +0300 Subject: [PATCH] getUnchecked. --- .../frame/typedkey/TypedKeyStorageImmutable.java | 3 +++ .../typedkey/TypedKeyStorageImmutableEmpty.java | 6 ++++++ .../frame/typedkey/TypedKeyStorageImmutableImpl.java | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutable.java b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutable.java index 33bc08a..3213f25 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutable.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutable.java @@ -13,6 +13,9 @@ public interface TypedKeyStorageImmutable { @Nullable Object get(@NotNull String key); + @Nullable + T getUnchecked(@NotNull String key); + boolean contains(@NotNull TypedKey key); @NotNull diff --git a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableEmpty.java b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableEmpty.java index 3502050..d0fbe52 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableEmpty.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableEmpty.java @@ -25,6 +25,12 @@ public Object get(@NotNull final String key) { return null; } + @Nullable + @Override + public T getUnchecked(@NotNull final String key) { + return null; + } + @Override public boolean contains(@NotNull final TypedKey key) { return false; diff --git a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableImpl.java b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableImpl.java index 0ed759b..4de2dc0 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableImpl.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableImpl.java @@ -33,6 +33,18 @@ public Object get(@NotNull final String key) { .orElse(null); } + @Nullable + @Override + @SuppressWarnings("unchecked") + public T getUnchecked(@NotNull final String key) { + return (T) this.map.keySet() + .stream() + .filter(k -> k.key().equals(key)) + .findFirst() + .map(this::get) + .orElse(null); + } + @Override public boolean contains(@NotNull final TypedKey key) { return this.map.containsKey(key);