01: /*
02: $Header: /cvsroot/xorm/xorm/src/org/xorm/DependencyComparator.java,v 1.6 2002/08/23 17:50:03 wbiggs Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify
07: it under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with XORM; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm;
21:
22: import java.util.Comparator;
23:
24: /**
25: * Sorts Proxy items such that those that depend on others are ordered
26: * following their dependencies.
27: */
28: public class DependencyComparator implements Comparator {
29: public int compare(Object o1, Object o2) {
30: // The object o1 and o2 are IIHs
31: InterfaceInvocationHandler h1 = (InterfaceInvocationHandler) o1;
32: InterfaceInvocationHandler h2 = (InterfaceInvocationHandler) o2;
33: if (h1.dependsOn(h2))
34: return 1;
35: if (h2.dependsOn(h1))
36: return -1;
37:
38: // Otherwise order by class, then primary key
39: return h1.compareTo(h2);
40:
41: // TODO maybe just move all this code to IIH and make it Comparable
42: }
43: }
|