problem 17183
[fedora-idea.git] / java / java-impl / src / com / intellij / slicer / DuplicateMap.java
blob77b49f79f4cc51ba09146c44330f7a515e20b8d6
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.slicer;
18 import com.intellij.usageView.UsageInfo;
19 import gnu.trove.THashMap;
20 import gnu.trove.TObjectHashingStrategy;
22 import java.util.Map;
24 /**
25 * @author cdr
26 */ // rehash map on each PSI modification since SmartPsiPointer's hashCode() and equals() are changed
27 class DuplicateMap {
28 private static final TObjectHashingStrategy<SliceUsage> USAGEINFO_EQUALITY = new TObjectHashingStrategy<SliceUsage>() {
29 public int computeHashCode(SliceUsage object) {
30 UsageInfo info = object.getUsageInfo();
31 return info.startOffset + info.endOffset * 31;
34 public boolean equals(SliceUsage o1, SliceUsage o2) {
35 return o1.getUsageInfo().equals(o2.getUsageInfo());
38 private final Map<SliceUsage, SliceNode> myDuplicates = new THashMap<SliceUsage, SliceNode>(USAGEINFO_EQUALITY);
40 public SliceNode putNodeCheckDupe(SliceNode node) {
41 SliceUsage usage = node.getValue();
42 SliceNode eq = myDuplicates.get(usage);
43 if (eq == null) {
44 myDuplicates.put(usage, node);
46 return eq;
49 public void clear() {
50 myDuplicates.clear();