]> git.argeo.org Git - lgpl/argeo-commons.git/blob - NodeElementComparer.java
f284b9c1385b25762aa6f52120635d24a98a21ad
[lgpl/argeo-commons.git] / NodeElementComparer.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.eclipse.ui.jcr;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.ArgeoException;
22 import org.eclipse.jface.viewers.IElementComparer;
23
24 /** Element comparer for JCR node, to be used in JFace viewers. */
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 ArgeoException("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 ArgeoException("Cannot get hash code", e);
48 }
49 }
50
51 }