Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Creation of Mapping repository.
[mapping.git] / src / and / Mapping / GTask.java
1 package and.Mapping ;
2
3
4 import java.io.Serializable;
5 import java.util.ArrayList;
6
7
8 /**
9  * Class representing an application task
10  * @author Sébastien Miquée
11  *
12  */
13 public class GTask implements Serializable
14 {
15         private static final long serialVersionUID = 1L;
16
17         
18         private int num ;
19         private int weight ;
20         private ArrayList<GTask> dependencies ;
21         private int nb_dep ;
22         
23         
24         /**
25          * Default constructor.
26          */
27         public GTask()
28         {
29                 num = -1 ;
30                 weight = 10000 ;
31                 dependencies = new ArrayList<GTask>() ;
32                 nb_dep = 0 ;
33         }
34         
35         
36         /**
37          * Constructor.
38          * @param _n Task number
39          */
40         public GTask( int _n )
41         {
42                 num = _n ;
43                 weight = 10000 ;
44                 dependencies = new ArrayList<GTask>() ;
45                 nb_dep = 0 ;
46         }
47         
48         
49         /**
50          * Add a dependency to the task.
51          * @param _t Dependency task
52          */
53         public void addDependance( GTask _t )
54         {
55                 if( _t != null )
56                 {
57                         if( ! _t.equals( this ) && ! dependencies.contains( _t ) )
58                         {
59                                 dependencies.add( _t ) ;
60                                 nb_dep ++ ;
61                         }
62                 }
63         }
64         
65         
66
67         /**
68          * Return the task's number in a string.
69          * @return A String containing the task's number
70          */
71         public String toString()
72         {
73                 return "" + num ;
74         }
75         
76         
77         /**
78          * Add a dependencies list to the task.
79          * @param at The dependencies list
80          */
81         public void addDependance( ArrayList<GTask> at )
82         {
83                 if( at != null )
84                 {
85                         for( int i = 0 ; i < at.size() ; i++ )
86                         {
87                                 this.addDependance( at.get( i ) ) ;
88                         }                       
89                 }
90         }
91         
92         
93         /**
94          * Define the task's computing weight.
95          * @param _p The computing weight
96          */
97         public void setWeight( int _p )
98         {
99                 weight = _p ;
100         }
101         
102         
103         /**
104          * Return the task's weight.
105          * @return The task's weight
106          */
107         public int getWeight()
108         {
109                 return weight ;
110         }
111         
112         
113         /**
114          * Return the task's dependencies list.
115          * @return The dependencies list
116          */
117         public ArrayList<GTask> getDependencies()
118         {
119                 return dependencies ;
120         }
121         
122         
123         /**
124          * Return the task's number.
125          * @return The task's number
126          */
127         public int getNum()
128         {
129                 return num ;
130         }
131         
132         
133         /**
134          * Return the amount of dependencies of the task.
135          * @return The amount of dependencies
136          */
137         public int getNbDep()
138         {
139                 return nb_dep ;
140         }
141
142         
143         /**
144          * Return the task's dependencies list in a text form.
145          * @return The String containing the dependencies list
146          */
147         public String printDep() 
148         {
149                 String s = "{ " ;
150                 
151                 for( int i = 0 ; i < nb_dep ; i++ )
152                 {
153                         s = s + dependencies.get( i ).getNum() ;
154                         if( i != nb_dep - 1 )
155                         {
156                                 s = s + ", " ;
157                         }
158                 }
159                 
160                 s = s + " }" ;
161                 
162                 return s ;
163         }
164 }
165
166 /** La programmation est un art, respectons ceux qui la pratiquent !! **/