Added SlicedMap.getSliceContents() method returning immutable map for particular slice.

This commit is contained in:
Evgeny Gerashchenko
2012-09-15 21:19:53 +04:00
parent 694f1f45f8
commit 84c10c1623
2 changed files with 22 additions and 0 deletions
@@ -16,6 +16,10 @@
package org.jetbrains.jet.util.slicedmap;
import com.google.common.collect.ImmutableMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
/**
* @author abreslav
*/
@@ -26,4 +30,8 @@ public interface MutableSlicedMap extends SlicedMap {
<K, V> V remove(RemovableSlice<K, V> slice, K key);
void clear();
@NotNull
@TestOnly
<K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice);
}
@@ -16,9 +16,11 @@
package org.jetbrains.jet.util.slicedmap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.util.CommonSuppliers;
import java.util.Collection;
@@ -106,4 +108,16 @@ public class SlicedMapImpl implements MutableSlicedMap {
//noinspection unchecked
return (Iterator) map.entrySet().iterator();
}
@NotNull
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
for (Map.Entry<SlicedMapKey<?, ?>, ?> entry : map.entrySet()) {
if (entry.getKey().getSlice() == slice) {
builder.put((K) entry.getKey().getKey(), (V) entry.getValue());
}
}
return builder.build();
}
}