From b5a34b143eb70af3b1ad75c008a5492b00903561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Mon, 30 Sep 2024 18:54:33 +0300 Subject: [PATCH] remove empty. --- .../typedkey/TypedKeyStorageFactory.java | 3 - .../typedkey/TypedKeyStorageFactoryImpl.java | 6 -- .../typedkey/TypedKeyStorageImmutable.java | 9 +++ .../TypedKeyStorageImmutableEmpty.java | 64 ------------------- .../TypedKeyStorageImmutableImpl.java | 19 ++++++ 5 files changed, 28 insertions(+), 73 deletions(-) delete mode 100644 common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableEmpty.java diff --git a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactory.java b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactory.java index 69fb4b7..206ed10 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactory.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactory.java @@ -17,7 +17,4 @@ static TypedKeyStorageFactory create() { @NotNull TypedKeyStorageImmutableBuilder createImmutableBuilder(@NotNull Map, Object> base); - - @NotNull - TypedKeyStorageImmutable createImmutableEmpty(); } diff --git a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactoryImpl.java b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactoryImpl.java index 8c965f7..121c24e 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactoryImpl.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageFactoryImpl.java @@ -27,10 +27,4 @@ public TypedKeyStorageImmutableBuilder createImmutableBuilder( ) { return new TypedKeyStorageImmutableBuilderImpl(base); } - - @NotNull - @Override - public TypedKeyStorageImmutable createImmutableEmpty() { - return TypedKeyStorageImmutableEmpty.INSTANCE; - } } 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 3213f25..628bd2c 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutable.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutable.java @@ -16,6 +16,15 @@ public interface TypedKeyStorageImmutable { @Nullable T getUnchecked(@NotNull String key); + @NotNull + T getOrThrow(@NotNull TypedKey key); + + @NotNull + Object getOrThrow(@NotNull String key); + + @NotNull + T getUncheckedOrThrow(@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 deleted file mode 100644 index d0fbe52..0000000 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableEmpty.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.infumia.frame.typedkey; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.UnmodifiableView; - -final class TypedKeyStorageImmutableEmpty implements TypedKeyStorageImmutable { - - static final TypedKeyStorageImmutable INSTANCE = new TypedKeyStorageImmutableEmpty(); - - private TypedKeyStorageImmutableEmpty() {} - - @Nullable - @Override - public T get(@NotNull final TypedKey key) { - return null; - } - - @Nullable - @Override - 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; - } - - @NotNull - @Override - @UnmodifiableView - public Collection> keys() { - return Collections.emptySet(); - } - - @NotNull - @Override - @UnmodifiableView - public Collection values() { - return Collections.emptySet(); - } - - @NotNull - @Override - @UnmodifiableView - public Collection, Object>> entries() { - return Collections.emptySet(); - } - - @Override - public String toString() { - return "TypedKeyStorageImmutableEmpty{}"; - } -} 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 4de2dc0..b239569 100644 --- a/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableImpl.java +++ b/common/src/main/java/net/infumia/frame/typedkey/TypedKeyStorageImmutableImpl.java @@ -3,6 +3,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import net.infumia.frame.util.Preconditions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,6 +46,24 @@ public T getUnchecked(@NotNull final String key) { .orElse(null); } + @NotNull + @Override + public T getOrThrow(@NotNull final TypedKey key) { + return Preconditions.argumentNotNull(this.get(key), "Key '%s' not found!", key); + } + + @NotNull + @Override + public Object getOrThrow(@NotNull final String key) { + return Preconditions.argumentNotNull(this.get(key), "Key '%s' not found!", key); + } + + @NotNull + @Override + public T getUncheckedOrThrow(@NotNull final String key) { + return Preconditions.argumentNotNull(this.getUnchecked(key), "Key '%s' not found!", key); + } + @Override public boolean contains(@NotNull final TypedKey key) { return this.map.containsKey(key);