Refactoring: rename duplicated Util classes
[jabaws.git] / engine / compbio / engine / Job.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.engine;\r
20 \r
21 import java.util.List;\r
22 \r
23 import compbio.engine.client.ConfiguredExecutable;\r
24 import compbio.engine.client.EngineUtil;\r
25 import compbio.util.annotation.Immutable;\r
26 \r
27 @Immutable\r
28 public final class Job {\r
29 \r
30         private final ClusterJobId jobId;\r
31         private final String taskId;\r
32         private final ConfiguredExecutable<?> cexecutable;\r
33 \r
34         public Job(String taskId, String jobId, ConfiguredExecutable<?> cexecutable) {\r
35                 if (!EngineUtil.isValidJobId(taskId)) {\r
36                         throw new IllegalArgumentException("TaskId " + taskId\r
37                                         + " is not valid!");\r
38                 }\r
39                 if (jobId == null) {\r
40                         throw new NullPointerException("Cluster JobId must be provided!");\r
41                 }\r
42                 if (cexecutable == null) {\r
43                         throw new NullPointerException(\r
44                                         "ConfiguredExecutable must be provided!");\r
45                 }\r
46                 this.jobId = new ClusterJobId(jobId);\r
47                 this.taskId = taskId;\r
48                 this.cexecutable = cexecutable;\r
49         }\r
50 \r
51         public ClusterJobId getJobId() {\r
52                 return jobId;\r
53         }\r
54 \r
55         public String getTaskId() {\r
56                 return taskId;\r
57         }\r
58 \r
59         public ConfiguredExecutable<?> getConfExecutable() {\r
60                 return cexecutable;\r
61         }\r
62 \r
63         @Override\r
64         public int hashCode() {\r
65                 final int prime = 31;\r
66                 int result = 1;\r
67                 result = prime * result + ((jobId == null) ? 0 : jobId.hashCode());\r
68                 result = prime * result + ((taskId == null) ? 0 : taskId.hashCode());\r
69                 return result;\r
70         }\r
71 \r
72         @Override\r
73         public boolean equals(Object obj) {\r
74                 if (this == obj)\r
75                         return true;\r
76                 if (obj == null)\r
77                         return false;\r
78                 if (getClass() != obj.getClass())\r
79                         return false;\r
80                 Job other = (Job) obj;\r
81                 if (jobId == null) {\r
82                         if (other.jobId != null)\r
83                                 return false;\r
84                 } else if (!jobId.equals(other.jobId))\r
85                         return false;\r
86                 if (taskId == null) {\r
87                         if (other.taskId != null)\r
88                                 return false;\r
89                 } else if (!taskId.equals(other.taskId))\r
90                         return false;\r
91                 return true;\r
92         }\r
93 \r
94         @Override\r
95         public String toString() {\r
96                 return "Job [cexecutable=" + cexecutable + ", jobId=" + jobId\r
97                                 + ", taskId=" + taskId + "]";\r
98         }\r
99 \r
100         public static Job getByTaskId(String taskId, List<Job> jobs) {\r
101                 for (Job j : jobs) {\r
102                         if (taskId.equals(j.getTaskId())) {\r
103                                 return j;\r
104                         }\r
105                 }\r
106                 return null;\r
107         }\r
108 \r
109         public static Job getByJobId(String jobId, List<Job> jobs) {\r
110                 for (Job j : jobs) {\r
111                         if (jobId.equals(j.getJobId())) {\r
112                                 return j;\r
113                         }\r
114                 }\r
115                 return null;\r
116         }\r
117 }\r