blob: 2aca12762ea58c82cc50d1ee36d4330b70e73576 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*******************************************************************************
* Copyright (c) 2006, 2013 Wind River Systems, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.viewsupport.WorkingSetFilterUI;
public class CElementSet {
private Set<ICElement> fSet = new LinkedHashSet<ICElement>();
private int fHashCode;
CElementSet(ICElement[] elements) {
fSet.addAll(Arrays.asList(elements));
fHashCode = 0;
for (int i = 0; i < elements.length; i++) {
fHashCode = 31 * fHashCode + elements[i].hashCode();
}
}
@Override
public int hashCode() {
return fHashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final CElementSet other = (CElementSet) obj;
if (fHashCode != other.fHashCode) {
return false;
}
if (fSet == null) {
if (other.fSet != null) {
return false;
}
} else {
if (fSet.size() != other.fSet.size()) {
return false;
}
for (Iterator<ICElement> iter = fSet.iterator(); iter.hasNext();) {
if (!other.fSet.contains(iter.next())) {
return false;
}
}
}
return true;
}
public boolean isEmpty() {
return fSet.isEmpty();
}
public ICElement[] getElements(WorkingSetFilterUI filter) {
ArrayList<ICElement> result = new ArrayList<ICElement>(fSet.size());
for (Iterator<ICElement> iter = fSet.iterator(); iter.hasNext();) {
ICElement element = iter.next();
if (filter == null || filter.isPartOfWorkingSet(element)) {
result.add(element);
}
}
return result.toArray(new ICElement[result.size()]);
}
}
|