Skip to content

Commit

Permalink
getUnchecked.
Browse files Browse the repository at this point in the history
  • Loading branch information
portlek committed Sep 30, 2024
1 parent 9872e5c commit b0dfdab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public interface TypedKeyStorageImmutable {
@Nullable
Object get(@NotNull String key);

@Nullable
<T> T getUnchecked(@NotNull String key);

boolean contains(@NotNull TypedKey<?> key);

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public Object get(@NotNull final String key) {
return null;
}

@Nullable
@Override
public <T> T getUnchecked(@NotNull final String key) {
return null;
}

@Override
public boolean contains(@NotNull final TypedKey<?> key) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public Object get(@NotNull final String key) {
.orElse(null);
}

@Nullable
@Override
@SuppressWarnings("unchecked")
public <T> 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);
Expand Down

0 comments on commit b0dfdab

Please sign in to comment.