KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > repository > plugins > basic > BasicAttributeComparator


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22
23 /*
24  * JBoss, Home of Professional Open Source
25  *
26  * Distributable under LGPL license.
27  * See terms of license at gnu.org.
28  */

29
30 package org.jboss.repository.plugins.basic;
31
32 import java.util.Comparator JavaDoc;
33 import java.util.HashMap JavaDoc;
34
35 import org.jboss.repository.spi.CommonNames;
36
37 /**
38  @author Scott.Stark@jboss.org
39  @version $Revision: 41119 $
40  */

41 public class BasicAttributeComparator
42    implements Comparator JavaDoc
43 {
44    private static String JavaDoc[] BASIC_ORDERING = {
45       CommonNames.THREAD,
46       CommonNames.REQUEST,
47       CommonNames.SESSION,
48       CommonNames.DEPLOYMENT,
49       CommonNames.APPLICATION,
50       CommonNames.SERVER,
51       CommonNames.CLUSTER,
52       CommonNames.DOMAIN
53    };
54    private static HashMap JavaDoc BASIC_ORDER_INDEXES = new HashMap JavaDoc();
55    static
56    {
57       for(int n = 0; n < BASIC_ORDERING.length; n ++)
58          BASIC_ORDER_INDEXES.put(BASIC_ORDERING[n], new Integer JavaDoc(n));
59    }
60
61    public int compare(Object JavaDoc obj1, Object JavaDoc obj2)
62    {
63       String JavaDoc name1 = (String JavaDoc) obj1;
64       String JavaDoc name2 = (String JavaDoc) obj2;
65       Integer JavaDoc index1 = (Integer JavaDoc) BASIC_ORDER_INDEXES.get(name1);
66       Integer JavaDoc index2 = (Integer JavaDoc) BASIC_ORDER_INDEXES.get(name2);
67       int compare = 0;
68       if( index1 != null )
69       {
70          if( index2 != null )
71             compare = index1.compareTo(index2);
72          else
73             compare = -1;
74       }
75       else if( index2 != null )
76       {
77          //
78
compare = 1;
79       }
80       else
81       {
82          // Neither attribute is a standard one
83
compare = name1.compareTo(name2);
84       }
85       return compare;
86    }
87
88 }
89
Popular Tags