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 gnu
.trove
.THashMap
;
19 import gnu
.trove
.TObjectHashingStrategy
;
25 */ // rehash map on each PSI modification since SmartPsiPointer's hashCode() and equals() are changed
27 private final Map
<SliceUsage
, SliceNode
> myDuplicates
= new THashMap
<SliceUsage
, SliceNode
>(USAGEINFO_EQUALITY
);
28 private static final TObjectHashingStrategy
<SliceUsage
> USAGEINFO_EQUALITY
= new TObjectHashingStrategy
<SliceUsage
>() {
29 public int computeHashCode(SliceUsage object
) {
30 return object
.getUsageInfo().hashCode();
33 public boolean equals(SliceUsage o1
, SliceUsage o2
) {
34 return o1
.getUsageInfo().equals(o2
.getUsageInfo());
37 private static final TObjectHashingStrategy
<SliceNode
> SLICE_NODE_EQUALITY
= new TObjectHashingStrategy
<SliceNode
>() {
38 public int computeHashCode(SliceNode object
) {
39 return object
.getValue().getUsageInfo().hashCode();
42 public boolean equals(SliceNode o1
, SliceNode o2
) {
43 return o1
.getValue().getUsageInfo().equals(o2
.getValue().getUsageInfo());
47 public SliceNode
putNodeCheckDupe(SliceNode node
) {
48 SliceUsage usage
= node
.getValue();
49 SliceNode eq
= myDuplicates
.get(usage
);
51 myDuplicates
.put(usage
, node
);