]>
git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/utils/NameVersionComparator.java
1 package org
.argeo
.slc
.client
.ui
.dist
.utils
;
3 import org
.argeo
.eclipse
.ui
.TreeParent
;
4 import org
.eclipse
.jface
.viewers
.Viewer
;
5 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
8 * Enable comparison of two names version string with form org.argeo.slc-1.2.x.
9 * with following rules and assumptions:
12 * Names are ordered using Lexicographical order</li>
14 * Version are parsed and compared segment by segment; doing best effort to
15 * convert major, minor and micro to integer and compare them as such (to have
16 * 0.1 < 0.9 < 0.10 not 0.1 < 0.10 < 0.9).</li>
17 * <li>Version should not contain any dash (-), version segments should be
18 * separated by dots (.)</li>
22 public class NameVersionComparator
extends ViewerComparator
{
23 private static final long serialVersionUID
= 8290130681918221197L;
25 private VersionComparator vc
= new VersionComparator();
28 public int category(Object element
) {
29 if (element
instanceof String
) {
30 int lastInd
= ((String
) element
).lastIndexOf('-');
34 // unvalid names always last
39 public int compare(Viewer viewer
, Object e1
, Object e2
) {
40 int cat1
= category(e1
);
41 int cat2
= category(e2
);
51 if (e1
instanceof TreeParent
) {
52 s1
= ((TreeParent
) e1
).getName();
53 s2
= ((TreeParent
) e2
).getName();
59 int i1
= s1
.lastIndexOf('-');
60 int i2
= s2
.lastIndexOf('-');
62 // Specific cases, unvalid Strings
65 return s1
.compareTo(s2
);
71 String aName
= s1
.substring(0, s1
.lastIndexOf('-'));
72 String aVersion
= s1
.substring(s1
.lastIndexOf('-'));
74 String bName
= s2
.substring(0, s2
.lastIndexOf('-'));
75 String bVersion
= s2
.substring(s2
.lastIndexOf('-'));
77 result
= aName
.compareTo(bName
);
81 return vc
.compare(viewer
, aVersion
, bVersion
);