01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.dlm;
07:
08: import java.util.Comparator;
09:
10: /**
11: * A comparator of fragment objects that sorts first by precedence value with
12: * highest number being higher and if equal it then sorts by fragment index
13: * with the lowest number having highest precedence since it is an indication
14: * of the fragments location within the config file. For those with equal
15: * precedence the one defined first when loading the file should take
16: * precedence.
17: * @version $Revision: 35705 $ $Date: 2005-05-01 20:14:20 -0700 (Sun, 01 May 2005) $
18: * @since uPortal 2.5
19: */
20:
21: public class FragmentComparator implements Comparator {
22: public static final String RCS_ID = "@(#) $Header$";
23:
24: public int compare(Object obj1, Object obj2) {
25: FragmentDefinition frag1 = (FragmentDefinition) obj1;
26: FragmentDefinition frag2 = (FragmentDefinition) obj2;
27:
28: if (frag1.precedence == frag2.precedence) {
29: return frag1.index - frag2.index;
30: } else {
31: return (int) (frag2.precedence - frag1.precedence);
32: }
33: }
34:
35: public boolean equals(Object obj) {
36: return obj.equals(this);
37: }
38: }
|