KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > WebAppComparable


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc;
5
6 import java.util.Arrays JavaDoc;
7
8 public class WebAppComparable implements Comparable JavaDoc {
9   private WebApp m_webApp;
10     
11   WebAppComparable(WebApp webApp) {
12     m_webApp = webApp;
13   }
14     
15   public WebApp element() {
16     return m_webApp;
17   }
18
19   public int compareTo(Object JavaDoc o) {
20     WebAppComparable other = (WebAppComparable)o;
21     WebApp otherType = other.element();
22     String JavaDoc otherName = otherType.getName();
23
24     return m_webApp.getName().compareTo(otherName);
25   }
26
27   public static WebApp[] sort(WebApp[] webApps) {
28     int count = webApps.length;
29     WebAppComparable[] tmp = new WebAppComparable[count];
30     
31     for(int i = 0; i < count; i++) {
32       tmp[i] = new WebAppComparable(webApps[i]);
33     }
34     Arrays.sort(tmp);
35     for(int i = 0; i < count; i++) {
36       webApps[i] = tmp[i].element();
37     }
38
39     return webApps;
40   }
41 }
42
Popular Tags