Added SlicedMap.getSliceContents() method returning immutable map for particular slice.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user