();
- private final TIntHashSet myKeysToRemove = new TIntHashSet();
- private final TIntProcedure myRemoveEntriesProcedure = new TIntProcedure() {
- @Override
- public boolean execute(int value) {
- myMap.remove(value);
- return true;
- }
- };
-
- /**
- * Asks for the value stored for the given key if any.
- *
- * @param key target key
- * @return value mapped for the given key if any; null otherwise
- */
- @Nullable
- public T get(int key) {
- return myMap.get(key);
- }
-
- /**
- * Stores mapping between the given key and value.
- *
- * @param key target key
- * @param value target value
- */
- public void put(int key, @NotNull T value) {
- myMap.put(key, value);
- myKeysToRemove.remove(key);
- }
-
- /**
- * Marks all entries of the given map that belongs to the [start; end] interval for further removal (triggered by
- * call to {@link #deleteMarked()}).
- *
- * @param start target key's interval start (inclusive)
- * @param end target key's interval end (inclusive)
- */
- public void markForDeletion(int start, int end) {
- for (int i = start; i <= end; i++) {
- if (myMap.containsKey(i)) {
- myKeysToRemove.add(i);
- }
- }
- }
-
- /**
- * Asks current map to remove all keys that were marked during {@link #markForDeletion(int, int)}.
- *
- * Note: following actions sequence is possible:
- *
- *
- * -
- * {@link #put(int, Object)} is called for entries with keys, say,
'1', '2' and '3';
- *
- * -
- * {@link #markForDeletion(int, int)} is called with range
[2; 3];
- *
- * -
- * {@link #put(int, Object)} is called for key
'2';
- *
- * -
- * {@link #deleteMarked()} is called;
- *
- *
- *
- * Entry with key '2' is not removed on {@link #deleteMarked()} processing then because it was updated after
- * {@link #markForDeletion(int, int)}.
- */
- public void deleteMarked() {
- myKeysToRemove.forEach(myRemoveEntriesProcedure);
- }
-
- /**
- * Asks current map to drop all entries which keys are greater or equal to the given one.
- *
- * @param key target start key
- */
- public void deleteFrom(final int key) {
- myMap.retainEntries(new TIntObjectProcedure() {
- @Override
- public boolean execute(int a, T b) {
- if (a >= key) {
- myKeysToRemove.remove(a);
- return false;
- }
- return true;
- }
- });
- }
-
- /**
- * Asks current map to clear its state.
- */
- public void clear() {
- myMap.clear();
- myKeysToRemove.clear();
- }
-
- public int size() {
- return myMap.size();
- }
-}
diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/DelayedRemovalMapTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/DelayedRemovalMapTest.java
deleted file mode 100644
index e807ee7d38ad..000000000000
--- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/DelayedRemovalMapTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2000-2010 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 com.intellij.openapi.editor.impl.softwrap.mapping;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-/**
- * @author Denis Zhdanov
- * @since 11/15/10 11:08 AM
- */
-public class DelayedRemovalMapTest {
-
- private DelayedRemovalMap myMap;
-
- @Before
- public void setUp() {
- myMap = new DelayedRemovalMap();
- }
-
- @Test
- public void delayedRemoval() {
- myMap.put(1, 1);
- myMap.put(2, 1);
- myMap.put(3, 1);
- myMap.put(4, 1);
- myMap.markForDeletion(2, 3);
- myMap.deleteMarked();
-
- assertEquals(2, myMap.size());
- assertNotNull(myMap.get(1));
- assertNull(myMap.get(2));
- assertNull(myMap.get(3));
- assertNotNull(myMap.get(4));
- }
-
- @Test
- public void delayedRemovalDoesntAffectNewlyStoredMappings() {
- myMap.put(1, 1);
- myMap.put(2, 1);
- myMap.markForDeletion(1, 2);
- myMap.put(2, 1);
- myMap.deleteMarked();
-
- assertEquals(1, myMap.size());
- assertNull(myMap.get(1));
- assertNotNull(myMap.get(2));
- }
-}