diff --git a/core/util.runtime/src/org/jetbrains/jet/utils/NotNullMemoizedFunction.java b/core/util.runtime/src/org/jetbrains/jet/utils/NotNullMemoizedFunction.java deleted file mode 100644 index a15accdf723..00000000000 --- a/core/util.runtime/src/org/jetbrains/jet/utils/NotNullMemoizedFunction.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.utils; - -import com.intellij.util.NotNullFunction; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public abstract class NotNullMemoizedFunction extends NullableMemoizedFunction implements NotNullFunction { - - public static NotNullFunction create(@NotNull final NotNullFunction compute) { - return new NotNullMemoizedFunction() { - @NotNull - @Override - protected V compute(@NotNull K input) { - return compute.fun(input); - } - }; - } - - public NotNullMemoizedFunction(@NotNull Map map) { - super(map); - } - - public NotNullMemoizedFunction() { - super(); - } - - @NotNull - @Override - public V fun(@NotNull K input) { - //noinspection ConstantConditions - return super.fun(input); - } - - @NotNull - @Override - protected abstract V compute(@NotNull K input); -} diff --git a/core/util.runtime/src/org/jetbrains/jet/utils/NullableMemoizedFunction.java b/core/util.runtime/src/org/jetbrains/jet/utils/NullableMemoizedFunction.java deleted file mode 100644 index 867944d6ced..00000000000 --- a/core/util.runtime/src/org/jetbrains/jet/utils/NullableMemoizedFunction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.utils; - -import com.intellij.util.Function; -import com.intellij.util.NullableFunction; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; - -public abstract class NullableMemoizedFunction implements NullableFunction { - - public static NullableFunction create(@NotNull final Function compute) { - return new NullableMemoizedFunction() { - @Nullable - @Override - protected V compute(@NotNull K input) { - return compute.fun(input); - } - }; - } - - private final Map cache; - - public NullableMemoizedFunction(@NotNull Map map) { - this.cache = map; - } - - public NullableMemoizedFunction() { - this(new HashMap()); - } - - @Override - @Nullable - public V fun(@NotNull K input) { - Object value = cache.get(input); - if (value != null) return WrappedValues.unescapeNull(value); - - V typedValue = compute(input); - - Object oldValue = cache.put(input, WrappedValues.escapeNull(typedValue)); - assert oldValue == null : "Race condition detected"; - - return typedValue; - } - - @Nullable - protected abstract V compute(@NotNull K input); -}