1 4 package com.tc; 5 6 import java.util.Arrays ; 7 8 public class WebAppComparable implements Comparable { 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 o) { 20 WebAppComparable other = (WebAppComparable)o; 21 WebApp otherType = other.element(); 22 String 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 |