Skip to content

Commit

Permalink
DataMap: List type compatibility improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xDec0de committed Nov 2, 2024
1 parent ed447be commit 0c29fab
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions shared/src/main/java/net/codersky/mcutils/storage/DataMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Set<String> getKeys(@NotNull String parent) {
@SuppressWarnings("unchecked")
private <T> T getFromMap(@NotNull Map<?, ?> source, @NotNull String key, @NotNull Class<T> type) {
final Object obj = source.get(key);
return obj != null && obj.getClass().equals(type) ? (T) obj : null;
return obj != null && type.isAssignableFrom(obj.getClass()) ? (T) obj : null;
}

// - Objects - //
Expand All @@ -154,9 +154,12 @@ public <T> T get(@NotNull String key, T def) {
@Nullable
@SuppressWarnings("unchecked")
public <T> List<T> getList(@NotNull String key, @NotNull Class<T> type) {
final Object obj = get(key, Object.class);
if (obj instanceof LinkedList<?> lst)
return lst.getClass().getTypeParameters()[0].getClass().equals(type) ? (List<T>) lst : null;
final Object obj = get(key, List.class);
if (obj instanceof List<?> lst) {
if (lst.isEmpty())
return List.of();
return lst.getFirst().getClass().equals(type) ? (List<T>) lst : null;
}
return null;
}

Expand Down

0 comments on commit 0c29fab

Please sign in to comment.