Skip to content

Commit

Permalink
Make dynamic maps return empty immutable collections instead of throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Jan 12, 2024
1 parent 6fa3e64 commit 03e7df5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Expand Up @@ -2,8 +2,11 @@

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.ints.IntSets;
import it.unimi.dsi.fastutil.objects.ObjectCollection;
import it.unimi.dsi.fastutil.objects.ObjectLists;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import it.unimi.dsi.fastutil.objects.ObjectSets;

import java.util.Map;
import java.util.function.Function;
Expand All @@ -15,17 +18,17 @@ public DynamicInt2ObjectMap(Function<Integer, V> function) {

@Override
public IntSet keySet() {
throw new UnsupportedOperationException();
return IntSets.EMPTY_SET;
}

@Override
public ObjectCollection<V> values() {
throw new UnsupportedOperationException();
return ObjectLists.emptyList();
}

@Override
public ObjectSet<Map.Entry<Integer, V>> entrySet() {
throw new UnsupportedOperationException();
return ObjectSets.emptySet();
}

@Override
Expand Down
Expand Up @@ -4,6 +4,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
Expand Down Expand Up @@ -64,18 +65,18 @@ public void clear() {
@NotNull
@Override
public Set<K> keySet() {
throw new UnsupportedOperationException();
return Collections.emptySet();
}

@NotNull
@Override
public Collection<V> values() {
throw new UnsupportedOperationException();
return Collections.emptyList();
}

@NotNull
@Override
public Set<Entry<K, V>> entrySet() {
throw new UnsupportedOperationException();
return Collections.emptySet();
}
}

0 comments on commit 03e7df5

Please sign in to comment.