KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ast > lib > DependencyComparator


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library 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 library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Mathieu Vadet.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ast.lib;
28
29 /** To access all the AST Declaration. */
30 import org.objectweb.openccm.ast.api.Declaration;
31
32
33 /**
34  * This class defines a comparator for dependencies.
35  * It can be used to sort a list of dependencies.
36  *
37  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
38  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
39  *
40  * @version 0.3
41  */

42
43 public class DependencyComparator
44        implements java.util.Comparator JavaDoc
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     // ==================================================================
53
//
54
// Constructor.
55
//
56
// ==================================================================
57

58     /**
59      * The default constructor.
60      */

61     public
62     DependencyComparator()
63     {
64     }
65
66     // ==================================================================
67
//
68
// Public methods for the java.util.Comparator interface.
69
//
70
// ==================================================================
71

72     /**
73      * Compare two declarations.
74      */

75     public int
76     compare(java.lang.Object JavaDoc o1,
77             java.lang.Object JavaDoc o2)
78     {
79         Declaration decl1 = (Declaration)o1;
80         Declaration decl2 = (Declaration)o2;
81
82         Declaration[] depend = decl1.getDependencies();
83         for (int i=0;i<depend.length;i++)
84         {
85             if (depend[i]==o2)
86                 return 1;
87         }
88
89         depend = decl2.getDependencies();
90         for (int i=0;i<depend.length;i++)
91         {
92             if (depend[i]==o1)
93                 return -1;
94         }
95
96         return 0;
97     }
98
99     /**
100      * Is equals to another object.
101      */

102     public boolean
103     equals(java.lang.Object JavaDoc o)
104     {
105         return (o==this);
106     }
107 }
108
Popular Tags