1 23 24 29 30 package com.sun.enterprise.util.diagnostics; 31 32 import java.util.*; 33 import com.sun.enterprise.util.StringUtils; 34 35 40 public class SystemProps 41 { 42 public static List get() 43 { 44 Properties p = System.getProperties(); 45 Set set = p.entrySet(); 49 List list = new ArrayList(set); 50 Collections.sort(list, new Comparator() 51 { 52 public int compare(Object o1, Object o2) 53 { 54 Map.Entry me1 = (Map.Entry)o1; 55 Map.Entry me2 = (Map.Entry)o2; 56 57 return ((String )me1.getKey()).compareToIgnoreCase((String )me2.getKey()); 58 } 59 }); 60 return list; 61 } 62 63 65 public static String toStringStatic() 66 { 67 int longestKey = 0; 68 List list = get(); 69 StringBuffer sb = new StringBuffer (); 70 71 for(Iterator it = list.iterator(); it.hasNext(); ) 72 { 73 Map.Entry entry = (Map.Entry)it.next(); 74 int len = ((String )entry.getKey()).length(); 75 76 if(len > longestKey) 77 longestKey = len; 78 } 79 80 longestKey += 1; 81 82 for(Iterator it = list.iterator(); it.hasNext(); ) 83 { 84 Map.Entry entry = (Map.Entry)it.next(); 85 sb.append(StringUtils.padRight((String )entry.getKey(), longestKey)); 86 sb.append("= "); 87 sb.append((String )entry.getValue()); 88 sb.append("\n"); 89 } 90 91 return sb.toString(); 92 } 93 94 96 private SystemProps() 97 { 98 } 99 100 102 public static void main(String [] args) 103 { 104 System.out.println(toStringStatic()); 105 } 106 } 107 | Popular Tags |