KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Util > DFSRChecker > node > AtomicAction


1 /*
2  * $Id: AtomicAction.java,v 1.1 2005/07/13 07:27:49 kofron Exp $
3  *
4  * Copyright 2004
5  * Distributed Systems Research Group
6  * Department of Software Engineering
7  * Faculty of Mathematics and Physics
8  * Charles University, Prague
9  *
10  * Copyright 2005
11  * Formal Methods In Software Engineering Group
12  * Institute of Computer Science
13  * Academy of Sciences of the Czech Republic
14  *
15  * This code was developed by Jan Kofron <kofron@nenya.ms.mff.cuni.cz>
16  */

17
18 package SOFA.SOFAnode.Util.DFSRChecker.node;
19
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.TreeSet JavaDoc;
23
24 /**
25  * Extending class for a treeset.
26  * Implements comparable interface and can be use for
27  * storing within a hashset or whatever
28  */

29 public class AtomicAction extends TreeSet JavaDoc implements Comparable JavaDoc {
30
31
32     /**
33      * Creates a new instance of AtomicAction.
34      * @param c members of c that are to be added to this AtomicAction
35      */

36     public AtomicAction(Collection JavaDoc c) {
37         super(c);
38     }
39
40     /**
41      * Creates a new instance of AtomicAction.
42      *
43      */

44     public AtomicAction() {}
45     
46     
47     /**
48      * @see java.lang.Comparable#compareTo(java.lang.Object)
49      */

50     public int compareTo(Object JavaDoc o) {
51         if (o instanceof AtomicAction) {
52             AtomicAction other = (AtomicAction)o;
53             
54             if (this.size() < other.size())
55                 return -1;
56             else if (this.size() > other.size())
57                 return 1;
58             
59             else {
60                 Iterator JavaDoc it1 = this.iterator();
61                 Iterator JavaDoc it2 = other.iterator();
62                 
63                 while (it1.hasNext()) {
64                     Object JavaDoc o1 = it1.next();
65                     Object JavaDoc o2 = it2.next();
66                     
67                     int result = ((Comparable JavaDoc)o1).compareTo(o2);
68                     if (result != 0)
69                         return result;
70                 }
71                 
72                 return 0;
73             }
74         }
75         else
76             return -1;
77     }
78     
79     
80 }
81
Popular Tags