View Javadoc

1   /*
2    * Copyright 2007 Sebastien Brunot (sbrunot@gmail.com)
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *   
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sourceforge.buildmonitor;
17  
18  import java.util.Comparator;
19  import java.util.Date;
20  
21  /**
22   * Build report from a monitor.
23   * @author sbrunot
24   *
25   */
26  public class BuildReport
27  {
28  	/////////////////////////////
29  	// Nested class
30  	/////////////////////////////
31  
32  	/**
33  	 * A comparator to use to compare BuildReport instance according to their names.
34  	 * Note: this comparator imposes orderings that are inconsistent with equals.
35  	 */
36  	public static class NameComparator implements Comparator<BuildReport>
37  	{
38  
39  		public int compare(BuildReport o1, BuildReport o2)
40  		{
41  			int returnedValue = 0;
42  			if ((o1 == null) || (o2 == null))
43  			{
44  				throw new IllegalArgumentException("Cannot compare with null object");
45  			}
46  			String firstBuildReportName = o1.getName();
47  			String secondBuildReportName = o2.getName();
48  			
49  			if (firstBuildReportName == null)
50  			{
51  				if (secondBuildReportName == null)
52  				{
53  					returnedValue = 0;
54  				}
55  				else
56  				{
57  					returnedValue = -1;
58  				}
59  			}
60  			else
61  			{
62  				if (secondBuildReportName == null)
63  				{
64  					returnedValue = 1;
65  				}
66  				else
67  				{
68  					returnedValue = firstBuildReportName.compareTo(secondBuildReportName);
69  				}
70  			}
71  			return returnedValue;
72  		}	
73  	}
74  	
75  	/**
76  	 * A comparator to use to compare BuildReport instance according to their age.
77  	 * Note: this comparator imposes orderings that are inconsistent with equals.
78  	 */
79  	public static class AgeComparator implements Comparator<BuildReport>
80  	{
81  
82  		public int compare(BuildReport o1, BuildReport o2)
83  		{
84  			int returnedValue = 0;
85  			if ((o1 == null) || (o2 == null))
86  			{
87  				throw new IllegalArgumentException("Cannot compare with null object");
88  			}
89  			Date firstBuildReportDate = o1.getDate();
90  			Date secondBuildReportDate = o2.getDate();
91  			
92  			if (firstBuildReportDate == null)
93  			{
94  				if (secondBuildReportDate == null)
95  				{
96  					returnedValue = 0;
97  				}
98  				else
99  				{
100 					returnedValue = -1;
101 				}
102 			}
103 			else
104 			{
105 				if (secondBuildReportDate == null)
106 				{
107 					returnedValue = 1;
108 				}
109 				else
110 				{
111 					returnedValue = firstBuildReportDate.compareTo(secondBuildReportDate);
112 				}
113 			}
114 			return returnedValue;
115 		}
116 		
117 	}
118 
119 	/////////////////////////////
120 	// Enums
121 	/////////////////////////////
122 	
123 	/**
124 	 * Status of a build
125 	 * @author sbrunot
126 	 *
127 	 */
128 	public enum Status {OK, FAILED};
129 
130 	/////////////////////////////
131 	// Instance attributes
132 	/////////////////////////////
133 
134 	/**
135 	 * Id of the build
136 	 */
137 	private String id;
138 	
139 	/**
140 	 * Name of the build
141 	 */
142 	private String name;
143 	
144 	/**
145 	 * status of the build
146 	 */
147 	private Status status;
148 	
149 	/**
150 	 * Date of the build
151 	 */
152 	private Date date;
153 
154 	/////////////////////////////
155 	// Constructor
156 	/////////////////////////////
157 
158 	/**
159 	 * No args constructor
160 	 */
161 	public BuildReport()
162 	{
163 		
164 	}
165 	
166 	/**
167 	 * Create a new instance from an id, a status and a date
168 	 * @param theId the id of the build
169 	 * @param theDate the date of the build
170 	 * @param theStatus the status of the build
171 	 */
172 	public BuildReport(String theId, Date theDate, Status theStatus)
173 	{
174 		this.id = theId;
175 		this.date = theDate;
176 		this.status = theStatus;
177 	}
178 	
179 	/////////////////////////////
180 	// Getters and setters
181 	/////////////////////////////
182 
183 	/**
184 	 * Get the date of the build
185 	 *  @return the date of the build
186 	 */
187 	public Date getDate()
188 	{
189 		return this.date;
190 	}
191 
192 	/**
193 	 * Set the date of the build
194 	 * @param theDateOfTheBuild the date of the build
195 	 */
196 	public void setDate(Date theDateOfTheBuild)
197 	{
198 		this.date = theDateOfTheBuild;
199 	}
200 
201 	/**
202 	 * Get the id of the build
203 	 * @return the id of the build
204 	 */
205 	public String getId()
206 	{
207 		return this.id;
208 	}
209 
210 	/**
211 	 * Set the id of the build
212 	 * @param theIdOfTheBuild
213 	 */
214 	public void setId(String theIdOfTheBuild)
215 	{
216 		this.id = theIdOfTheBuild;
217 	}
218 
219 	/**
220 	 * Get the name of the build
221 	 * @return the name of the build
222 	 */
223 	public String getName()
224 	{
225 		return this.name;
226 	}
227 	
228 	/**
229 	 * Set the name of the build
230 	 * @param theName
231 	 */
232 	public void setName(String theName)
233 	{
234 		this.name = theName;
235 	}
236 
237 	/**
238 	 * Get the status of the build
239 	 * @return the status of the build
240 	 */
241 	public Status getStatus()
242 	{
243 		return this.status;
244 	}
245 
246 	/**
247 	 * Set the status of the build
248 	 * @param theStatusOfTheBuild the statud of the build
249 	 */
250 	public void setStatus(Status theStatusOfTheBuild)
251 	{
252 		this.status = theStatusOfTheBuild;
253 	}
254 
255 	/**
256 	 * Does this build report signal a failed build ?
257 	 * @return
258 	 */
259 	public boolean hasFailed()
260 	{
261 		return Status.FAILED.equals(this.status);
262 	}
263 }