Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 170540 | Differences between
and this patch

Collapse All | Expand All

(-).classpath (-1 / +5 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
3
	<classpathentry kind="src" path="WEB-INF/src"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**/TaskListImages"/>
6
			<accessrule kind="accessible" pattern="**/TaskListImages"/>
Lines 12-16 Link Here
12
			<accessrule kind="nonaccessible" pattern="com/sun/**"/>
12
			<accessrule kind="nonaccessible" pattern="com/sun/**"/>
13
		</accessrules>
13
		</accessrules>
14
	</classpathentry>
14
	</classpathentry>
15
	<classpathentry kind="lib" path="/org.eclipse.mylar/lib-httpclient/commons-httpclient-3.0.1.jar"/>
16
	<classpathentry kind="lib" path="C:/Temp/tomcat/apache-tomcat-6.0.2/lib/servlet-api.jar"/>
17
	<classpathentry kind="lib" path="WEB-INF/lib/commons-fileupload-1.1.1.jar"/>
18
	<classpathentry kind="lib" path="WEB-INF/lib/commons-io-1.2.jar"/>
15
	<classpathentry kind="output" path="bin"/>
19
	<classpathentry kind="output" path="bin"/>
16
</classpath>
20
</classpath>
(-)lib/readme.txt (-2 lines)
Removed Link Here
1
2
Download info for libraries.
(-)WEB-INF/src/upload/UsageAnalysis.java (+272 lines)
Added Link Here
1
package upload;
2
3
import java.io.File;
4
import java.io.FileOutputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.PrintStream;
8
import java.io.PrintWriter;
9
import java.util.ArrayList;
10
import java.util.Collections;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.zip.ZipEntry;
15
import java.util.zip.ZipFile;
16
17
public class UsageAnalysis {
18
19
	Map<Integer, Map<String, Integer>> userToViewMap = new HashMap<Integer, Map<String, Integer>>();
20
21
	Map<Integer, Integer> usersNumSelections = new HashMap<Integer, Integer>();
22
23
	Map<String, Integer> totalNumSelections = new HashMap<String, Integer>();
24
	
25
	final static String USAGE_DIRECTORY = MylarUsageUploadServlet.UPLOAD_DIRECTORY;
26
	
27
	final static String LOGGING_DIRECTORY = "home//study//logging//";
28
		
29
	final static String ERROR_LOGGING_FILE = "MylarUsageAnalysisErrorLog.txt";
30
31
	final static String USAGE_SUMMARY_FILE = "usageSummary.txt";
32
33
	int MAX_NUM_VIEWS_TO_REPORT = 10;
34
35
	int totalSelections = 0;
36
37
	public static void main(String []args) {
38
		UsageAnalysis ua = new UsageAnalysis();
39
		ua.analyzeLogs();
40
	}
41
	public void analyzeLogs() {
42
43
		try {
44
			String[] files = new File(USAGE_DIRECTORY).list();
45
			int userID = 0;
46
47
			for (String filename : files) {
48
				File currFile = new File(USAGE_DIRECTORY, filename);
49
50
				userID = this.getUserId(currFile);
51
52
				int numSelections = 0;
53
				if (usersNumSelections.containsKey(userID)) {
54
					numSelections = usersNumSelections.get(userID);
55
				}
56
57
				Map<String, Integer> viewToNumberMap = userToViewMap.get(userID);
58
				if (viewToNumberMap == null) {
59
					viewToNumberMap = new HashMap<String, Integer>();
60
					userToViewMap.put(userID, viewToNumberMap);
61
				}
62
63
				int index;
64
				int endIndex;
65
				String currOriginId;
66
				String buf = "";
67
				byte[] buffer = new byte[1000];
68
				int bytesRead = 0;
69
				String beginningTag = "<originId>";
70
				String endTag = "</originId>";
71
72
				String kindTag = "<kind>";
73
				String matchKind = "selection";
74
75
				// they should all be zip files, ignore anything that's not
76
				if (currFile.getName().endsWith(".zip")) {
77
					ZipFile zip = new ZipFile(currFile);
78
79
					if (zip.entries().hasMoreElements()) {
80
						ZipEntry entry = zip.entries().nextElement();
81
						InputStream stream = zip.getInputStream(entry);
82
83
						while ((bytesRead = stream.read(buffer)) != -1) {
84
							buf = buf + new String(buffer, 0, bytesRead);
85
86
							while ((endIndex = buf.indexOf(endTag)) != -1) {
87
								index = buf.indexOf(beginningTag);
88
								index += beginningTag.length();
89
90
								int kindIndex = buf.indexOf(kindTag);
91
								kindIndex += kindTag.length();
92
93
								if (buf.substring(kindIndex, kindIndex + matchKind.length()).equals(matchKind)) {
94
95
									numSelections++;
96
									totalSelections++;
97
98
									currOriginId = buf.substring(index, endIndex);
99
100
									if (!viewToNumberMap.containsKey(currOriginId)) {
101
										viewToNumberMap.put(currOriginId, 0);
102
									}
103
									int numViews = viewToNumberMap.get(currOriginId) + 1;
104
									viewToNumberMap.put(currOriginId, numViews);
105
106
									if (!totalNumSelections.containsKey(currOriginId)) {
107
										totalNumSelections.put(currOriginId, 0);
108
									}
109
									int totalNumViews = totalNumSelections.get(currOriginId) + 1;
110
									totalNumSelections.put(currOriginId, totalNumViews);
111
112
								}
113
114
								buf = buf.substring(endIndex + endTag.length(), buf.length());
115
116
							}
117
118
							buffer = new byte[1000];
119
						}
120
					}
121
				}
122
				usersNumSelections.put(userID, numSelections);
123
124
			}
125
			// print to a file.
126
			printSummaryToFile();
127
		} catch (IOException ioe) {
128
			logError(ioe.getMessage());
129
		}
130
131
	}
132
133
	private static void logError(String error) {
134
		File errorLogFile = new File(LOGGING_DIRECTORY, ERROR_LOGGING_FILE);
135
		try {
136
			if (!errorLogFile.exists()) {
137
				errorLogFile.createNewFile();
138
			}
139
140
			PrintStream errorLogStream = new PrintStream(new FileOutputStream(errorLogFile, true));
141
142
			errorLogStream.println(error);
143
144
		} catch (IOException e) {
145
			e.printStackTrace();
146
		}
147
	}
148
149
	/**
150
	 * Assuming the file naming convention of <phase>-<version>-usage-<userID>-<date
151
	 * and time>.zip
152
	 * 
153
	 * copied from: org.eclipse.mylar.monitor.usage.core.ReportGenerator author:
154
	 * Mik Kersten
155
	 */
156
	private int getUserId(File source) {
157
		String userIDText = source.getName();
158
		int userId = -1;
159
		String prefix = "-usage-";
160
161
		if (source.getName().indexOf(prefix) >= 0) {
162
			try {
163
				userIDText = userIDText.substring(userIDText.indexOf(prefix) + prefix.length(), userIDText.length());
164
				userIDText = userIDText.substring(0, userIDText.indexOf("-"));
165
				userId = Integer.valueOf(userIDText);
166
			} catch (Throwable t) {
167
				logError(t.getMessage());
168
			}
169
		}
170
171
		return userId;
172
	}
173
174
	private String formatAsPercentage(float viewUse) {
175
		String formattedViewUse = ("" + viewUse * 100);
176
177
		// sometimes the floats are so small that formattedViewUsage ends up
178
		// being
179
		// something like 7.68334E-4, which would get formatted to 7.68% without
180
		// this check
181
		if (formattedViewUse.contains("E")) {
182
			return "0.00%";
183
		}
184
		int indexOf2ndDecimal = formattedViewUse.indexOf('.') + 3;
185
		if (indexOf2ndDecimal <= formattedViewUse.length()) {
186
			formattedViewUse = formattedViewUse.substring(0, indexOf2ndDecimal);
187
		}
188
		return formattedViewUse + "%";
189
	}
190
191
	static public String getSummaryFilePath() {
192
		File summaryFile = new File(USAGE_DIRECTORY, USAGE_SUMMARY_FILE);
193
		if (!summaryFile.exists()) {
194
			try {
195
				summaryFile.createNewFile();
196
			} catch (IOException e) {
197
				logError(e.getMessage());
198
			}
199
		}
200
201
		return summaryFile.getAbsolutePath();
202
	}
203
204
	public void printSummaryToFile() {
205
206
		File summaryFile = new File(USAGE_DIRECTORY, USAGE_SUMMARY_FILE);
207
		try {
208
			if (!summaryFile.exists()) {
209
				summaryFile.createNewFile();
210
			} else {
211
				summaryFile.delete();
212
				summaryFile.createNewFile();
213
			}
214
215
			PrintStream summaryLogStream = new PrintStream(new FileOutputStream(summaryFile, true));
216
217
			summaryLogStream.println("Total events: " + totalSelections);
218
			summaryLogStream.println("Number of unique users: " + userToViewMap.entrySet().size());
219
			summaryLogStream.println();
220
221
			summaryLogStream.println(MAX_NUM_VIEWS_TO_REPORT + " most used views:");
222
223
			List<String> viewUsage = new ArrayList<String>();
224
			for (String view : totalNumSelections.keySet()) {
225
				float numSelections = (float) (totalNumSelections.get(view));
226
				float viewUse = numSelections / totalSelections;
227
				String formattedViewUse = formatAsPercentage(viewUse);
228
				viewUsage.add(formattedViewUse + ": " + view + " (" + totalNumSelections.get(view) + ")");
229
			}
230
			Collections.sort(viewUsage, new PercentUsageComparator());
231
			int numViewsToReport = 0;
232
			for (String viewUsageSummary : viewUsage) {
233
				if (MAX_NUM_VIEWS_TO_REPORT == -1 || numViewsToReport < MAX_NUM_VIEWS_TO_REPORT) {
234
235
					summaryLogStream.println(viewUsageSummary);
236
					numViewsToReport++;
237
				}
238
			}
239
240
		} catch (IOException e) {
241
			logError(e.getMessage());
242
		}
243
244
	}
245
246
	public void printSummary(int userId, PrintWriter out) {
247
		Map<String, Integer> normalViewSelections = userToViewMap.get(userId);
248
249
		float numSelections = usersNumSelections.get(userId);
250
251
		List<String> viewUsage = new ArrayList<String>();
252
		for (String view : normalViewSelections.keySet()) {
253
			float viewUse = ((float) (normalViewSelections.get(view))) / numSelections;
254
			String formattedViewUse = formatAsPercentage(viewUse);
255
			viewUsage.add(formattedViewUse + ": " + view + " (" + normalViewSelections.get(view) + ")" + "<br>");
256
		}
257
		Collections.sort(viewUsage, new PercentUsageComparator());
258
		int numViewsToReport = 0;
259
		for (String viewUsageSummary : viewUsage) {
260
			if (MAX_NUM_VIEWS_TO_REPORT == -1 || numViewsToReport < MAX_NUM_VIEWS_TO_REPORT) {
261
				out.println(viewUsageSummary);
262
				numViewsToReport++;
263
			}
264
		}
265
	}
266
267
	public void printReport(PrintWriter out) {
268
		for (int userId : userToViewMap.keySet()) {
269
			printSummary(userId, out);
270
		}
271
	}
272
}
(-)WEB-INF/src/upload/GetUserIDServlet.java (+104 lines)
Added Link Here
1
package upload;
2
3
import java.io.BufferedWriter;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileOutputStream;
7
import java.io.FileWriter;
8
import java.io.IOException;
9
import java.io.PrintStream;
10
import java.io.PrintWriter;
11
12
import javax.servlet.ServletException;
13
import javax.servlet.http.HttpServlet;
14
import javax.servlet.http.HttpServletRequest;
15
import javax.servlet.http.HttpServletResponse;
16
17
/**
18
 * @author - Meghan Allen
19
 */
20
public class GetUserIDServlet extends HttpServlet {
21
22
	private static final long serialVersionUID = 1L;
23
24
	private static final String USER_ID_PARAM = "MylarUserID";
25
26
	private static final String USER_ID_DIRECTORY = "//home//study//userIDS//";
27
28
	private static final String NEXT_USER_ID_FILENAME = "MylarNextUserID.txt";
29
30
	private static final String MYLAR_USER_IDS_FILENAME = "MylarUserIDs.txt";
31
32
	private static final String LOGGING_DIRECTORY = "//home//study//logging//";
33
34
	private static final String ERROR_LOGGING_FILE = "MylarUsageGetUIDErrorLog.txt";
35
36
	private static final int SIZE_OF_INT = 8;
37
38
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
39
		String userIDRequest = req.getParameter(USER_ID_PARAM);
40
41
		if (userIDRequest == null) {
42
			res.sendError(HttpServletResponse.SC_BAD_REQUEST);
43
			return;
44
		}
45
46
		res.setContentType("text/plain");
47
		PrintWriter out = res.getWriter();
48
		try {
49
			out.print("" + this.getNewUserID());
50
			res.setStatus(HttpServletResponse.SC_OK);
51
		} catch (IOException ioe) {
52
			logError("GetUserIDServlet:doPost out.print() failed " + ioe.getMessage());
53
			res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
54
		}
55
	}
56
57
	private synchronized int getNewUserID() throws IOException {
58
		File nextUserIDFile = new File(USER_ID_DIRECTORY, NEXT_USER_ID_FILENAME);
59
		if (!nextUserIDFile.exists()) {
60
			throw new IOException(USER_ID_DIRECTORY + NEXT_USER_ID_FILENAME + " does not exist");
61
		}
62
63
		FileInputStream fileInputStream = new FileInputStream(nextUserIDFile);
64
		byte[] buffer = new byte[SIZE_OF_INT];
65
		int numBytesRead = fileInputStream.read(buffer);
66
		int uID = new Integer(new String(buffer, 0, numBytesRead)).intValue();
67
		fileInputStream.close();
68
69
		BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(nextUserIDFile));
70
		int nextUId = uID + 17;
71
		bufferedWriter.write(new Integer(nextUId).toString());
72
		bufferedWriter.close();
73
74
		File allUserIDFile = new File(USER_ID_DIRECTORY, MYLAR_USER_IDS_FILENAME);
75
		if (!allUserIDFile.exists()) {
76
			throw new IOException(USER_ID_DIRECTORY + MYLAR_USER_IDS_FILENAME + " does not exist");
77
		}
78
79
		PrintStream printStreamAllIds = new PrintStream(new FileOutputStream(allUserIDFile, true));
80
81
		printStreamAllIds.println(new Integer(uID).toString());
82
		printStreamAllIds.flush();
83
84
		printStreamAllIds.close();
85
86
		return uID;
87
	}
88
89
	private void logError(String errorMessage) {
90
		File errorLogFile = new File(LOGGING_DIRECTORY, ERROR_LOGGING_FILE);
91
		try {
92
			if (!errorLogFile.exists()) {
93
				errorLogFile.createNewFile();
94
			}
95
96
			PrintStream errorLogStream = new PrintStream(new FileOutputStream(errorLogFile, true));
97
98
			errorLogStream.println(errorMessage);
99
100
		} catch (IOException e) {
101
			e.printStackTrace();
102
		}
103
	}
104
}
(-).refactorings/2007/2/6/refactorings.history (+4 lines)
Added Link Here
1
<?xml version="1.0" encoding="utf-8"?>
2
<session version="1.0">
3
<refactoring comment="Move 1 elements(s) to 'WEB-INF'&#13;&#10;- Original project: 'org.eclipse.mylar.monitor.server'&#13;&#10;- Destination element: 'WEB-INF'&#13;&#10;- Original element: 'lib'" description="Move folder" element1="lib" files="0" flags="589830" folders="1" id="org.eclipse.jdt.ui.move" policy="org.eclipse.jdt.ui.moveResources" qualified="false" references="true" stamp="1170886725833" target="/org.eclipse.mylar.monitor.server/WEB-INF" units="0" version="1.0"/>
4
</session>
(-)WEB-INF/src/upload/MylarUsageUploadServlet.java (+109 lines)
Added Link Here
1
package upload;
2
3
import java.io.File;
4
import java.io.FileOutputStream;
5
import java.io.IOException;
6
import java.io.PrintStream;
7
import java.text.SimpleDateFormat;
8
import java.util.Date;
9
import java.util.List;
10
11
import javax.servlet.http.HttpServlet;
12
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletResponse;
14
15
import org.apache.commons.fileupload.FileItem;
16
import org.apache.commons.fileupload.FileItemFactory;
17
import org.apache.commons.fileupload.FileUploadException;
18
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
19
import org.apache.commons.fileupload.servlet.ServletFileUpload;
20
21
/**
22
 * @author - Meghan Allen
23
 */
24
public class MylarUsageUploadServlet extends HttpServlet {
25
26
	private static final long serialVersionUID = 1L;
27
28
	public static final String UPLOAD_DIRECTORY = "//home//study//uploads//";
29
30
	private static final String LOGGING_DIRECTORY = "//home//study//logging//";
31
32
	private static final String ERROR_LOGGING_FILE = "MylarUsageUploadErrorLog.txt";
33
34
	// 4 digit year, 2 digit month, 2 digit day, 2 digit hour, 2 digit minute
35
	// 2 digit second, 3 digit millisecond
36
	private static final String DATE_FORMAT_STRING = "yyyy.MM.dd.HH.mm.ss.SSS";
37
38
	// Supress warnings because
39
	// org.apache.commons.fileupload.servlet.ServletFileUpload
40
	// parseRequest doesn't use generics (suppress unchecked), and
41
	// ServletFileUpload.isMultipartContent is deprecated (suppress deprecation)
42
	@SuppressWarnings( { "unchecked", "deprecation" })
43
	@Override
44
	protected void doPost(HttpServletRequest request, HttpServletResponse response) {
45
46
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);
47
48
		try {
49
50
			if (isMultipart) {
51
52
				// Create a factory for disk-based file items
53
				FileItemFactory factory = new DiskFileItemFactory();
54
55
				// Create a new file upload handler
56
				ServletFileUpload upload = new ServletFileUpload(factory);
57
58
				// Parse the request
59
				List<FileItem> items = upload.parseRequest(request);
60
61
				for (FileItem fi : items) {
62
63
					String oldFilename = fi.getName();
64
65
					int indexFirstDot = oldFilename.indexOf(".");
66
67
					String uid = oldFilename.substring(0, indexFirstDot);
68
					String extension = oldFilename.substring(oldFilename.length() - 4, oldFilename.length());
69
70
					String name = "USAGE-1.0-usage-" + uid + "-"
71
							+ new SimpleDateFormat(DATE_FORMAT_STRING).format(new Date()) + extension;
72
73
					File destFile = new File(UPLOAD_DIRECTORY, name);
74
					destFile.createNewFile();
75
76
					try {
77
						fi.write(destFile);
78
					} catch (Exception e) {
79
						logError("MylarUsageUploadServlet:doPost fi.write() failed " + e.getMessage());
80
81
					}
82
83
				}
84
85
			}
86
		} catch (FileUploadException fue) {
87
			logError("MylarUsageUploadServlet:doPost upload.parseRequest(request) failed " + fue.getMessage());
88
89
		} catch (IOException ioe) {
90
			logError("MylarUsageUploadServlet:doPost destFile.createNewFile() failed " + ioe.getMessage());
91
		}
92
	}
93
94
	private void logError(String errorMessage) {
95
		File errorLogFile = new File(LOGGING_DIRECTORY, ERROR_LOGGING_FILE);
96
		try {
97
			if (!errorLogFile.exists()) {
98
				errorLogFile.createNewFile();
99
			}
100
101
			PrintStream errorLogStream = new PrintStream(new FileOutputStream(errorLogFile, true));
102
103
			errorLogStream.println(errorMessage);
104
105
		} catch (IOException e) {
106
			e.printStackTrace();
107
		}
108
	}
109
}
(-)WEB-INF/web.xml (+43 lines)
Added Link Here
1
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
2
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
3
4
<web-app>
5
6
<servlet>
7
<servlet-name>MylarUsageUploadServlet</servlet-name>
8
<display-name>MylarUsageUploadServlet</display-name>
9
<servlet-class>upload.MylarUsageUploadServlet</servlet-class>
10
</servlet>
11
12
<servlet-mapping>
13
<servlet-name>MylarUsageUploadServlet</servlet-name>
14
<url-pattern>/MylarUsageUploadServlet</url-pattern>
15
</servlet-mapping>
16
17
18
<servlet>
19
<servlet-name>GetUserIDServlet</servlet-name>
20
<display-name>GetUserIDServlet</display-name>
21
<servlet-class>upload.GetUserIDServlet</servlet-class>
22
</servlet>
23
24
<servlet-mapping>
25
<servlet-name>GetUserIDServlet</servlet-name>
26
<url-pattern>/GetUserIDServlet</url-pattern>
27
</servlet-mapping>
28
29
30
31
<servlet>
32
<servlet-name>UsageAnalysisServlet</servlet-name>
33
<display-name>UsageAnalysisServlet</display-name>
34
<servlet-class>upload.UsageAnalysisServlet</servlet-class>
35
</servlet>
36
37
<servlet-mapping>
38
<servlet-name>UsageAnalysisServlet</servlet-name>
39
<url-pattern>/UsageAnalysisServlet</url-pattern>
40
</servlet-mapping>
41
42
43
</web-app>
(-).refactorings/2007/2/6/refactorings.index (+1 lines)
Added Link Here
1
1170886725833	Move folder
(-)WEB-INF/lib/readme.txt (+8 lines)
Added Link Here
1
This plugin depends on two Apache libraries that must be downloaded independently of Mylar.
2
3
4
commons-fileupload-1.1.1.jar can be downloaded from here:
5
http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi
6
7
commons-io-1.2.jar can be downloaded from here:
8
http://archive.apache.org/dist/jakarta/commons/io/binaries/
(-)WEB-INF/lib/.cvsignore (+2 lines)
Added Link Here
1
commons-io-1.2.jar
2
commons-fileupload-1.1.1.jar
(-)WEB-INF/src/upload/UsageAnalysisServlet.java (+40 lines)
Added Link Here
1
package upload;
2
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.IOException;
6
import java.io.PrintWriter;
7
8
import javax.servlet.ServletException;
9
import javax.servlet.http.HttpServlet;
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletResponse;
12
13
public class UsageAnalysisServlet extends HttpServlet {
14
15
	private static final long serialVersionUID = 1L;
16
17
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
18
		PrintWriter out = res.getWriter();
19
20
// run the analysis as a cron job
21
//		UsageAnalysis usageAnalysis = new UsageAnalysis();
22
//		usageAnalysis.analyzeLogs();
23
24
		String filePath = UsageAnalysis.getSummaryFilePath();
25
26
		File summaryFile = new File(filePath);
27
28
		FileInputStream inputStream = new FileInputStream(summaryFile);
29
30
		int bytesRead = 0;
31
		byte[] buffer = new byte[1000];
32
33
		while ((bytesRead = inputStream.read(buffer)) != -1) {
34
			out.print(new String(buffer, 0, bytesRead));
35
36
		}
37
38
	}
39
40
}
(-)WEB-INF/src/upload/PercentUsageComparator.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package upload;
13
14
import java.util.Comparator;
15
16
/**
17
 * This class was copied from
18
 * org.eclipse.mylar.internal.monitor.core.collection.
19
 * 
20
 * 
21
 * @author Mik Kersten and Leah Findlater
22
 */
23
class PercentUsageComparator implements Comparator<String> {
24
	public int compare(String o1, String o2) {
25
		int index1 = o1.indexOf('%');
26
		int index2 = o2.indexOf('%');
27
		if (index1 != -1 && index2 != -1) {
28
			String s1 = o1.substring(0, index1);
29
			String s2 = o2.substring(0, index2);
30
			return (-1) * new Float(s1).compareTo(new Float(s2));
31
		} else {
32
			return 0;
33
		}
34
	}
35
}

Return to bug 170540