mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove ConcurrentSoftArrayHashMap
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-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 com.intellij.util.containers;
|
||||
|
||||
import com.intellij.reference.SoftReference;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class ConcurrentSoftArrayHashMap<T,V> implements Cloneable {
|
||||
private ConcurrentSoftHashMap<T, ConcurrentSoftArrayHashMap<T,V>> myContinuationMap;
|
||||
private ConcurrentSoftHashMap<T, SoftReference<V>> myValuesMap;
|
||||
private SoftReference<V> myValueForEmptyArray;
|
||||
private final TObjectHashingStrategy<T> myStrategy;
|
||||
|
||||
public ConcurrentSoftArrayHashMap() {
|
||||
this(ContainerUtil.<T>canonicalStrategy());
|
||||
}
|
||||
|
||||
public ConcurrentSoftArrayHashMap(@NotNull TObjectHashingStrategy<T> strategy) {
|
||||
myStrategy = strategy;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private V get(T[] array, int index) {
|
||||
if (index == array.length - 1) {
|
||||
final ConcurrentSoftHashMap<T, SoftReference<V>> valuesMap = myValuesMap;
|
||||
if (valuesMap != null) {
|
||||
final SoftReference<V> softReference = valuesMap.get(array[index]);
|
||||
if (softReference != null) {
|
||||
return softReference.get();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final ConcurrentSoftHashMap<T, ConcurrentSoftArrayHashMap<T, V>> continuationMap = myContinuationMap;
|
||||
if (continuationMap != null) {
|
||||
final ConcurrentSoftArrayHashMap<T, V> map = continuationMap.get(array[index]);
|
||||
if (map != null) {
|
||||
return map.get(array, index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final V get(T[] key) {
|
||||
if (key.length == 0) {
|
||||
final SoftReference<V> emptyValue = myValueForEmptyArray;
|
||||
return emptyValue == null ? null : emptyValue.get();
|
||||
}
|
||||
return get(key, 0);
|
||||
}
|
||||
|
||||
private void put(T[] array, int index, V value) {
|
||||
final T key = array[index];
|
||||
if (index == array.length - 1) {
|
||||
if (myValuesMap == null) {
|
||||
myValuesMap = new ConcurrentSoftHashMap<T, SoftReference<V>>(myStrategy);
|
||||
}
|
||||
myValuesMap.put(key, new SoftReference<V>(value));
|
||||
} else {
|
||||
if (myContinuationMap == null) {
|
||||
myContinuationMap = new ConcurrentSoftHashMap<T, ConcurrentSoftArrayHashMap<T,V>>(myStrategy);
|
||||
}
|
||||
ConcurrentSoftArrayHashMap<T, V> softArrayHashMap = myContinuationMap.get(key);
|
||||
if (softArrayHashMap == null) {
|
||||
myContinuationMap.put(key, softArrayHashMap = new ConcurrentSoftArrayHashMap<T, V>(myStrategy));
|
||||
}
|
||||
softArrayHashMap.put(array, index + 1, value);
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized void put(T[] key, V value) {
|
||||
if (key.length == 0) {
|
||||
myValueForEmptyArray = new SoftReference<V>(value);
|
||||
}
|
||||
else {
|
||||
put(key, 0, value);
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized void clear() {
|
||||
myContinuationMap = null;
|
||||
myValuesMap = null;
|
||||
myValueForEmptyArray = null;
|
||||
}
|
||||
|
||||
public final boolean containsKey(final T[] path) {
|
||||
return get(path) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final synchronized ConcurrentSoftArrayHashMap<T,V> clone() {
|
||||
final ConcurrentSoftArrayHashMap<T, V> copy = new ConcurrentSoftArrayHashMap<T, V>(myStrategy);
|
||||
copy.myContinuationMap = copyMap(myContinuationMap);
|
||||
copy.myValuesMap = copyMap(myValuesMap);
|
||||
copy.myValueForEmptyArray = myValueForEmptyArray;
|
||||
return copy;
|
||||
}
|
||||
|
||||
private <X> ConcurrentSoftHashMap<T, X> copyMap(final ConcurrentSoftHashMap<T, X> map) {
|
||||
final ConcurrentSoftHashMap<T, X> copy = new ConcurrentSoftHashMap<T, X>();
|
||||
for (final Map.Entry<T, X> entry : map.entrySet()) {
|
||||
copy.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import com.intellij.util.ReflectionCache;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
import com.intellij.util.containers.ConcurrentSoftArrayHashMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import com.intellij.util.xml.impl.DomInvocationHandler;
|
||||
import com.intellij.util.xml.impl.DomManagerImpl;
|
||||
@@ -27,12 +25,6 @@ import java.util.*;
|
||||
* @author peter
|
||||
*/
|
||||
public class ModelMergerImpl implements ModelMerger {
|
||||
// [greg] the key should actually be the MergingStrategy class, but this will break the API
|
||||
private final ConcurrentFactoryMap<Class, ConcurrentSoftArrayHashMap<Object, Object>> myMergedMap = new ConcurrentFactoryMap<Class, ConcurrentSoftArrayHashMap<Object, Object>>() {
|
||||
protected ConcurrentSoftArrayHashMap<Object, Object> create(final Class key) {
|
||||
return new ConcurrentSoftArrayHashMap<Object, Object>(ContainerUtil.identityStrategy());
|
||||
}
|
||||
};
|
||||
private final List<Pair<InvocationStrategy,Class>> myInvocationStrategies = new ArrayList<Pair<InvocationStrategy,Class>>();
|
||||
private final List<MergingStrategy> myMergingStrategies = new ArrayList<MergingStrategy>();
|
||||
private final List<Class> myMergingStrategyClasses = new ArrayList<Class>();
|
||||
@@ -195,10 +187,6 @@ public class ModelMergerImpl implements ModelMerger {
|
||||
}
|
||||
|
||||
public <T> T mergeModels(final Class<T> aClass, final T... implementations) {
|
||||
/*final Object o = myMergedMap.get(aClass).get(implementations);
|
||||
if (o != null) {
|
||||
return (T)o;
|
||||
}*/
|
||||
if (implementations.length == 1) return implementations[0];
|
||||
final MergingInvocationHandler<T> handler = new MergingInvocationHandler<T>(aClass, Arrays.asList(implementations));
|
||||
return _mergeModels(aClass, handler, implementations);
|
||||
@@ -214,7 +202,6 @@ public class ModelMergerImpl implements ModelMerger {
|
||||
commonClasses.add(MERGED_OBJECT_CLASS);
|
||||
commonClasses.add(aClass);
|
||||
final T t = AdvancedProxy.<T>createProxy(handler, null, commonClasses.toArray(new Class[commonClasses.size()]));
|
||||
//myMergedMap.get(aClass).put(implementations, t);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user