Delete RemovableSlice and MutableSlicedMap.remove

This commit is contained in:
Alexander Udalov
2015-07-28 18:52:16 +03:00
parent 96ded4d5d2
commit ae277a0ad7
5 changed files with 9 additions and 77 deletions
@@ -24,8 +24,6 @@ public interface MutableSlicedMap extends SlicedMap {
<K, V> void put(WritableSlice<K, V> slice, K key, V value);
<K, V> V remove(RemovableSlice<K, V> slice, K key);
void clear();
@NotNull
@@ -1,21 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.util.slicedMap;
public interface RemovableSlice<K, V> extends WritableSlice<K, V> {
}
@@ -99,24 +99,6 @@ public class SlicedMapImpl implements MutableSlicedMap {
return (Collection<K>) collectiveSliceKeys.get(slice);
}
@Override
public <K, V> V remove(RemovableSlice<K, V> slice, K key) {
UserDataHolderImpl holder = map.get(key);
if (holder == null) return null;
Key<V> sliceKey = slice.getKey();
V value = holder.getUserData(sliceKey);
holder.putUserData(sliceKey, null);
if (holder.isUserDataEmpty()) {
map.remove(key);
}
return value;
}
@Override
public void forEach(@NotNull Function3<WritableSlice, Object, Object, Void> f) {
for (Map.Entry<Object, UserDataHolderImpl> entry : map.entrySet()) {
@@ -86,17 +86,17 @@ public class Slices {
return this;
}
public RemovableSlice<K, V> build() {
BasicRemovableSlice<K, V> result = doBuild();
public WritableSlice<K, V> build() {
BasicWritableSlice<K, V> result = doBuild();
if (debugName != null) {
result.setDebugName(debugName);
}
return result;
}
private BasicRemovableSlice<K, V> doBuild() {
private BasicWritableSlice<K, V> doBuild() {
if (furtherLookupSlices != null) {
return new BasicRemovableSlice<K, V>(rewritePolicy) {
return new BasicWritableSlice<K, V>(rewritePolicy) {
@Override
public V computeValue(SlicedMap map, K key, V value, boolean valueNotFound) {
if (valueNotFound) {
@@ -112,21 +112,11 @@ public class Slices {
}
};
}
return new BasicRemovableSlice<K, V>(rewritePolicy);
return new BasicWritableSlice<K, V>(rewritePolicy);
}
}
public static class BasicRemovableSlice<K, V> extends BasicWritableSlice<K, V> implements RemovableSlice<K, V> {
protected BasicRemovableSlice(RewritePolicy rewritePolicy) {
super(rewritePolicy);
}
protected BasicRemovableSlice(RewritePolicy rewritePolicy, boolean isCollective) {
super(rewritePolicy, isCollective);
}
}
public static class SetSlice<K> extends BasicRemovableSlice<K, Boolean> {
public static class SetSlice<K> extends BasicWritableSlice<K, Boolean> {
protected SetSlice(RewritePolicy rewritePolicy) {
this(rewritePolicy, false);
@@ -16,11 +16,9 @@
package org.jetbrains.kotlin.util.slicedMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import kotlin.jvm.functions.Function3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.utils.Printer;
import java.util.Collection;
@@ -70,23 +68,6 @@ public class TrackingSlicedMap extends SlicedMapImpl {
super.put(wrapSlice(slice), key, new TrackableValue<V>(value, trackWithStackTraces));
}
@Override
public <K, V> V remove(RemovableSlice<K, V> slice, K key) {
return super.remove(wrapSlice(slice), key).value;
}
@Override
public void clear() {
super.clear();
}
@Override
@NotNull
@TestOnly
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
return super.getSliceContents(slice);
}
private static class TrackableValue<V> {
private final static StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
@@ -136,7 +117,9 @@ public class TrackingSlicedMap extends SlicedMapImpl {
}
}
private class SliceWithStackTrace<K, V> extends AbstractWritableSlice<K, TrackableValue<V>> implements RemovableSlice<K, TrackableValue<V>> {
private class SliceWithStackTrace<K, V>
extends AbstractWritableSlice<K, TrackableValue<V>>
implements WritableSlice<K, TrackableValue<V>> {
private final ReadOnlySlice<K, V> delegate;