1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.eclipse.ui.jcr;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.eclipse.ui.EclipseUiException;
22 import org.eclipse.jface.viewers.IElementComparer;
23
24
25 public class NodeElementComparer implements IElementComparer {
26
27 public boolean equals(Object a, Object b) {
28 try {
29 if ((a instanceof Node) && (b instanceof Node)) {
30 Node nodeA = (Node) a;
31 Node nodeB = (Node) b;
32 return nodeA.getIdentifier().equals(nodeB.getIdentifier());
33 } else {
34 return a.equals(b);
35 }
36 } catch (RepositoryException e) {
37 throw new EclipseUiException("Cannot compare nodes", e);
38 }
39 }
40
41 public int hashCode(Object element) {
42 try {
43 if (element instanceof Node)
44 return ((Node) element).getIdentifier().hashCode();
45 return element.hashCode();
46 } catch (RepositoryException e) {
47 throw new EclipseUiException("Cannot get hash code", e);
48 }
49 }
50
51 }