]> git.argeo.org Git - lgpl/argeo-commons.git/blob - NodeElementComparer.java
fc18965c6ec1eb3edac77845655e39879d0c7b30
[lgpl/argeo-commons.git] / NodeElementComparer.java
1 package org.argeo.eclipse.ui.jcr;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.argeo.ArgeoException;
7 import org.eclipse.jface.viewers.IElementComparer;
8
9 /** Element comparer for JCR node, to be used in JFace viewers. */
10 public class NodeElementComparer implements IElementComparer {
11
12 public boolean equals(Object a, Object b) {
13 try {
14 if ((a instanceof Node) && (b instanceof Node)) {
15 Node nodeA = (Node) a;
16 Node nodeB = (Node) b;
17 return nodeA.getIdentifier().equals(nodeB.getIdentifier());
18 } else {
19 return a.equals(b);
20 }
21 } catch (RepositoryException e) {
22 throw new ArgeoException("Cannot compare nodes", e);
23 }
24 }
25
26 public int hashCode(Object element) {
27 try {
28 if (element instanceof Node)
29 return ((Node) element).getIdentifier().hashCode();
30 return element.hashCode();
31 } catch (RepositoryException e) {
32 throw new ArgeoException("Cannot get hash code", e);
33 }
34 }
35
36 }