1 /*
2 * $Id: WorkflowComparator.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: WorkflowComparator.java 1419 2010-11-01 14:12:17Z hoheisel $
18 */
19 public class WorkflowComparator implements Comparator {
20
21 public static final int COMPARE_BIRTHDAY = 1;
22
23 private int compare_code;
24
25 public WorkflowComparator(int compare_code) {
26 this.compare_code = compare_code;
27 }
28
29
30 /**
31 * Compares its two Workflows for order. Returns a negative integer,
32 * zero, or a positive integer as the birthday of the first workflow 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_BIRTHDAY) {
47 long value1 = ((WorkflowInformation) o1).workflowBirthday;
48 long value2 = ((WorkflowInformation) o2).workflowBirthday;
49 long delta = value2 - value1;
50 if (delta > 0) return 1;
51 else if (delta < 0) return -1;
52 else return 0;
53 } else {
54 return 0;
55 }
56 }
57
58 }