1 /*
2 * $Id: ResourceComparator.java 1419 2010-11-01 14:12:17Z hoheisel $
3 *
4 * Copyright (c) 2005-2006, The K-Wf Grid Consortium
5 * Fraunhofer Institute for Computer Architecture and Software Technology
6 * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
7 */
8
9 package net.kwfgrid.gwes.servlet;
10
11 import java.util.Comparator;
12
13 /**
14 * Compares two workflows
15 * @author Andreas Hoheisel
16 * (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
17 * @version $Id: ResourceComparator.java 1419 2010-11-01 14:12:17Z hoheisel $
18 */
19 public class ResourceComparator implements Comparator {
20
21 public static final int COMPARE_URI = 1;
22
23 private int compare_code;
24
25 public ResourceComparator(int compare_code) {
26 this.compare_code = compare_code;
27 }
28
29
30 /**
31 * Compares its two Resources for order. Returns a negative integer,
32 * zero, or a positive integer as the uri of the first resource is less than, equal
33 * to, or greater than the second.<p>
34 * <p/>
35 * Note: this comparator imposes orderings that are inconsistent with equals.
36 *
37 * @param o1 the first object to be compared.
38 * @param o2 the second object to be compared.
39 * @return a negative integer, zero, or a positive integer as the
40 * first argument is less than, equal to, or greater than the
41 * second.
42 * @throws ClassCastException if the arguments' types prevent them from
43 * being compared by this Comparator.
44 */
45 public int compare(Object o1, Object o2) {
46 if (compare_code==COMPARE_URI) {
47 String value1 = ((ResourceInformation) o1).uri;
48 String value2 = ((ResourceInformation) o2).uri;
49 return value1.compareTo(value2);
50 } else {
51 return 0;
52 }
53 }
54
55 }